Class EmbeddedDocumentUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumType of embedded resource, used for generating canonical resource names. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgenerateResourceName(EmbeddedDocumentUtil.EmbeddedResourcePrefix type, int count, String mediaType) Generates a canonical resource name from a type, counter, and media type.static DetectorgetDetector(ParseContext context) Looks up theDetectorconfigured for this parse.static EmbeddedDocumentExtractorgetEmbeddedDocumentExtractor(ParseContext context) Looks up theEmbeddedDocumentExtractorconfigured for this parse.static StringgetExtension(TikaInputStream is, Metadata metadata, ParseContext context) static StringgetExtensionForMediaType(String mediaType) Looks up the file extension for a given media type string.static MimeTypesgetMimeTypes(ParseContext context) static ParsergetStatelessParser(ParseContext context) Utility function to get the Parser that was sent in to the ParseContext to handle embedded documents.static StringnormalizeMediaType(String mediaType) Normalizes internal OCR routing media types (e.g.,image/ocr-png) back to standard media types (e.g.,image/png).static voidstatic voidrecordException(Throwable t, Metadata m) static voidsetGeneratedResourceName(Metadata metadata, EmbeddedDocumentUtil.EmbeddedResourcePrefix type, int count, String mediaType) Sets a generated resource name on the metadata and marks the extension as inferred.static ParsertryToFindExistingLeafParser(Class clazz, ParseContext context) Tries to find an existing parser within the ParseContext.
-
Method Details
-
getEmbeddedDocumentExtractor
Looks up theEmbeddedDocumentExtractorconfigured for this parse.A configured parse (one that has gone through
AutoDetectParser) always has one bound in the context. If none is bound -- e.g. a concrete parser was invoked directly with a bareParseContext-- this returns the statelessParsingEmbeddedDocumentExtractor.INSTANCE, which delegates to whateverParseris in the context (or silently skips embedded documents if none is set).- Parameters:
context- the parse context- Returns:
- the EmbeddedDocumentExtractor to use for this parse
-
getStatelessParser
Utility function to get the Parser that was sent in to the ParseContext to handle embedded documents. If it is stateful, unwrap it to get its stateless delegating parser.If there is no Parser in the parser context, this will return null.
- Parameters:
context-- Returns:
-
getDetector
Looks up theDetectorconfigured for this parse.A configured parse (one that has gone through
AutoDetectParser) always has one bound in the context. If none is bound -- e.g. a concrete parser was invoked directly with a bareParseContext-- this returnsNoOpDetector.INSTANCErather than constructing an SPI-discoveredDefaultDetector: an honest "unknown" beats a partially-informed guess from a detector the caller never configured.- Parameters:
context- the parse context- Returns:
- the Detector to use for this parse
-
getMimeTypes
-
getExtension
-
normalizeMediaType
Normalizes internal OCR routing media types (e.g.,image/ocr-png) back to standard media types (e.g.,image/png). Returns the input unchanged if it is not an OCR routing type.- Parameters:
mediaType- the media type string- Returns:
- the normalized media type string, or the original if no normalization needed
-
getExtensionForMediaType
Looks up the file extension for a given media type string.- Parameters:
mediaType- the media type string (e.g., "image/png"), parameters allowed- Returns:
- the extension including the dot (e.g., ".png"), or empty string if unknown
-
generateResourceName
public static String generateResourceName(EmbeddedDocumentUtil.EmbeddedResourcePrefix type, int count, String mediaType) Generates a canonical resource name from a type, counter, and media type. For example:generateResourceName(EmbeddedResourcePrefix.EMBEDDED, 0, "image/png")returns"embedded-0.png".- Parameters:
type- the embedded resource typecount- the counter valuemediaType- the media type string, or null if unknown- Returns:
- the generated resource name with extension
-
setGeneratedResourceName
public static void setGeneratedResourceName(Metadata metadata, EmbeddedDocumentUtil.EmbeddedResourcePrefix type, int count, String mediaType) Sets a generated resource name on the metadata and marks the extension as inferred.- Parameters:
metadata- the metadata to updatetype- the embedded resource typecount- the counter valuemediaType- the media type string, or null if unknown
-
recordException
-
recordEmbeddedStreamException
-
tryToFindExistingLeafParser
Tries to find an existing parser within the ParseContext. It looks inside of CompositeParsers and ParserDecorators. The use case is when a parser needs to parse an internal stream that is _part_ of the document, e.g. rtf body inside an msg. Can returnnullif the context contains no parser or the correct parser can't be found.- Parameters:
clazz- parser class to search forcontext-- Returns:
-