|
17 | 17 | import com.marklogic.client.schemasloader.SchemasLoader; |
18 | 18 |
|
19 | 19 | public class DefaultSchemasLoader extends LoggingObject implements SchemasLoader { |
20 | | - |
21 | | - @Override |
22 | | - public Set<File> loadSchemas(File baseDir, SchemasFinder schemasDataFinder, DatabaseClient client) { |
23 | | - XMLDocumentManager xmlDocMgr = client.newXMLDocumentManager(); |
24 | | - TextDocumentManager textDocMgr = client.newTextDocumentManager(); |
25 | | - JSONDocumentManager jsonDocMgr = client.newJSONDocumentManager(); |
26 | | - |
27 | | - List<File> schemasData = schemasDataFinder.findSchemas(baseDir); |
| 20 | + |
| 21 | + @Override |
| 22 | + public Set<File> loadSchemas(File baseDir, SchemasFinder schemasDataFinder, DatabaseClient client) { |
| 23 | + XMLDocumentManager xmlDocMgr = client.newXMLDocumentManager(); |
| 24 | + TextDocumentManager textDocMgr = client.newTextDocumentManager(); |
| 25 | + JSONDocumentManager jsonDocMgr = client.newJSONDocumentManager(); |
| 26 | + |
| 27 | + List<File> schemasData = schemasDataFinder.findSchemas(baseDir); |
28 | 28 |
|
29 | 29 | Set<File> loadedSchemas = new HashSet<>(); |
30 | | - DocumentMetadataHandle tdeCollection = new DocumentMetadataHandle().withCollections("http://marklogic.com/xdmp/tde"); |
| 30 | + DocumentMetadataHandle tdeCollection = new DocumentMetadataHandle() |
| 31 | + .withCollections("http://marklogic.com/xdmp/tde"); |
31 | 32 | for (File f : schemasData) { |
32 | | - String extension = getExtensionNameFromFile(f); |
33 | | - FileHandle handle = new FileHandle(f); |
34 | | - if (extension.equals("tdej")) { |
35 | | - jsonDocMgr.write(f.getName(), tdeCollection, handle.withFormat(Format.JSON)); |
36 | | - } |
37 | | - else if (extension.equals("tdex")) { |
38 | | - xmlDocMgr.write(f.getName(), tdeCollection, handle.withFormat(Format.XML)); |
39 | | - } |
40 | | - else if (extension.equals("xsd")) { |
41 | | - xmlDocMgr.write(f.getName(), handle.withFormat(Format.XML)); |
42 | | - } else { |
43 | | - textDocMgr.write(f.getName(), handle.withFormat(Format.TEXT)); |
44 | | - } |
45 | | - loadedSchemas.add(f); |
| 33 | + String extension = getExtensionNameFromFile(f); |
| 34 | + FileHandle handle = new FileHandle(f); |
| 35 | + if (extension.equals("tdej")) { |
| 36 | + jsonDocMgr.write(f.getName(), tdeCollection, handle.withFormat(Format.JSON)); |
| 37 | + } else if (extension.equals("tdex")) { |
| 38 | + xmlDocMgr.write(f.getName(), tdeCollection, handle.withFormat(Format.XML)); |
| 39 | + } else if (extension.equals("xsd")) { |
| 40 | + xmlDocMgr.write(f.getName(), handle.withFormat(Format.XML)); |
| 41 | + } else { |
| 42 | + textDocMgr.write(f.getName(), handle.withFormat(Format.TEXT)); |
| 43 | + } |
| 44 | + loadedSchemas.add(f); |
46 | 45 | } |
47 | 46 |
|
48 | 47 | return loadedSchemas; |
49 | | - } |
50 | | - protected String getExtensionNameFromFile(File file) { |
51 | | - String name = file.getName(); |
52 | | - int pos = name.lastIndexOf('.'); |
53 | | - if (pos < 0) |
54 | | - return name; |
55 | | - return name.substring(0, pos); |
56 | | - } |
| 48 | + } |
| 49 | + |
| 50 | + protected String getExtensionNameFromFile(File file) { |
| 51 | + String name = file.getName(); |
| 52 | + int pos = name.lastIndexOf('.'); |
| 53 | + return pos < 0 ? name : name.substring(pos + 1); |
| 54 | + } |
57 | 55 | } |
0 commit comments