private Parser initializeTikaParser(IndexDefinition definition) { ClassLoader current = Thread.currentThread().getContextClassLoader(); try { if (definition.hasCustomTikaConfig()) { Thread.currentThread().setContextClassLoader(FulltextIndexEditorContext.class.getClassLoader()); return new AutoDetectParser(getTikaConfig()); } } finally { Thread.currentThread().setContextClassLoader(current); } return defaultParser; }
private Set<MediaType> getNonIndexedMediaTypes() { InputStream configStream = null; String configSource = null; try { if (definition.hasCustomTikaConfig()) { configSource = String.format("Custom config at %s", definition.getIndexPath()); configStream = definition.getTikaConfig(); } else { URL configUrl = FulltextIndexEditorContext.class.getResource("tika-config.xml"); configSource = "Default : tika-config.xml"; if (configUrl != null) { configStream = configUrl.openStream(); } } if (configStream != null) { return TikaParserConfig.getNonIndexedMediaTypes(configStream); } } catch (TikaException | IOException | SAXException e) { log.warn("Tika configuration not available : " + configSource, e); } finally { IOUtils.closeQuietly(configStream); } return Collections.emptySet(); }
private static TikaConfigHolder initializeTikaConfig(@Nullable IndexDefinition definition) { ClassLoader current = Thread.currentThread().getContextClassLoader(); InputStream configStream = null; String configSource = null; try { Thread.currentThread().setContextClassLoader(FulltextIndexEditorContext.class.getClassLoader()); if (definition != null && definition.hasCustomTikaConfig()) { log.debug("[{}] Using custom tika config", definition.getIndexName()); configSource = "Custom config at " + definition.getIndexPath(); configStream = definition.getTikaConfig(); } else { URL configUrl = FulltextIndexEditorContext.class.getResource("tika-config.xml"); if (configUrl != null) { configSource = configUrl.toString(); configStream = configUrl.openStream(); } } if (configStream != null) { return new TikaConfigHolder(new TikaConfig(configStream), configSource); } } catch (TikaException | IOException | SAXException e) { log.warn("Tika configuration not available : " + configSource, e); } finally { IOUtils.closeQuietly(configStream); Thread.currentThread().setContextClassLoader(current); } return new TikaConfigHolder(TikaConfig.getDefaultConfig(), "Default Config"); }
@Test public void customTikaConfig() throws Exception{ NodeBuilder defnb = newFTIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "foo", "lucene", of(TYPENAME_STRING)); IndexDefinition defn = new IndexDefinition(root, defnb.getNodeState(), "/foo"); assertFalse(defn.hasCustomTikaConfig()); defnb.child(FulltextIndexConstants.TIKA) .child(FulltextIndexConstants.TIKA_CONFIG) .child(JcrConstants.JCR_CONTENT) .setProperty(JcrConstants.JCR_DATA, "hello".getBytes()); defn = new IndexDefinition(root, defnb.getNodeState(), "/foo"); assertTrue(defn.hasCustomTikaConfig()); }