tika-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattm...@apache.org
Subject svn commit: r578881 - in /incubator/tika/trunk/src: main/java/org/apache/tika/config/ main/java/org/apache/tika/mime/ main/java/org/apache/tika/utils/ main/resources/ test/java/org/apache/tika/mime/
Date Mon, 24 Sep 2007 17:12:51 GMT
Author: mattmann
Date: Mon Sep 24 10:12:50 2007
New Revision: 578881

URL: http://svn.apache.org/viewvc?rev=578881&view=rev
Log:
- remove Hadoop/Nutch Configuration and Configurable interfaces
- wire together MimeUtils and tika config.xml file
- wire together MimeUtils and TikaConfig

Removed:
    incubator/tika/trunk/src/main/java/org/apache/tika/utils/Configurable.java
    incubator/tika/trunk/src/main/java/org/apache/tika/utils/Configuration.java
Modified:
    incubator/tika/trunk/src/main/java/org/apache/tika/config/TikaConfig.java
    incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java
    incubator/tika/trunk/src/main/java/org/apache/tika/utils/ParseUtils.java
    incubator/tika/trunk/src/main/resources/config.xml
    incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java

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=578881&r1=578880&r2=578881&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 10:12:50
2007
@@ -16,11 +16,17 @@
  */
 package org.apache.tika.config;
 
+//JDK imports
 import java.io.File;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
+//TIKA imports
+import org.apache.tika.mime.MimeTypes;
+import org.apache.tika.mime.MimeUtils;
+
+//JDOM imports
 import org.jdom.Document;
 import org.jdom.Element;
 import org.jdom.JDOMException;
@@ -34,9 +40,14 @@
 
     private final Map<String, ParserConfig> configs =
         new HashMap<String, ParserConfig>();
+    
+    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"));
+        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")) {
@@ -47,6 +58,10 @@
 
     public ParserConfig getParserConfig(String mimeType) {
         return configs.get(mimeType);
+    }
+    
+    public MimeTypes getMimeRepository(){
+        return mimeTypeRepo.getRepository();
     }
 
 }

