Author: nick
Date: Tue Dec 23 06:23:55 2014
New Revision: 1647486

URL: http://svn.apache.org/r1647486
Log:
Split the Berkeley DB mimetypes into three levels, and add a detection test 
(passes) and a heirarchy test (disabled as fails) TIKA-1502

Modified:
    
tika/trunk/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml
    
tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java
    
tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java

Modified: 
tika/trunk/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml?rev=1647486&r1=1647485&r2=1647486&view=diff
==============================================================================
--- 
tika/trunk/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml 
(original)
+++ 
tika/trunk/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml 
Tue Dec 23 06:23:55 2014
@@ -2523,32 +2523,53 @@
     <glob pattern="*.bcpio"/>
   </mime-type>
 
-  <!-- TODO Rationalise to add a third level -->
   <mime-type type="application/x-berkeley-db">
+    <_comment>Berkeley DB</_comment>
     <alias type="application/x-dbm"/>
+  </mime-type>
+  <mime-type type="application/x-berkeley-db;format=hash">
+    <_comment>Berkeley DB Hash Database</_comment>
     <magic priority="50">
-      <!-- Hash -->
+      <match value="0x00061561" type="host32" offset="0"/>
       <match value="0x00061561" type="big32" offset="0"/>
+      <match value="0x00061561" type="little32" offset="0"/>
       <match value="0x00061561" type="host32" offset="12"/>
       <match value="0x00061561" type="big32" offset="12"/>
       <match value="0x00061561" type="little32" offset="12"/>
-      <!-- BTree -->
+    </magic>
+    <sub-class-of type="application/x-berkeley-db"/>
+  </mime-type>
+  <mime-type type="application/x-berkeley-db;format=btree">
+    <_comment>Berkeley DB BTree Database</_comment>
+    <magic priority="50">
       <match value="0x00053162" type="host32" offset="0"/>
       <match value="0x00053162" type="big32" offset="0"/>
       <match value="0x00053162" type="little32" offset="0"/>
       <match value="0x00053162" type="host32" offset="12"/>
       <match value="0x00053162" type="big32" offset="12"/>
       <match value="0x00053162" type="little32" offset="12"/>
-      <!-- Queue -->
+    </magic>
+    <sub-class-of type="application/x-berkeley-db"/>
+  </mime-type>
+  <mime-type type="application/x-berkeley-db;format=queue">
+    <_comment>Berkeley DB Queue Database</_comment>
+    <magic priority="50">
       <match value="0x00042253" type="host32" offset="12"/>
       <match value="0x00042253" type="big32" offset="12"/>
       <match value="0x00042253" type="little32" offset="12"/>
-      <!-- Log -->
+    </magic>
+    <sub-class-of type="application/x-berkeley-db"/>
+  </mime-type>
+  <mime-type type="application/x-berkeley-db;format=log">
+    <_comment>Berkeley DB Log Database</_comment>
+    <magic priority="50">
       <match value="0x00040988" type="host32" offset="12"/>
       <match value="0x00040988" type="little32" offset="12"/>
       <match value="0x00040988" type="big32" offset="12"/>
     </magic>
+    <sub-class-of type="application/x-berkeley-db"/>
   </mime-type>
+
   <mime-type type="application/x-berkeley-db;format=hash;version=2">
     <_comment>Berkeley DB Version 2 Hash Database</_comment>
     <magic priority="60">
@@ -2562,7 +2583,7 @@
           <match value="0x0005" type="little32" offset="16"/>
       </match>
     </magic>
-    <sub-class-of type="application/x-berkeley-db"/>
+    <sub-class-of type="application/x-berkeley-db;format=hash"/>
   </mime-type>
   <mime-type type="application/x-berkeley-db;format=hash;version=3">
     <_comment>Berkeley DB Version 3 Hash Database</_comment>
@@ -2577,7 +2598,7 @@
           <match value="0x0007" type="little32" offset="16"/>
       </match>
     </magic>
-    <sub-class-of type="application/x-berkeley-db"/>
+    <sub-class-of type="application/x-berkeley-db;format=hash"/>
   </mime-type>
   <mime-type type="application/x-berkeley-db;format=hash;version=4">
     <_comment>Berkeley DB Version 4 Hash Database</_comment>
@@ -2592,7 +2613,7 @@
           <match value="0x0008" type="little32" offset="16"/>
       </match>
     </magic>
-    <sub-class-of type="application/x-berkeley-db"/>
+    <sub-class-of type="application/x-berkeley-db;format=hash"/>
   </mime-type>
   <mime-type type="application/x-berkeley-db;format=hash;version=5">
     <_comment>Berkeley DB Version 5 Hash Database</_comment>
@@ -2607,8 +2628,9 @@
           <match value="0x0009" type="little32" offset="16"/>
       </match>
     </magic>
-    <sub-class-of type="application/x-berkeley-db"/>
+    <sub-class-of type="application/x-berkeley-db;format=hash"/>
   </mime-type>
