Apache Tika - Get Tika parsing up and running in 5 minutes
Add your MIME-Type
If your MIME-Types aren't standard ones, ensure you listed them in a "custom-mimetypes.xml" file so that Tika knows about them (see above).
Is in the "parse" method where you will do all your work. This is, extract the information of the resource and then set the metadata.
Read full article from Apache Tika - Get Tika parsing up and running in 5 minutes
Add your MIME-Type
Tika loads the core, standard MIME-Types from the file "org/apache/tika/mime/tika-mimetypes.xml", which comes from tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml . If your new MIME-Type is a standard one which is missing from Tika, submit a patch for this file!
If your MIME-Type needs adding, create a new file "org/apache/tika/mime/custom-mimetypes.xml" in your codebase. You should add to it something like this:
<?xml version="1.0" encoding="UTF-8"?> <mime-info> <mime-type type="application/hello"> <glob pattern="*.hi"/> </mime-type> </mime-info>
public class HelloParser extends AbstractParser { private static final Set<MediaType> SUPPORTED_TYPES = Collections.singleton(MediaType.application("hello")); public static final String HELLO_MIME_TYPE = "application/hello"; public Set<MediaType> getSupportedTypes(ParseContext context) { return SUPPORTED_TYPES; } public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { metadata.set(Metadata.CONTENT_TYPE, HELLO_MIME_TYPE); metadata.set("Hello", "World"); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); xhtml.endDocument(); } }
If your MIME-Types aren't standard ones, ensure you listed them in a "custom-mimetypes.xml" file so that Tika knows about them (see above).
Is in the "parse" method where you will do all your work. This is, extract the information of the resource and then set the metadata.
List the new parser
Finally, you should explicitly tell the AutoDetectParser to include your new parser. This step is only needed if you want to use the AutoDetectParser functionality.
List your new parser in: tika-parsers/src/main/resources/META-INF/services/org.apache.tika.parser.ParserRead full article from Apache Tika - Get Tika parsing up and running in 5 minutes
No comments:
Post a Comment