Search in sources :

Example 1 with ExecutableParser

use of org.apache.tika.parser.executable.ExecutableParser in project tika by apache.

the class TikaParserConfigTest method testParserExcludeFromDefault.

@Test
public void testParserExcludeFromDefault() throws Exception {
    TikaConfig config = getConfig("TIKA-1558-blacklist.xml");
    assertNotNull(config.getParser());
    assertNotNull(config.getDetector());
    CompositeParser parser = (CompositeParser) config.getParser();
    MediaType PE_EXE = MediaType.application("x-msdownload");
    MediaType ELF = MediaType.application("x-elf");
    // Get the DefaultParser from the config
    ParserDecorator confWrappedParser = (ParserDecorator) parser.getParsers().get(MediaType.APPLICATION_XML);
    assertNotNull(confWrappedParser);
    DefaultParser confParser = (DefaultParser) confWrappedParser.getWrappedParser();
    // Get a fresh "default" DefaultParser
    DefaultParser normParser = new DefaultParser(config.getMediaTypeRegistry());
    // The default one will offer the Executable Parser
    assertContains(PE_EXE, normParser.getSupportedTypes(context));
    assertContains(ELF, normParser.getSupportedTypes(context));
    boolean hasExec = false;
    for (Parser p : normParser.getParsers().values()) {
        if (p instanceof ExecutableParser) {
            hasExec = true;
            break;
        }
    }
    assertTrue(hasExec);
    // The one from the config won't
    assertNotContained(PE_EXE, confParser.getSupportedTypes(context));
    assertNotContained(ELF, confParser.getSupportedTypes(context));
    for (Parser p : confParser.getParsers().values()) {
        if (p instanceof ExecutableParser)
            fail("Shouldn't have the Executable Parser from config");
    }
}
Also used : CompositeParser(org.apache.tika.parser.CompositeParser) ParserDecorator(org.apache.tika.parser.ParserDecorator) MediaType(org.apache.tika.mime.MediaType) ExecutableParser(org.apache.tika.parser.executable.ExecutableParser) DefaultParser(org.apache.tika.parser.DefaultParser) Parser(org.apache.tika.parser.Parser) ExecutableParser(org.apache.tika.parser.executable.ExecutableParser) CompositeParser(org.apache.tika.parser.CompositeParser) XMLParser(org.apache.tika.parser.xml.XMLParser) DefaultParser(org.apache.tika.parser.DefaultParser) EmptyParser(org.apache.tika.parser.EmptyParser) Test(org.junit.Test)

Aggregations

MediaType (org.apache.tika.mime.MediaType)1 CompositeParser (org.apache.tika.parser.CompositeParser)1 DefaultParser (org.apache.tika.parser.DefaultParser)1 EmptyParser (org.apache.tika.parser.EmptyParser)1 Parser (org.apache.tika.parser.Parser)1 ParserDecorator (org.apache.tika.parser.ParserDecorator)1 ExecutableParser (org.apache.tika.parser.executable.ExecutableParser)1 XMLParser (org.apache.tika.parser.xml.XMLParser)1 Test (org.junit.Test)1