Modified: incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java
URL: http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java?rev=578881&r1=578880&r2=578881&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java (original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/mime/MimeUtils.java Mon Sep 24 10:12:50
2007
@@ -25,15 +25,13 @@
 import org.xml.sax.InputSource;
 
 // Tika imports
-import org.apache.tika.utils.Configurable;
-import org.apache.tika.utils.Configuration;
 import org.apache.tika.metadata.TikaMimeKeys;
 
 /**
  * 
  * Wrapper external interface around a {@link MimeTypes} repository.
  */
-public class MimeUtils implements Configurable, TikaMimeKeys {
+public class MimeUtils implements TikaMimeKeys {
 
     /** My logger */
     private final static Logger LOG = Logger.getLogger(MimeUtils.class
@@ -42,9 +40,6 @@
     /** The key used to cache the mime repository in conf */
     private final static String KEY = MimeUtils.class.getName();
 
-    /** My current configuration */
-    private Configuration conf = null;
-
     /** A flag that tells if magic resolution must be performed */
     private boolean magic = true;
 
@@ -52,33 +47,13 @@
     private MimeTypes repository = null;
 
     /** Creates a new instance of MimeUtils */
-    public MimeUtils(Configuration conf) {
-        setConf(conf);
-    }
-
-    /***************************************************************************
-     * ----------------------------- <implementation:Configurable> *
-     * -----------------------------
-     */
-
-    public void setConf(Configuration conf) {
-        this.conf = conf;
-        this.magic = conf.getBoolean(MIME_TYPE_MAGIC, true);
-        this.repository = (MimeTypes) conf.getObject(KEY);
-        if (repository == null) {
-            repository = load(conf.get(TIKA_MIME_FILE));
-            conf.setObject(KEY, repository);
+    public MimeUtils(String resPath, boolean magic) {
+        this.magic = magic;
+        if(repository == null){
+            repository = load(resPath);
         }
     }
 
-    public Configuration getConf() {
-        return this.conf;
-    }
-
-    /***************************************************************************
-     * ----------------------------- </implementation:Configurable> *
-     * -----------------------------
-     */
 
     public final MimeTypes getRepository() {
         return repository;

Modified: incubator/tika/trunk/src/main/java/org/apache/tika/utils/ParseUtils.java
URL: http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/java/org/apache/tika/utils/ParseUtils.java?rev=578881&r1=578880&r2=578881&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/java/org/apache/tika/utils/ParseUtils.java (original)
+++ incubator/tika/trunk/src/main/java/org/apache/tika/utils/ParseUtils.java Mon Sep 24 10:12:50
2007
@@ -27,7 +27,6 @@
 import org.apache.tika.config.TikaConfig;
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.metadata.TikaMimeKeys;
-import org.apache.tika.mime.MimeUtils;
 import org.apache.tika.parser.Parser;
 import org.apache.tika.parser.ParserFactory;
 
@@ -37,14 +36,6 @@
  */
 public class ParseUtils implements TikaMimeKeys {
 
-    private static final Configuration conf = new Configuration();
-
-    static {
-        conf.set(TIKA_MIME_FILE, "org/apache/tika/mime/tika-mimetypes.xml");
-    }
-
-    private static final MimeUtils mimeUtils = new MimeUtils(conf);
-
     /**
      * Returns a parser that can handle the specified MIME type, and is set to
      * receive input from a stream opened from the specified URL. NB: Close the
@@ -117,7 +108,7 @@
     public static Parser getParser(URL documentUrl, TikaConfig config)
             throws TikaException, IOException {
 
-        String mimetype = mimeUtils.getRepository().getMimeType(documentUrl)
+        String mimetype = config.getMimeRepository().getMimeType(documentUrl)
                 .getName();
         return getParser(documentUrl, config, mimetype);
     }
@@ -172,7 +163,7 @@
     public static Parser getParser(File documentFile, TikaConfig config)
             throws TikaException, IOException {
 
-        String mimetype = mimeUtils.getRepository().getMimeType(documentFile)
+        String mimetype = config.getMimeRepository().getMimeType(documentFile)
                 .getName();
         return getParser(documentFile, config, mimetype);
     }

Modified: incubator/tika/trunk/src/main/resources/config.xml
URL: http://svn.apache.org/viewvc/incubator/tika/trunk/src/main/resources/config.xml?rev=578881&r1=578880&r2=578881&view=diff
==============================================================================
--- incubator/tika/trunk/src/main/resources/config.xml (original)
+++ incubator/tika/trunk/src/main/resources/config.xml Mon Sep 24 10:12:50 2007
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <properties>
+    <mimeTypeRepository resource="org/apache/tika/mime/tika-mimetypes.xml" magic="false"/>
     <parsers>
         <parser name="text-xml" class="org.apache.tika.parser.xml.XMLParser">
                 <namespace>http://purl.org/dc/elements/1.1/</namespace>

Modified: incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java
URL: http://svn.apache.org/viewvc/incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java?rev=578881&r1=578880&r2=578881&view=diff
==============================================================================
--- incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java (original)
+++ incubator/tika/trunk/src/test/java/org/apache/tika/mime/TestMimeUtils.java Mon Sep 24
10:12:50 2007
@@ -24,7 +24,6 @@
 
 //Tika imports
 import org.apache.tika.metadata.TikaMimeKeys;
-import org.apache.tika.utils.Configuration;
 
 //Junit imports
 import junit.framework.TestCase;
@@ -37,8 +36,8 @@
 public class TestMimeUtils extends TestCase implements TikaMimeKeys {
 
     private static final String tikaMimeFile = "org/apache/tika/mime/tika-mimetypes.xml";
-
-    private Configuration conf;
+    
+    private static final boolean magic = false;
 
     private static URL u;
 
@@ -55,9 +54,7 @@
     private MimeUtils utils;
 
     public TestMimeUtils() {
-        Configuration conf = new Configuration();
-        conf.set(TIKA_MIME_FILE, tikaMimeFile);
-        utils = new MimeUtils(conf);
+        utils = new MimeUtils(tikaMimeFile, magic);
         assertNotNull(utils);
     }
 



Mime
View raw message