|
68 | 68 |
|
69 | 69 | import org.apache.tika.Tika; |
70 | 70 | import org.apache.tika.async.cli.TikaAsyncCLI; |
71 | | -import org.apache.tika.config.TikaConfig; |
72 | 71 | import org.apache.tika.config.TikaConfigSerializer; |
| 72 | +import org.apache.tika.config.loader.TikaLoader; |
73 | 73 | import org.apache.tika.detect.CompositeDetector; |
74 | 74 | import org.apache.tika.detect.Detector; |
75 | 75 | import org.apache.tika.exception.TikaException; |
@@ -129,7 +129,7 @@ protected ContentHandler getContentHandler(OutputStream output, Metadata metadat |
129 | 129 | private ParseContext context; |
130 | 130 | private Detector detector; |
131 | 131 | private Parser parser; |
132 | | - private TikaConfig config; |
| 132 | + private TikaLoader tikaLoader; |
133 | 133 | private String configFilePath; |
134 | 134 | private boolean recursiveJSON = false; |
135 | 135 | private URI networkURI = null; |
@@ -518,9 +518,9 @@ public void process(String arg) throws Exception { |
518 | 518 |
|
519 | 519 | private void dumpConfig(TikaConfigSerializer.Mode mode) throws Exception { |
520 | 520 | configure(); |
521 | | - TikaConfig localConfig = (config == null) ? TikaConfig.getDefaultConfig() : config; |
522 | | - |
523 | | - TikaConfigSerializer.serialize(localConfig, mode, new OutputStreamWriter(System.out, UTF_8), UTF_8); |
| 521 | + TikaLoader localConfig = (tikaLoader == null) ? TikaLoader.loadDefault() : tikaLoader; |
| 522 | + //TODO -- implement mode |
| 523 | + System.out.println(localConfig.getConfig().toString()); |
524 | 524 | } |
525 | 525 |
|
526 | 526 | private void convertConfigXmlToJson(String paths) throws Exception { |
@@ -553,14 +553,16 @@ private void convertConfigXmlToJson(String paths) throws Exception { |
553 | 553 | private void handleRecursiveJson(URL url, OutputStream output) throws IOException, SAXException, TikaException { |
554 | 554 | Metadata metadata = new Metadata(); |
555 | 555 | RecursiveParserWrapper wrapper = new RecursiveParserWrapper(parser); |
556 | | - RecursiveParserWrapperHandler handler = new RecursiveParserWrapperHandler(getContentHandlerFactory(type), -1, config.getMetadataFilter()); |
| 556 | + RecursiveParserWrapperHandler handler = new RecursiveParserWrapperHandler(getContentHandlerFactory(type), -1, |
| 557 | + tikaLoader.loadMetadataFilters()); |
557 | 558 | try (InputStream input = TikaInputStream.get(url, metadata)) { |
558 | 559 | wrapper.parse(input, handler, metadata, context); |
559 | 560 | } |
560 | 561 | JsonMetadataList.setPrettyPrinting(prettyPrint); |
561 | 562 | try (Writer writer = getOutputWriter(output, encoding)) { |
562 | 563 | List<Metadata> metadataList = handler.getMetadataList(); |
563 | | - metadataList = config.getMetadataFilter().filter(metadataList); |
| 564 | + metadataList = tikaLoader |
| 565 | + .loadMetadataFilters().filter(metadataList); |
564 | 566 | JsonMetadataList.toJson(metadataList, writer); |
565 | 567 | } |
566 | 568 | } |
@@ -710,26 +712,32 @@ private boolean testForBatch(String[] args) { |
710 | 712 |
|
711 | 713 | private void configure() throws TikaException, IOException, SAXException { |
712 | 714 | if (configFilePath != null) { |
713 | | - config = new TikaConfig(new File(configFilePath)); |
| 715 | + tikaLoader = TikaLoader.load(Paths.get(configFilePath)); |
714 | 716 | } else { |
715 | 717 | String warn = "As a convenience, TikaCLI has turned on several non-default features\n" + |
716 | | - "as specified in tika-app/src/main/resources/tika-config-default-single-file.xml.\n" + |
| 718 | + "as specified in tika-app/src/main/resources/tika-config-default-single-file.json.\n" + |
717 | 719 | "See: TIKA-2374, TIKA-4017, TIKA-4354 and TIKA-4472).\n" + |
718 | 720 | "This is not the default behavior in Tika generally or in tika-server."; |
719 | 721 | LOG.info(warn); |
720 | | - try (InputStream is = getClass().getResourceAsStream("/tika-config-default-single-file.xml")) { |
721 | | - config = new TikaConfig(is); |
| 722 | + Path tempConfig = Files.createTempFile("tika-config-", ".json"); |
| 723 | + try { |
| 724 | + try (InputStream is = getClass().getResourceAsStream("/tika-config-default-single-file.json")) { |
| 725 | + Files.copy(is, tempConfig, StandardCopyOption.REPLACE_EXISTING); |
| 726 | + } |
| 727 | + tikaLoader = TikaLoader.load(tempConfig); |
| 728 | + } finally { |
| 729 | + Files.deleteIfExists(tempConfig); |
722 | 730 | } |
723 | 731 | } |
724 | 732 | if (networkURI != null) { |
725 | 733 | parser = new NetworkParser(networkURI); |
726 | 734 | } else { |
727 | | - parser = new AutoDetectParser(config); |
| 735 | + parser = tikaLoader.loadAutoDetectParser(); |
728 | 736 | if (digester != null) { |
729 | 737 | parser = new DigestingParser(parser, digester, false); |
730 | 738 | } |
731 | 739 | } |
732 | | - detector = config.getDetector(); |
| 740 | + detector = tikaLoader.loadDetectors(); |
733 | 741 | context.set(Parser.class, parser); |
734 | 742 | context.set(PasswordProvider.class, new SimplePasswordProvider(password)); |
735 | 743 | } |
@@ -932,9 +940,9 @@ private void compareFileMagic(String magicDir) throws Exception { |
932 | 940 | } |
933 | 941 |
|
934 | 942 | // See how those compare to the Tika ones |
935 | | - TikaConfig config = TikaConfig.getDefaultConfig(); |
936 | | - MimeTypes mimeTypes = config.getMimeRepository(); |
937 | | - MediaTypeRegistry registry = config.getMediaTypeRegistry(); |
| 943 | + TikaLoader loader = TikaLoader.loadDefault(); |
| 944 | + MimeTypes mimeTypes = TikaLoader.getMimeTypes(); |
| 945 | + MediaTypeRegistry registry = loader.getMediaTypeRegistry(); |
938 | 946 | for (String mime : fileMimes) { |
939 | 947 | try { |
940 | 948 | final MimeType type = mimeTypes.getRegisteredMimeType(mime); |
|
0 commit comments