Class ParsingEmbeddedDocumentExtractor

java.lang.Object
org.apache.tika.extractor.ParsingEmbeddedDocumentExtractor
All Implemented Interfaces:
EmbeddedDocumentExtractor
Direct Known Subclasses:
UnpackExtractor

public class ParsingEmbeddedDocumentExtractor extends Object implements EmbeddedDocumentExtractor
Helper class for parsers of package archives or other compound document formats that support embedded or attached component documents.

Stateless: every method takes the ParseContext of the enclosing parse as a parameter rather than capturing one at construction, so a single shared instance (INSTANCE) is safe to reuse across parses and threads.

Since:
Apache Tika 0.8
  • Field Details

  • Constructor Details

    • ParsingEmbeddedDocumentExtractor

      public ParsingEmbeddedDocumentExtractor()
  • Method Details

    • shouldParseEmbedded

      public boolean shouldParseEmbedded(Metadata metadata, ParseContext context)
      Description copied from interface: EmbeddedDocumentExtractor
      Determines whether the given embedded document should be parsed.

      Note: Implementations may throw EmbeddedLimitReachedException (a RuntimeException) if a limit is exceeded and throwing is configured.

      Specified by:
      shouldParseEmbedded in interface EmbeddedDocumentExtractor
      Parameters:
      metadata - the metadata for the embedded document
      context - the parse context of the enclosing parse
      Returns:
      true if the embedded document should be parsed
    • checkEmbeddedLimits

      protected boolean checkEmbeddedLimits(ParseRecord parseRecord, ParseContext context)
      Checks embedded document limits from ParseRecord: the task deadline, then max count, then max depth.

      If throwing is configured for the limit hit, the corresponding EmbeddedLimitReachedException is thrown. Otherwise, returns false and sets the appropriate limit flag on the ParseRecord.

      Note: The deadline and count limits are hard stops (once hit, no more embedded docs are parsed). The depth limit only affects documents at that depth - sibling documents at shallower depths will still be parsed.

      Subclasses that override parseEmbedded() should call this method to enforce limits.

      Parameters:
      parseRecord - the parse record to check
      context - the parse context of the enclosing parse
      Returns:
      true if the embedded document should be parsed, false if limits are exceeded
      Throws:
      EmbeddedLimitReachedException - if a limit is exceeded and throwing is configured
    • parseEmbedded

      public void parseEmbedded(TikaInputStream tis, ContentHandler handler, Metadata metadata, ParseContext context, boolean outputHtml) throws SAXException, IOException
      Description copied from interface: EmbeddedDocumentExtractor
      Processes the supplied embedded resource, calling the delegating parser with the appropriate details.
      Specified by:
      parseEmbedded in interface EmbeddedDocumentExtractor
      Parameters:
      tis - The embedded resource
      handler - The handler to use
      metadata - The metadata for the embedded resource
      context - The parse context
      outputHtml - Should we output HTML for this resource, or has the parser already done so?
      Throws:
      SAXException
      IOException
    • recordException

      protected void recordException(Exception e, ParseContext context)
    • getDelegatingParser

      public Parser getDelegatingParser()
    • isWriteFileNameToContent

      public boolean isWriteFileNameToContent(ParseContext context)
      Returns whether to write file names to content based on SAXOutputConfig in the ParseContext. Defaults to true if no config is present.
      Parameters:
      context - the parse context of the enclosing parse
      Returns:
      true if file names should be written to content