Search in sources :

Example 11 with CompositeDetector

use of org.apache.tika.detect.CompositeDetector in project tika by apache.

the class TikaDetectorConfigTest method testDetectorExcludeFromDefault.

@Test
public void testDetectorExcludeFromDefault() throws Exception {
    TikaConfig config = getConfig("TIKA-1702-detector-blacklist.xml");
    assertNotNull(config.getParser());
    assertNotNull(config.getDetector());
    CompositeDetector detector = (CompositeDetector) config.getDetector();
    // Should be wrapping two detectors
    assertEquals(2, detector.getDetectors().size());
    // First should be DefaultDetector, second Empty, that order
    assertEquals(DefaultDetector.class, detector.getDetectors().get(0).getClass());
    assertEquals(EmptyDetector.class, detector.getDetectors().get(1).getClass());
    // Get the DefaultDetector from the config
    DefaultDetector confDetector = (DefaultDetector) detector.getDetectors().get(0);
    // Get a fresh "default" DefaultParser
    DefaultDetector normDetector = new DefaultDetector(config.getMimeRepository());
    // The default one will offer the Zip and POIFS detectors
    assertDetectors(normDetector, true, true);
    // The one from the config won't, as we excluded those
    assertDetectors(confDetector, false, false);
}
Also used : DefaultDetector(org.apache.tika.detect.DefaultDetector) CompositeDetector(org.apache.tika.detect.CompositeDetector) Test(org.junit.Test)

Aggregations

CompositeDetector (org.apache.tika.detect.CompositeDetector)11 Detector (org.apache.tika.detect.Detector)7 DefaultDetector (org.apache.tika.detect.DefaultDetector)4 Test (org.junit.Test)3 Tika (org.apache.tika.Tika)2 Metadata (org.apache.tika.metadata.Metadata)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 URL (java.net.URL)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TikaConfig (org.apache.tika.config.TikaConfig)1 TikaConfigSerializer (org.apache.tika.config.TikaConfigSerializer)1 CompositeEncodingDetector (org.apache.tika.detect.CompositeEncodingDetector)1 DefaultEncodingDetector (org.apache.tika.detect.DefaultEncodingDetector)1 EmptyDetector (org.apache.tika.detect.EmptyDetector)1