jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1167687 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Date Sun, 11 Sep 2011 09:26:50 GMT
Author: jukka
Date: Sun Sep 11 09:26:49 2011
New Revision: 1167687

URL: http://svn.apache.org/viewvc?rev=1167687&view=rev
Log:
JCR-3003: Tika configuration may use wrong class loader

Construct the parser already during repository initialization

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=1167687&r1=1167686&r2=1167687&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Sun Sep 11 09:26:49 2011
@@ -565,8 +565,9 @@ public class SearchIndex extends Abstrac
             }
         }
 
-        // initialize spell checker
+        // initialize spell checker and Tika parser
         spellChecker = createSpellChecker();
+        parser = createParser();
 
         log.info("Index initialized: {} Version: {}",
                 new Object[]{path, index.getIndexFormatVersion()});
@@ -928,50 +929,51 @@ public class SearchIndex extends Abstrac
      *
      * @return the configured parser
      */
-    public synchronized Parser getParser() {
-        if (parser == null) {
-            URL url = null;
-            if (tikaConfigPath != null) {
-                File file = new File(tikaConfigPath);
-                if (file.exists()) {
-                    try {
-                        url = file.toURI().toURL();
-                    } catch (MalformedURLException e) {
-                        log.warn("Invalid Tika configuration path: " + file, e);
-                    }
-                } else {
-                    ClassLoader loader = SearchIndex.class.getClassLoader();
-                    url = loader.getResource(tikaConfigPath);
-                }
-            }
-            if (url == null) {
-                url = SearchIndex.class.getResource("tika-config.xml");
-            }
+    public Parser getParser() {
+        return parser;
+    }
 
-            TikaConfig config = null;
-            if (url != null) {
+    private Parser createParser() {
+        URL url = null;
+        if (tikaConfigPath != null) {
+            File file = new File(tikaConfigPath);
+            if (file.exists()) {
                 try {
-                    config = new TikaConfig(url);
-                } catch (Exception e) {
-                    log.warn("Tika configuration not available: " + url, e);
+                    url = file.toURI().toURL();
+                } catch (MalformedURLException e) {
+                    log.warn("Invalid Tika configuration path: " + file, e);
                 }
+            } else {
+                ClassLoader loader = SearchIndex.class.getClassLoader();
+                url = loader.getResource(tikaConfigPath);
             }
-            if (config == null) {
-                config = TikaConfig.getDefaultConfig();
-            }
+        }
+        if (url == null) {
+            url = SearchIndex.class.getResource("tika-config.xml");
+        }
 
-            if (forkJavaCommand == null) {
-                parser = new AutoDetectParser(config);
-            } else {
-                ForkParser forkParser = new ForkParser(
-                        SearchIndex.class.getClassLoader(),
-                        new AutoDetectParser(config));
-                forkParser.setJavaCommand(forkJavaCommand);
-                forkParser.setPoolSize(extractorPoolSize);
-                parser = forkParser;
+        TikaConfig config = null;
+        if (url != null) {
+            try {
+                config = new TikaConfig(url);
+            } catch (Exception e) {
+                log.warn("Tika configuration not available: " + url, e);
             }
         }
-        return parser;
+        if (config == null) {
+            config = TikaConfig.getDefaultConfig();
+        }
+
+        if (forkJavaCommand != null) {
+            ForkParser forkParser = new ForkParser(
+                    SearchIndex.class.getClassLoader(),
+                    new AutoDetectParser(config));
+            forkParser.setJavaCommand(forkJavaCommand);
+            forkParser.setPoolSize(extractorPoolSize);
+            return forkParser;
+        } else {
+            return new AutoDetectParser(config);
+        }
     }
 
     /**
@@ -1179,7 +1181,7 @@ public class SearchIndex extends Abstrac
             throws RepositoryException {
         NodeIndexer indexer = new NodeIndexer(
                 node, getContext().getItemStateManager(), nsMappings,
-                getContext().getExecutor(), getParser());
+                getContext().getExecutor(), parser);
         indexer.setSupportHighlighting(supportHighlighting);
         indexer.setIndexingConfiguration(indexingConfig);
         indexer.setIndexFormatVersion(indexFormatVersion);



Mime
View raw message