Class ParserLoader

All Implemented Interfaces:
ComponentLoader<Parser>

public class ParserLoader extends AbstractSpiComponentLoader<Parser>
Loader for parsers with support for:
  • SPI fallback via "default-parser" marker with exclusions
  • Mime type filtering decorations (_mime-include, _mime-exclude)
  • EncodingDetector, Renderer and content-enricher dependency injection
  • Constructor Details

    • ParserLoader

      public ParserLoader()
  • Method Details

    • loadComponent

      protected Parser loadComponent(String name, com.fasterxml.jackson.databind.JsonNode configNode, LoaderContext context) throws TikaConfigException
      Description copied from class: AbstractSpiComponentLoader
      Load a single component from config. The default instantiates the named component from its config; subclasses override to apply decorations (e.g., mime filtering for parsers).
      Overrides:
      loadComponent in class AbstractSpiComponentLoader<Parser>
      Parameters:
      name - the component name (friendly name or FQCN)
      configNode - the JSON configuration for this component
      context - the loader context
      Returns:
      the loaded component
      Throws:
      TikaConfigException - if loading fails
    • createDefaultComposite

      protected Parser createDefaultComposite(Set<Class<? extends Parser>> exclusions, LoaderContext context)
      Description copied from class: AbstractSpiComponentLoader
      Create the SPI-backed default composite with exclusions. E.g., new DefaultParser(..., exclusions) or new DefaultDetector(..., exclusions)
      Specified by:
      createDefaultComposite in class AbstractSpiComponentLoader<Parser>
      Parameters:
      exclusions - classes to exclude from SPI loading
      context - the loader context
      Returns:
      the default composite
    • getAllowedMarkerKeys

      protected Set<String> getAllowedMarkerKeys()
      Description copied from class: AbstractSpiComponentLoader
      The set of keys permitted inside a marker config (e.g., inside default-parser). Subclasses extend this when they consume additional framework-level decorators on the marker.

      Default: just "exclude". ParserLoader adds the mime-filter decorators.

      Overrides:
      getAllowedMarkerKeys in class AbstractSpiComponentLoader<Parser>
    • decorateDefaultComposite

      protected Parser decorateDefaultComposite(Parser parser, com.fasterxml.jackson.databind.JsonNode configNode, LoaderContext context) throws TikaConfigException
      Description copied from class: AbstractSpiComponentLoader
      Decorate the default composite with additional behavior. E.g., for parsers, apply mime filtering from _mime-include/_mime-exclude. Default: returns the composite unchanged.
      Overrides:
      decorateDefaultComposite in class AbstractSpiComponentLoader<Parser>
      Parameters:
      parser - the default composite
      configNode - the JSON configuration for the default marker (may be null)
      context - the loader context
      Returns:
      the decorated composite
      Throws:
      TikaConfigException - if decoration fails
    • wrapInComposite

      protected Parser wrapInComposite(List<Parser> parsers, LoaderContext context)
      Description copied from class: AbstractSpiComponentLoader
      Wrap a list of components in a composite. E.g., new CompositeParser(registry, list) or new CompositeDetector(registry, list)
      Specified by:
      wrapInComposite in class AbstractSpiComponentLoader<Parser>
      Parameters:
      parsers - the list of components
      context - the loader context
      Returns:
      the composite component
    • unwrapClass

      protected Class<? extends Parser> unwrapClass(Parser component)
      Description copied from class: AbstractSpiComponentLoader
      Unwrap a component to get the underlying class for auto-exclusion purposes. When a component is wrapped in a decorator (e.g., ParserDecorator for mime filtering), we need to exclude the underlying class from SPI, not the decorator class. Subclasses can override this for type-specific unwrapping.
      Overrides:
      unwrapClass in class AbstractSpiComponentLoader<Parser>
    • postProcess

      protected Parser postProcess(Parser parser, LoaderContext context) throws TikaConfigException
      Description copied from class: AbstractSpiComponentLoader
      Post-process a single component (e.g., inject dependencies). Default: returns the component unchanged.
      Overrides:
      postProcess in class AbstractSpiComponentLoader<Parser>
      Parameters:
      parser - the component to post-process
      context - the loader context
      Returns:
      the post-processed component
      Throws:
      TikaConfigException - if post-processing fails
    • finish

      protected Parser finish(Parser root, LoaderContext context) throws TikaConfigException
      Content enrichers are settled once, over the whole tree: the configured list, or with none, one engine per type resolved from the enrichers among the loaded parsers. Either way every EnrichingParser gets a composite (possibly empty), the effective engines are logged, and every engine under "parsers", the deprecated shape, is called out with what the entry does today.
      Overrides:
      finish in class AbstractSpiComponentLoader<Parser>
      Parameters:
      root - the fully assembled component
      context - the loader context
      Returns:
      the component to hand out
      Throws:
      TikaConfigException - if finishing fails