Package org.apache.tika.parser.enricher
Class ContentEnrichers
java.lang.Object
org.apache.tika.parser.enricher.ContentEnrichers
Resolves the content enricher for a media type.
Call sites: wrap the handler (an EmbeddedContentHandler over a
BodyContentHandler) so the enricher cannot dump structure or metadata into the
caller's XHTML; resolve on the detected type, captured before a parser can
refine Content-Type mid-parse; pass the target's metadata, or a probe carrying its
Content-Type and EMBEDDED_RESOURCE_TYPE when resolving ahead of a render;
and pass the caller's own ParseContext through -- the recursion guard rides it, so
a fresh context defeats it.
- Since:
- Apache Tika 4.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classScope of asuspend(org.apache.tika.parser.ParseContext)orsuspendRecognizers(org.apache.tika.parser.ParseContext); closing restores the prior state. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBelow this in either dimension an image is a spacer, not a picture: no engine sees it. -
Method Summary
Modifier and TypeMethodDescriptionstatic TextRecognizerasTextRecognizer(Parser parser) TheTextRecognizerunder any decorators; null if the parser is not one.static Parserget(CompositeContentEnricher enrichers, MediaType mediaType, Metadata target, ParseContext context) The enricher to invoke for a media type, or null.static booleanhasTextRecognizer(CompositeContentEnricher enrichers, MediaType mediaType, Metadata target, ParseContext context) Whether the enricherget(org.apache.tika.parser.enricher.CompositeContentEnricher, org.apache.tika.mime.MediaType, org.apache.tika.metadata.Metadata, org.apache.tika.parser.ParseContext)would return produces the document's text: aTextRecognizerthat recognizes for this context, or a legacyimage/ocr-*claimant.static booleanisDisabled(ParseContext context) Whether the request switched the list off:{"text-recognizers": {"enabled": false}}.static booleanisEnricher(Parser parser) True if the parser, under any decorators, is aContentEnricher.static booleanisLegacyOcrType(MediaType mediaType) True for a retiredimage/ocr-*pseudo-type.static CompositeContentEnricherOne enricher per type from the enrichers found in a parser tree: an engine outsideDefaultParserbeats one inside it, the last wins within a tier, and an entry's_mime-include/_mime-excludeapplies at every node.static MediaTypestripLegacyOcrPrefix(MediaType mediaType) The real type behind a retired pseudo-type; any other type unchanged.static ContentEnrichers.Suspensionsuspend(ParseContext context) Suspends dispatch in this context until the returned scope closes.static ContentEnrichers.SuspensionsuspendRecognizers(ParseContext context) Suspends text recognizers only, until the returned scope closes:get(org.apache.tika.parser.enricher.CompositeContentEnricher, org.apache.tika.mime.MediaType, org.apache.tika.metadata.Metadata, org.apache.tika.parser.ParseContext)returns the annotators (embedders, taggers, captioners) andhasTextRecognizer(org.apache.tika.parser.enricher.CompositeContentEnricher, org.apache.tika.mime.MediaType, org.apache.tika.metadata.Metadata, org.apache.tika.parser.ParseContext)is false.
-
Field Details
-
MIN_PIXELS
public static final int MIN_PIXELSBelow this in either dimension an image is a spacer, not a picture: no engine sees it.- See Also:
-
-
Method Details
-
get
public static Parser get(CompositeContentEnricher enrichers, MediaType mediaType, Metadata target, ParseContext context) The enricher to invoke for a media type, or null. A configured list is authoritative: every matching member runs in order and an uncovered type gets nothing. With no list, theContentEnrichers in the composite bound to the context are candidates and one runs, chosen asresolve(org.apache.tika.parser.Parser)chooses. Null while an enrichment is in progress in this context, so an enricher cannot recurse.- Parameters:
enrichers- the injected composite; null when none is configuredmediaType- the real, normalized media type of the bytes; may be nulltarget- the metadata of the image the engine will be handed, or a probe for a render not yet made; dispatch reads only facts from it: an image whose recorded size is underMIN_PIXELSgets nothing
-
suspend
Suspends dispatch in this context until the returned scope closes. A container that enriches a rendering itself wraps the embedded parse of that rendering, so the embedded copy is not enriched a second time. Scopes nest; each restores the state it found. -
suspendRecognizers
Suspends text recognizers only, until the returned scope closes:get(org.apache.tika.parser.enricher.CompositeContentEnricher, org.apache.tika.mime.MediaType, org.apache.tika.metadata.Metadata, org.apache.tika.parser.ParseContext)returns the annotators (embedders, taggers, captioners) andhasTextRecognizer(org.apache.tika.parser.enricher.CompositeContentEnricher, org.apache.tika.mime.MediaType, org.apache.tika.metadata.Metadata, org.apache.tika.parser.ParseContext)is false. A recognizer that declines this parse is still a recognizer, not an annotator. Scopes nest as forsuspend(org.apache.tika.parser.ParseContext). -
hasTextRecognizer
public static boolean hasTextRecognizer(CompositeContentEnricher enrichers, MediaType mediaType, Metadata target, ParseContext context) Whether the enricherget(org.apache.tika.parser.enricher.CompositeContentEnricher, org.apache.tika.mime.MediaType, org.apache.tika.metadata.Metadata, org.apache.tika.parser.ParseContext)would return produces the document's text: aTextRecognizerthat recognizes for this context, or a legacyimage/ocr-*claimant. False while an enrichment is in progress.targetis as forget(org.apache.tika.parser.enricher.CompositeContentEnricher, org.apache.tika.mime.MediaType, org.apache.tika.metadata.Metadata, org.apache.tika.parser.ParseContext). -
resolve
One enricher per type from the enrichers found in a parser tree: an engine outsideDefaultParserbeats one inside it, the last wins within a tier, and an entry's_mime-include/_mime-excludeapplies at every node. A collision within the winning tier is logged once. Empty when the tree holds no enricher. This is what the loader injects when no"text-recognizers"list is configured; the runtime fallback for an unloadedAutoDetectParserapplies the same rules. -
isEnricher
True if the parser, under any decorators, is aContentEnricher. -
asTextRecognizer
TheTextRecognizerunder any decorators; null if the parser is not one. -
isLegacyOcrType
True for a retiredimage/ocr-*pseudo-type. -
stripLegacyOcrPrefix
The real type behind a retired pseudo-type; any other type unchanged. -
isDisabled
Whether the request switched the list off:{"text-recognizers": {"enabled": false}}.
-