Added: tika/site/src/site/apt/2.6.0/parser.apt URL: http://svn.apache.org/viewvc/tika/site/src/site/apt/2.6.0/parser.apt?rev=1905121&view=auto ============================================================================== --- tika/site/src/site/apt/2.6.0/parser.apt (added) +++ tika/site/src/site/apt/2.6.0/parser.apt Mon Nov 7 11:40:42 2022 @@ -0,0 +1,251 @@ + -------------------- + The Parser interface + -------------------- + +~~ Licensed to the Apache Software Foundation (ASF) under one or more +~~ contributor license agreements. See the NOTICE file distributed with +~~ this work for additional information regarding copyright ownership. +~~ The ASF licenses this file to You under the Apache License, Version 2.0 +~~ (the "License"); you may not use this file except in compliance with +~~ the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, software +~~ distributed under the License is distributed on an "AS IS" BASIS, +~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +~~ See the License for the specific language governing permissions and +~~ limitations under the License. + +The Parser interface + + The + {{{./api/org/apache/tika/parser/Parser.html}org.apache.tika.parser.Parser}} + interface is the key concept of Apache Tika. It hides the complexity of + different file formats and parsing libraries while providing a simple and + powerful mechanism for client applications to extract structured text + content and metadata from all sorts of documents. All this is achieved + with a single method: + +--- +void parse( + InputStream stream, ContentHandler handler, Metadata metadata, + ParseContext context) throws IOException, SAXException, TikaException; +--- + + The <<<parse>>> method takes the document to be parsed and related metadata + as input and outputs the results as XHTML SAX events and extra metadata. + The parse context argument is used to specify context information (like + the current local) that is not related to any individual document. + The main criteria that lead to this design were: + + [Streamed parsing] The interface should require neither the client + application nor the parser implementation to keep the full document + content in memory or spooled to disk. This allows even huge documents + to be parsed without excessive resource requirements. + + [Structured content] A parser implementation should be able to + include structural information (headings, links, etc.) in the extracted + content. A client application can use this information for example to + better judge the relevance of different parts of the parsed document. + + [Input metadata] A client application should be able to include metadata + like the file name or declared content type with the document to be + parsed. The parser implementation can use this information to better + guide the parsing process. + + [Output metadata] A parser implementation should be able to return + document metadata in addition to document content. Many document + formats contain metadata like the name of the author that may be useful + to client applications. + + [Context sensitivity] While the default settings and behaviour of Tika + parsers should work well for most use cases, there are still situations + where more fine-grained control over the parsing process is desirable. + It should be easy to inject such context-specific information to the + parsing process without breaking the layers of abstraction. + + [] + + These criteria are reflected in the arguments of the <<<parse>>> method. + +* Document input stream + + The first argument is an + {{{http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html}InputStream}} + for reading the document to be parsed. + + If this document stream can not be read, then parsing stops and the thrown + {{{http://docs.oracle.com/javase/6/docs/api/java/io/IOException.html}IOException}} + is passed up to the client application. If the stream can be read but + not parsed (for example if the document is corrupted), then the parser + throws a {{{./api/org/apache/tika/exception/TikaException.html}TikaException}}. + + The parser implementation will consume this stream but <will not close it>. + Closing the stream is the responsibility of the client application that + opened it in the first place. The recommended pattern for using streams + with the <<<parse>>> method is: + +--- +InputStream stream = ...; // open the stream +try { + parser.parse(stream, ...); // parse the stream +} finally { + stream.close(); // close the stream +} +--- + + Some document formats like the OLE2 Compound Document Format used by + Microsoft Office are best parsed as random access files. In such cases the + content of the input stream is automatically spooled to a temporary file + that gets removed once parsed. A future version of Tika may make it possible + to avoid this extra file if the input document is already a file in the + local file system. See + {{{https://issues.apache.org/jira/browse/TIKA-153}TIKA-153}} for the status + of this feature request. + +* XHTML SAX events + + The parsed content of the document stream is returned to the client + application as a sequence of XHTML SAX events. XHTML is used to express + structured content of the document and SAX events enable streamed + processing. Note that the XHTML format is used here only to convey + structural information, not to render the documents for browsing! + + The XHTML SAX events produced by the parser implementation are sent to a + {{{http://docs.oracle.com/javase/6/docs/api/org/xml/sax/ContentHandler.html}ContentHandler}} + instance given to the <<<parse>>> method. If this the content handler + fails to process an event, then parsing stops and the thrown + {{{http://docs.oracle.com/javase/6/docs/api/org/xml/sax/SAXException.html}SAXException}} + is passed up to the client application. + + The overall structure of the generated event stream is (with indenting + added for clarity): + +--- +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <title>...</title> + </head> + <body> + ... + </body> +</html> +--- + + Parser implementations typically use the + {{{./api/org/apache/tika/sax/XHTMLContentHandler.html}XHTMLContentHandler}} + utility class to generate the XHTML output. + + Dealing with the raw SAX events can be a bit complex, so Apache Tika + comes with a number of utility classes that can be used to process and + convert the event stream to other representations. + + For example, the + {{{./api/org/apache/tika/sax/BodyContentHandler.html}BodyContentHandler}} + class can be used to extract just the body part of the XHTML output and + feed it either as SAX events to another content handler or as characters + to an output stream, a writer, or simply a string. The following code + snippet parses a document from the standard input stream and outputs the + extracted text content to standard output: + +--- +ContentHandler handler = new BodyContentHandler(System.out); +parser.parse(System.in, handler, ...); +--- + + Another useful class is + {{{./api/org/apache/tika/parser/ParsingReader.html}ParsingReader}} that + uses a background thread to parse the document and returns the extracted + text content as a character stream: + +--- +InputStream stream = ...; // the document to be parsed +Reader reader = new ParsingReader(parser, stream, ...); +try { + ...; // read the document text using the reader +} finally { + reader.close(); // the document stream is closed automatically +} +--- + +* Document metadata + + The third argument to the <<<parse>>> method is used to pass document + metadata both in and out of the parser. Document metadata is expressed + as an {{{./api/org/apache/tika/metadata/Metadata.html}Metadata}} object. + + The following are some of the more interesting metadata properties: + + [Metadata.RESOURCE_NAME_KEY] The name of the file or resource that contains + the document. + + A client application can set this property to allow the parser to use + file name heuristics to determine the format of the document. + + The parser implementation may set this property if the file format + contains the canonical name of the file (for example the Gzip format + has a slot for the file name). + + [Metadata.CONTENT_TYPE] The declared content type of the document. + + A client application can set this property based on for example a HTTP + Content-Type header. The declared content type may help the parser to + correctly interpret the document. + + The parser implementation sets this property to the content type according + to which the document was parsed. + + [Metadata.TITLE] The title of the document. + + The parser implementation sets this property if the document format + contains an explicit title field. + + [Metadata.AUTHOR] The name of the author of the document. + + The parser implementation sets this property if the document format + contains an explicit author field. + + [] + + Note that metadata handling is still being discussed by the Tika development + team, and it is likely that there will be some (backwards incompatible) + changes in metadata handling before Tika 1.0. + +* Parse context + + + The final argument to the <<<parse>>> method is used to inject + context-specific information to the parsing process. This is useful + for example when dealing with locale-specific date and number formats + in Microsoft Excel spreadsheets. Another important use of the parse + context is passing in the delegate parser instance to be used by + two-phase parsers like the + {{{./api/org/apache/parser/pkg/PackageParser.html}PackageParser}} subclasses. + Some parser classes allow customization of the parsing process through + strategy objects in the parse context. + +* Parser implementations + + Apache Tika comes with a number of parser classes for parsing + {{{./formats.html}various document formats}}. You can also extend Tika + with your own parsers, and of course any contributions to Tika are + warmly welcome. + + The goal of Tika is to reuse existing parser libraries like + {{{http://pdfbox.apache.org/}PDFBox}} or + {{{http://poi.apache.org/}Apache POI}} as much as possible, and so most + of the parser classes in Tika are adapters to such external libraries. + + Tika also contains some general purpose parser implementations that are + not targeted at any specific document formats. The most notable of these + is the {{{./api/org/apache/tika/parser/AutoDetectParser.html}AutoDetectParser}} + class that encapsulates all Tika functionality into a single parser that + can handle any types of documents. This parser will automatically determine + the type of the incoming document based on various heuristics and will then + parse the document accordingly. + +* {More Examples} + + For more examples of calling Parsing with Apache Tika, please take a look at + the {{{./examples.html}Tika Examples page}}.
Added: tika/site/src/site/apt/2.6.0/parser_guide.apt URL: http://svn.apache.org/viewvc/tika/site/src/site/apt/2.6.0/parser_guide.apt?rev=1905121&view=auto ============================================================================== --- tika/site/src/site/apt/2.6.0/parser_guide.apt (added) +++ tika/site/src/site/apt/2.6.0/parser_guide.apt Mon Nov 7 11:40:42 2022 @@ -0,0 +1,141 @@ + -------------------------------------------- + Get Tika parsing up and running in 5 minutes + -------------------------------------------- + +~~ Licensed to the Apache Software Foundation (ASF) under one or more +~~ contributor license agreements. See the NOTICE file distributed with +~~ this work for additional information regarding copyright ownership. +~~ The ASF licenses this file to You under the Apache License, Version 2.0 +~~ (the "License"); you may not use this file except in compliance with +~~ the License. You may obtain a copy of the License at +~~ +~~ http://www.apache.org/licenses/LICENSE-2.0 +~~ +~~ Unless required by applicable law or agreed to in writing, software +~~ distributed under the License is distributed on an "AS IS" BASIS, +~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +~~ See the License for the specific language governing permissions and +~~ limitations under the License. + +Get Tika parsing up and running in 5 minutes + + This page is a quick start guide showing how to add a new parser to Apache Tika. + Following the simple steps listed below your new parser can be running in only 5 minutes. + +%{toc|section=1|fromDepth=1} + +* {Getting Started} + + The {{{./gettingstarted.html}Getting Started}} document describes how to + build Apache Tika from sources and how to start using Tika in an application. Pay close attention + and follow the instructions in the "Getting and building the sources" section. + + +* {Add your MIME-Type} + + Tika loads the core, standard MIME-Types from the file + "org/apache/tika/mime/tika-mimetypes.xml", which comes from + {{{https://gitbox.apache.org/repos/asf?p=tika.git;a=blob;f=tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml;hb=refs/heads/master}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> +--- + +* {Create your Parser class} + + Now, you need to create your new parser. This is a class that must + implement the Parser interface offered by Tika. Instead of implementing + the Parser interface directly, it is recommended that you extend the + abstract class AbstractParser if possible. AbstractParser handles + translating between API changes for you. + + A very simple Tika Parser looks like this: + +--- +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @Author: Arturo Beltran + */ +package org.apache.tika.parser.hello; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.Set; + +import org.apache.tika.exception.TikaException; +import org.apache.tika.metadata.Metadata; +import org.apache.tika.mime.MediaType; +import org.apache.tika.parser.ParseContext; +import org.apache.tika.parser.AbstractParser; +import org.apache.tika.sax.XHTMLContentHandler; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; + +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(); + } +} +--- + + Pay special attention to the definition of the SUPPORTED_TYPES static class + field in the parser class that defines what MIME-Types it supports. 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. + If you figure out the correct parser in a different way, it isn't needed. + + List your new parser in: + {{{https://gitbox.apache.org/repos/asf?p=tika.git;a=blob;f=tika-parsers/src/main/resources/META-INF/services/org.apache.tika.parser.Parser;hb=refs/heads/master}tika-parsers/src/main/resources/META-INF/services/org.apache.tika.parser.Parser}} + + Modified: tika/site/src/site/apt/index.apt.vm URL: http://svn.apache.org/viewvc/tika/site/src/site/apt/index.apt.vm?rev=1905121&r1=1905120&r2=1905121&view=diff ============================================================================== --- tika/site/src/site/apt/index.apt.vm (original) +++ tika/site/src/site/apt/index.apt.vm Mon Nov 7 11:40:42 2022 @@ -42,10 +42,17 @@ Apache Tika - a content analysis toolkit Latest News + [07 November 2022: Apache Tika Release] + Apache Tika 2.6.0 has been released! This release includes an optional integration with the Siegfried detector, + a bug fix to the OpenSearch emitter and dependency upgrades. Please see the + {{{https://dist.apache.org/repos/dist/release/tika/2.6.0/CHANGES-2.6.0.txt}CHANGES.txt}} + file for the full list of changes in the release and have a look at the download page for more information + on how to obtain Apache Tika 2.6.0. + [03 October 2022: Apache Tika Release] Apache Tika 2.5.0 has been released! This release includes improvements to configurability and customization as well as security related fixes - and dependency upgrades. Please see the {{{https://dist.apache.org/repos/dist/release/tika/2.5.0/CHANGES-2.5.0.txt}CHANGES.txt}} + and dependency upgrades. Please see the {{{https://archive.apache.org/dist/tika/2.5.0/CHANGES-2.5.0.txt}CHANGES.txt}} file for the full list of changes in the release and have a look at the download page for more information on how to obtain Apache Tika 2.5.0. @@ -54,7 +61,7 @@ Latest News [14 September 2022: Apache Tika Release] Apache Tika 1.28.5 has been released! This release includes a security related fix - and dependency upgrades. Please see the {{{https://dist.apache.org/repos/dist/release/tika/1.28.5/CHANGES-1.28.5.txt}CHANGES.txt}} + and dependency upgrades. Please see the {{{https://archive.apache.org/dist/tika/1.28.5/CHANGES-1.28.5.txt}CHANGES.txt}} file for the full list of changes in the release and have a look at the download page for more information on how to obtain Apache Tika 1.28.5. Modified: tika/site/src/site/resources/doap.rdf URL: http://svn.apache.org/viewvc/tika/site/src/site/resources/doap.rdf?rev=1905121&r1=1905120&r2=1905121&view=diff ============================================================================== --- tika/site/src/site/resources/doap.rdf (original) +++ tika/site/src/site/resources/doap.rdf Mon Nov 7 11:40:42 2022 @@ -42,6 +42,13 @@ <category rdf:resource="http://projects.apache.org/category/library" /> <release> <Version> + <name>Apache Tika 2.6.0</name> + <created>2022-11-07</created> + <revision>2.6.0</revision> + </Version> + </release> + <release> + <Version> <name>Apache Tika 2.5.0</name> <created>2022-10-03</created> <revision>2.5.0</revision> Modified: tika/site/src/site/site.xml URL: http://svn.apache.org/viewvc/tika/site/src/site/site.xml?rev=1905121&r1=1905120&r2=1905121&view=diff ============================================================================== --- tika/site/src/site/site.xml (original) +++ tika/site/src/site/site.xml Mon Nov 7 11:40:42 2022 @@ -42,7 +42,17 @@ <item name="Security" href="security.html"/> </menu> <menu name="Documentation"> - <item name="Apache Tika 2.5.0" href="2.5.0/index.html"> + <item name="Apache Tika 2.6.0" href="2.6.0/index.html"> + <item name="Getting Started" href="2.6.0/gettingstarted.html"/> + <item name="Supported Formats" href="2.6.0/formats.html"/> + <item name="Parser API" href="2.6.0/parser.html"/> + <item name="Parser 5min Quick Start Guide" href="2.6.0/parser_guide.html"/> + <item name="Content and Language Detection" href="2.6.0/detection.html"/> + <item name="Configuring Tika" href="2.6.0/configuring.html"/> + <item name="Usage Examples" href="2.6.0/examples.html"/> + <item name="API Documentation" href="2.6.0/api/"/> + </item> + <item name="Apache Tika 2.5.0" href="2.5.0/index.html" collapse="true"> <item name="Getting Started" href="2.5.0/gettingstarted.html"/> <item name="Supported Formats" href="2.5.0/formats.html"/> <item name="Parser API" href="2.5.0/parser.html"/>