This repository was archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rob Rudin
committed
Feb 21, 2017
1 parent
c94da03
commit e6ede2b
Showing
11 changed files
with
167 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/com/marklogic/client/file/DefaultFileLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.marklogic.client.file; | ||
|
||
import com.marklogic.client.batch.BatchWriter; | ||
import com.marklogic.client.helper.LoggingObject; | ||
import org.springframework.util.ClassUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DefaultFileLoader extends LoggingObject implements FileLoader { | ||
|
||
private DocumentFileFinder documentFileFinder; | ||
private BatchWriter batchWriter; | ||
private List<DocumentFileProcessor> documentFileProcessors; | ||
|
||
public DefaultFileLoader(BatchWriter batchWriter) { | ||
this(batchWriter, new DefaultDocumentFileFinder()); | ||
} | ||
|
||
/** | ||
* @param batchWriter This is assumed to have already been initialized, as this class is not interested in managing | ||
* the lifecycle of a BatchWriter | ||
* @param documentFileFinder | ||
*/ | ||
public DefaultFileLoader(BatchWriter batchWriter, DocumentFileFinder documentFileFinder) { | ||
this.batchWriter = batchWriter; | ||
this.documentFileFinder = documentFileFinder; | ||
initializeDocumentFileProcessors(); | ||
} | ||
|
||
protected void initializeDocumentFileProcessors() { | ||
documentFileProcessors = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public List<DocumentFile> loadFiles(String... paths) { | ||
List<DocumentFile> documentFiles = documentFileFinder.findDocumentFiles(paths); | ||
batchWriter.write(documentFiles); | ||
return documentFiles; | ||
} | ||
|
||
public DocumentFileProcessor getDocumentFileProcessor(String classShortName) { | ||
for (DocumentFileProcessor processor : documentFileProcessors) { | ||
if (ClassUtils.getShortName(processor.getClass()).equals(classShortName)) { | ||
return processor; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void addDocumentFileProcessor(DocumentFileProcessor processor) { | ||
if (documentFileProcessors == null) { | ||
documentFileProcessors = new ArrayList<>(); | ||
} | ||
documentFileProcessors.add(processor); | ||
} | ||
|
||
public List<DocumentFileProcessor> getDocumentFileProcessors() { | ||
return documentFileProcessors; | ||
} | ||
|
||
public void setDocumentFileProcessors(List<DocumentFileProcessor> documentFileProcessors) { | ||
this.documentFileProcessors = documentFileProcessors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/marklogic/client/file/DocumentFileProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.marklogic.client.file; | ||
|
||
/** | ||
* Callback-style interface for processing - i.e. do whatever you want with - a DocumentFile instance before it's | ||
* written to MarkLogic. | ||
*/ | ||
public interface DocumentFileProcessor { | ||
|
||
boolean supportsDocumentFile(DocumentFile documentFile); | ||
|
||
void processDocumentFile(DocumentFile documentFile); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/marklogic/client/file/FileExtensionDocumentFileProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.marklogic.client.file; | ||
|
||
public class FileExtensionDocumentFileProcessor implements DocumentFileProcessor { | ||
|
||
@Override | ||
public boolean supportsDocumentFile(DocumentFile documentFile) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void processDocumentFile(DocumentFile documentFile) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/marklogic/client/schemasloader/impl/TdeDocumentFileProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.marklogic.client.schemasloader.impl; | ||
|
||
import com.marklogic.client.file.DocumentFile; | ||
import com.marklogic.client.file.DocumentFileProcessor; | ||
import com.marklogic.client.io.Format; | ||
|
||
public class TdeDocumentFileProcessor implements DocumentFileProcessor { | ||
|
||
@Override | ||
public boolean supportsDocumentFile(DocumentFile documentFile) { | ||
String extension = documentFile.getFileExtension(); | ||
return "tdej".equals(extension) || "tdex".equals(extension); | ||
} | ||
|
||
@Override | ||
public void processDocumentFile(DocumentFile documentFile) { | ||
documentFile.getDocumentMetadata().withCollections("http://marklogic.com/xdmp/tde"); | ||
|
||
String extension = documentFile.getFileExtension(); | ||
if ("tdej".equals(extension)) { | ||
documentFile.setFormat(Format.JSON); | ||
} else if ("tdex".equals(extension)) { | ||
documentFile.setFormat(Format.XML); | ||
} | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
src/main/java/com/marklogic/client/schemasloader/impl/TdeSchemaFileHandler.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/main/java/com/marklogic/client/schemasloader/impl/XsdDocumentFileProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.marklogic.client.schemasloader.impl; | ||
|
||
import com.marklogic.client.file.DocumentFile; | ||
import com.marklogic.client.file.DocumentFileProcessor; | ||
import com.marklogic.client.io.Format; | ||
|
||
public class XsdDocumentFileProcessor implements DocumentFileProcessor { | ||
|
||
@Override | ||
public boolean supportsDocumentFile(DocumentFile documentFile) { | ||
return "xsd".equals(documentFile.getFileExtension()); | ||
} | ||
|
||
@Override | ||
public void processDocumentFile(DocumentFile documentFile) { | ||
documentFile.setFormat(Format.XML); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters