use of org.apache.tika.parser.AutoDetectParser in project tika by apache.
the class FontParsersTest method testTTFParsing.
@Test
public void testTTFParsing() throws Exception {
// Should auto-detect!
Parser parser = new AutoDetectParser();
ContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
ParseContext context = new ParseContext();
try (TikaInputStream stream = TikaInputStream.get(FontParsersTest.class.getResource("/test-documents/testTrueType3.ttf"))) {
parser.parse(stream, handler, metadata, context);
}
assertEquals("application/x-font-ttf", metadata.get(Metadata.CONTENT_TYPE));
assertEquals("Open Sans Bold", metadata.get(TikaCoreProperties.TITLE));
assertEquals("2010-12-30T11:04:00Z", metadata.get(Metadata.CREATION_DATE));
assertEquals("2010-12-30T11:04:00Z", metadata.get(TikaCoreProperties.CREATED));
assertEquals("2011-05-05T12:37:53Z", metadata.get(TikaCoreProperties.MODIFIED));
assertEquals("Open Sans Bold", metadata.get(MET_FONT_NAME));
assertEquals("Open Sans", metadata.get(MET_FONT_FAMILY_NAME));
assertEquals("Bold", metadata.get(MET_FONT_SUB_FAMILY_NAME));
assertEquals("OpenSans-Bold", metadata.get(MET_PS_NAME));
assertEquals("Digitized", metadata.get("Copyright").substring(0, 9));
assertEquals("Open Sans", metadata.get("Trademark").substring(0, 9));
// Not extracted
assertEquals(null, metadata.get(MET_FONT_FULL_NAME));
assertEquals(null, metadata.get(MET_FONT_WEIGHT));
assertEquals(null, metadata.get(MET_FONT_VERSION));
// Currently, the parser doesn't extract any contents
String content = handler.toString();
assertEquals("", content);
}
use of org.apache.tika.parser.AutoDetectParser in project tika by apache.
the class DBFParserTest method testVariants.
@Test
public void testVariants() throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (InputStream is = getResourceAsStream("/test-documents/testDBF.dbf")) {
IOUtils.copy(is, bos);
}
byte[] bytes = bos.toByteArray();
for (DBFReader.Version version : DBFReader.Version.values()) {
//this cast happens to work because of the range of possible values
bytes[0] = (byte) version.getId();
XMLResult r = getXML(TikaInputStream.get(bytes), new AutoDetectParser(), new Metadata());
assertEquals(version.getFullMimeString(), r.metadata.get(Metadata.CONTENT_TYPE));
}
}
use of org.apache.tika.parser.AutoDetectParser in project tika by apache.
the class TikaResource method createParser.
@SuppressWarnings("serial")
public static Parser createParser() {
final Parser parser = new AutoDetectParser(tikaConfig);
Map<MediaType, Parser> parsers = ((AutoDetectParser) parser).getParsers();
parsers.put(MediaType.APPLICATION_XML, new HtmlParser());
((AutoDetectParser) parser).setParsers(parsers);
((AutoDetectParser) parser).setFallback(new Parser() {
public Set<MediaType> getSupportedTypes(ParseContext parseContext) {
return parser.getSupportedTypes(parseContext);
}
public void parse(InputStream inputStream, ContentHandler contentHandler, Metadata metadata, ParseContext parseContext) {
throw new WebApplicationException(Response.Status.UNSUPPORTED_MEDIA_TYPE);
}
});
if (digester != null) {
return new DigestingParser(parser, digester);
}
return parser;
}
use of org.apache.tika.parser.AutoDetectParser in project stanbol by apache.
the class TikaEngine method activate.
@Override
protected void activate(ComponentContext ctx) throws ConfigurationException {
super.activate(ctx);
config = TikaConfig.getDefaultConfig();
this.detector = config.getDetector();
this.parser = new AutoDetectParser(config);
this.skipLinebreaks = getBoolean(ctx.getProperties(), SKIP_LINEBREAKS_WITHIN_CONTENT, DEFAULT_SKIP_LINEBREAKS);
this.ontologyMappings = new OntologyMappings();
if (getBoolean(ctx.getProperties(), MAPPING_MEDIA_RESOURCE, DEFAULT_MAPPING_MEDIA_RESOURCE_STATE)) {
addMediaResourceOntologyMappings(ontologyMappings);
}
if (getBoolean(ctx.getProperties(), MAPPING_DUBLIN_CORE_TERMS, DEFAULT_MAPPING_DUBLIN_CORE_TERMS_STATE)) {
addDcMappings(ontologyMappings);
}
if (getBoolean(ctx.getProperties(), MAPPING_NEPOMUK_MESSAGE, DEFAULT_MAPPING_NEPOMUK_MESSAGE_STATE)) {
addNepomukMessageMappings(ontologyMappings);
}
if (getBoolean(ctx.getProperties(), MAPPING_NEPOMUK_EXIF, DEFAULT_MAPPING_NEPOMUK_EXIF_STATE)) {
addNepomukExifMappings(ontologyMappings);
}
if (getBoolean(ctx.getProperties(), MAPPING_SKOS, DEFAULT_MAPPING_SKOS_STATE)) {
addSkosMappings(ontologyMappings);
}
if (getBoolean(ctx.getProperties(), MAPPING_RDFS, DEFAULT_MAPPING_RDFS_STATE)) {
addRdfsMappings(ontologyMappings);
}
if (getBoolean(ctx.getProperties(), MAPPING_GEO, DEFAULT_MAPPING_GEO_STATE)) {
addGeoMappings(ontologyMappings);
}
includeUnmappedProperties = getBoolean(ctx.getProperties(), UNMAPPED_PROPERTIES, DEFAULT_UNMAPPED_PROPERTIES_STATE);
}
use of org.apache.tika.parser.AutoDetectParser in project tika by apache.
the class TIAParsingExample method testHtmlMapper.
public static void testHtmlMapper() throws Exception {
InputStream stream = new ByteArrayInputStream(new byte[0]);
ContentHandler handler = new DefaultHandler();
Metadata metadata = new Metadata();
Parser parser = new AutoDetectParser();
ParseContext context = new ParseContext();
context.set(HtmlMapper.class, new IdentityHtmlMapper());
parser.parse(stream, handler, metadata, context);
}
Aggregations