tika-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r578976 - in /incubator/tika/trunk: CHANGES.txt src/main/java/org/apache/tika/config/TikaConfig.java
Date Mon, 24 Sep 2007 21:19:57 GMT
Author: jukka
Date: Mon Sep 24 14:19:56 2007
New Revision: 578976

URL: http://svn.apache.org/viewvc?rev=578976&view=rev
Log:
TIKA-30 - Added utility constructors to TikaConfig
    - TikaConfig(String), calls TikaConfig(File)
    - TikaConfig(File), calls TikaConfig(Document)
    - TikaConfig(URL), calls TikaConfig(Document)
    - TikaConfig(InputStream), calls TikaConfig(Document)
    - TikaConfig(Document), calls TikaConfig(Element)
    - TikaConfig(Element), the base implementation

Modified:
    incubator/tika/trunk/CHANGES.txt
    incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java

Modified: incubator/tika/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/tika/trunk/CHANGES.txt?rev=578976&r1=578975&r2=578976&view=diff
==============================================================================
--- incubator/tika/trunk/CHANGES.txt (original)
+++ incubator/tika/trunk/CHANGES.txt Mon Sep 24 14:19:56 2007
@@ -40,3 +40,5 @@
 18. TIKA-21 - Simplified configuration code (jukka)
 
 19. TIKA-17 - Rename all "Luis" classes to be "Tika" classes (jukka)
+
+20. TIKA-30 - Added utility constructors to TikaConfig (K. Bennett & jukka)

Modified: incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java
URL: http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java?rev=578976&r1=578975&r2=578976&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java (original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java Mon Sep 24 14:19:56
2007
@@ -19,6 +19,8 @@
 //JDK imports
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -44,14 +46,35 @@
     private static MimeUtils mimeTypeRepo;
 
     public TikaConfig(String file) throws JDOMException, IOException {
-        Document document = new SAXBuilder().build(new File(file));
-        String mimeTypeRepoResource = document.getRootElement().getChild("mimeTypeRepository").getAttributeValue("resource");
-        boolean magic = Boolean.valueOf(document.getRootElement().getChild("mimeTypeRepository").getAttributeValue("magic"));
+        this(new File(file));
+    }
+
+    public TikaConfig(File file) throws JDOMException, IOException {
+        this(new SAXBuilder().build(file));
+    }
+
+    public TikaConfig(URL url) throws JDOMException, IOException {
+        this(new SAXBuilder().build(url));
+    }
+
+    public TikaConfig(InputStream stream) throws JDOMException, IOException {
+        this(new SAXBuilder().build(stream));
+    }
+
+    public TikaConfig(Document document) throws JDOMException {
+        this(document.getRootElement());
+    }
+
+    public TikaConfig(Element element) throws JDOMException {
+        Element mtr = element.getChild("mimeTypeRepository");
+        String mimeTypeRepoResource = mtr.getAttributeValue("resource");
+        boolean magic = Boolean.valueOf(mtr.getAttributeValue("magic"));
         mimeTypeRepo = new MimeUtils(mimeTypeRepoResource, magic);
-        for (Object element : XPath.selectNodes(document, "//parser")) {
-            ParserConfig pc = new ParserConfig((Element) element);
-            for (Object child : ((Element) element).getChildren("mime")) {
-                configs.put(((Element) child).getTextTrim(), pc);
+
+        for (Object parser : XPath.selectNodes(element, "//parser")) {
+            ParserConfig config = new ParserConfig((Element) parser);
+            for (Object child : ((Element) parser).getChildren("mime")) {
+                configs.put(((Element) child).getTextTrim(), config);
             }
         }
     }



Mime
View raw message