+
   <mime-type type="application/x-berkeley-db;format=btree;version=2">
     <_comment>Berkeley DB Version 2 BTree Database</_comment>
     <magic priority="60">
@@ -2622,7 +2644,7 @@
           <match value="0x0006" type="little32" offset="16"/>
       </match>
     </magic>
-    <sub-class-of type="application/x-berkeley-db"/>
+    <sub-class-of type="application/x-berkeley-db;format=btree"/>
   </mime-type>
   <mime-type type="application/x-berkeley-db;format=btree;version=3">
     <_comment>Berkeley DB Version 3 BTree Database</_comment>
@@ -2637,7 +2659,7 @@
           <match value="0x0008" type="little32" offset="16"/>
       </match>
     </magic>
-    <sub-class-of type="application/x-berkeley-db"/>
+    <sub-class-of type="application/x-berkeley-db;format=btree"/>
   </mime-type>
   <mime-type type="application/x-berkeley-db;format=btree;version=4">
     <_comment>Berkeley DB Version 4 and 5 BTree Database</_comment>
@@ -2652,7 +2674,7 @@
           <match value="0x0009" type="little32" offset="16"/>
       </match>
     </magic>
-    <sub-class-of type="application/x-berkeley-db"/>
+    <sub-class-of type="application/x-berkeley-db;format=btree"/>
   </mime-type>
 
   <mime-type type="application/x-bibtex-text-file">

Modified: 
tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java?rev=1647486&r1=1647485&r2=1647486&view=diff
==============================================================================
--- 
tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java
 (original)
+++ 
tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java
 Tue Dec 23 06:23:55 2014
@@ -23,9 +23,10 @@ import java.util.List;
 
 import org.apache.tika.config.TikaConfig;
 import org.apache.tika.metadata.Metadata;
-
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -142,6 +143,26 @@ public class MimeTypesReaderTest {
             mime.getLinks().get(0).toString());
     }
     
+    // TODO Get this to work - currently jumps two levels!
+    @Test
+    @Ignore
+    public void testReadParameterHeirarchy() throws Exception {
+        MimeType mimeBTree4 = 
this.mimeTypes.forName("application/x-berkeley-db;format=btree;version=4");
+        MediaType mtBTree4 = mimeBTree4.getType();
+        
+        // Canonicalised with spaces
+        assertEquals("application/x-berkeley-db; format=btree; version=4", 
mimeBTree4.toString());
+        assertEquals("application/x-berkeley-db; format=btree; version=4", 
mtBTree4.toString());
+        
+        // Parent has one parameter
+        MediaType mtBTree = 
this.mimeTypes.getMediaTypeRegistry().getSupertype(mtBTree4);
+        assertEquals("application/x-berkeley-db; format=btree", 
mtBTree.toString());
+        
+        // Parent of that has none
+        MediaType mtBD = 
this.mimeTypes.getMediaTypeRegistry().getSupertype(mtBTree);
+        assertEquals("application/x-berkeley-db", mtBD.toString());
+    }
+    
     /**
      * TIKA-746 Ensures that the custom mimetype maps were also 
      *  loaded and used

Modified: 
tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java?rev=1647486&r1=1647485&r2=1647486&view=diff
==============================================================================
--- 
tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java 
(original)
+++ 
tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java 
Tue Dec 23 06:23:55 2014
@@ -819,6 +819,36 @@ public class TestMimeTypes {
         assertText(new byte[] { '\t', '\r', '\n', 0x0C, 0x1B });
         assertNotText(new byte[] { '\t', '\r', '\n', 0x0E, 0x1C });
     }
+    
+    @Test
+    public void testBerkeleyDB() throws IOException {
+        assertTypeByData(
+                "application/x-berkeley-db; format=btree; version=2", 
+                "testBDB_btree_2.db");
+        assertTypeByData(
+                "application/x-berkeley-db; format=btree; version=3", 
+                "testBDB_btree_3.db");
+        assertTypeByData(
+                "application/x-berkeley-db; format=btree; version=4", 
+                "testBDB_btree_4.db");
+        // V4 and V5 share the same btree format
+        assertTypeByData(
+                "application/x-berkeley-db; format=btree; version=4", 
+                "testBDB_btree_5.db");
+        
+        assertTypeByData(
+                "application/x-berkeley-db; format=hash; version=2", 
+                "testBDB_hash_2.db");
+        assertTypeByData(
+                "application/x-berkeley-db; format=hash; version=3", 
+                "testBDB_hash_3.db");
+        assertTypeByData(
+                "application/x-berkeley-db; format=hash; version=4", 
+                "testBDB_hash_4.db");
+        assertTypeByData(
+                "application/x-berkeley-db; format=hash; version=5", 
+                "testBDB_hash_5.db");
+    }
 
     private void assertText(byte[] prefix) throws IOException {
         assertMagic("text/plain", prefix);


Reply via email to