Class AbstractSpiComponentLoader<T>

java.lang.Object
org.apache.tika.config.loader.AbstractSpiComponentLoader<T>
Type Parameters:
T - the component type (Parser, Detector, EncodingDetector)
All Implemented Interfaces:
ComponentLoader<T>
Direct Known Subclasses:
DetectorLoader, EncodingDetectorLoader, ParserLoader

public abstract class AbstractSpiComponentLoader<T> extends Object implements ComponentLoader<T>
Base loader for components that support SPI fallback with exclusions.

Handles the common pattern for loading Parsers, Detectors, and EncodingDetectors:

  1. Check if config section exists
  2. Find "default-xxx" marker and extract exclusions
  3. Load explicitly configured components
  4. Auto-exclude configured component classes from SPI
  5. Create Default* composite with combined exclusions
  6. Post-process (e.g., inject dependencies)
  • Constructor Details

    • AbstractSpiComponentLoader

      protected AbstractSpiComponentLoader(String sectionName, String defaultMarkerName, Class<T> componentClass)
      Creates a new SPI component loader.
      Parameters:
      sectionName - the JSON config section name (e.g., "parsers")
      defaultMarkerName - the default marker name (e.g., "default-parser")
      componentClass - the component interface class
  • Method Details

    • load

      public T load(TikaJsonConfig config, LoaderContext context) throws TikaConfigException
      Description copied from interface: ComponentLoader
      Load components from the JSON config.
      Specified by:
      load in interface ComponentLoader<T>
      Parameters:
      config - the JSON configuration
      context - shared context with dependencies and utilities
      Returns:
      the loaded component (typically a composite)
      Throws:
      TikaConfigException - if loading fails
    • loadComponent

      protected abstract T loadComponent(String name, com.fasterxml.jackson.databind.JsonNode configNode, LoaderContext context) throws TikaConfigException
      Load a single component from config. Subclasses can apply decorations (e.g., mime filtering for parsers).
      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 abstract T createDefaultComposite(Set<Class<? extends T>> exclusions, LoaderContext context)
      Create the SPI-backed default composite with exclusions. E.g., new DefaultParser(..., exclusions) or new DefaultDetector(..., exclusions)
      Parameters:
      exclusions - classes to exclude from SPI loading
      context - the loader context
      Returns:
      the default composite
    • wrapInComposite

      protected abstract T wrapInComposite(List<T> components, LoaderContext context)
      Wrap a list of components in a composite. E.g., new CompositeParser(registry, list) or new CompositeDetector(registry, list)
      Parameters:
      components - the list of components
      context - the loader context
      Returns:
      the composite component
    • postProcess

      protected T postProcess(T component, LoaderContext context) throws TikaConfigException
      Post-process a single component (e.g., inject dependencies). Default: returns the component unchanged.
      Parameters:
      component - the component to post-process
      context - the loader context
      Returns:
      the post-processed component
      Throws:
      TikaConfigException - if post-processing fails
    • postProcessList

      protected List<T> postProcessList(List<T> components, LoaderContext context) throws TikaConfigException
      Post-process a list of components (e.g., inject dependencies). Default: calls postProcess on each component.
      Parameters:
      components - the components to post-process
      context - the loader context
      Returns:
      the post-processed components
      Throws:
      TikaConfigException - if post-processing fails
    • handleSpecialName

      protected T handleSpecialName(String name, com.fasterxml.jackson.databind.JsonNode configNode, LoaderContext context) throws TikaConfigException
      Handle special component names that require custom loading. E.g., "mime-types" for detectors returns TikaLoader.getMimeTypes(). Return null for normal handling.
      Parameters:
      name - the component name
      configNode - the JSON configuration
      context - the loader context
      Returns:
      the special component, or null for normal handling
      Throws:
      TikaConfigException - if loading fails
    • decorateDefaultComposite

      protected T decorateDefaultComposite(T composite, com.fasterxml.jackson.databind.JsonNode configNode, LoaderContext context) throws TikaConfigException
      Decorate the default composite with additional behavior. E.g., for parsers, apply mime filtering from _mime-include/_mime-exclude. Default: returns the composite unchanged.
      Parameters:
      composite - 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
    • unwrapClass

      protected Class<? extends T> unwrapClass(T component)
      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.
    • getSectionName

      protected String getSectionName()
    • getDefaultMarkerName

      protected String getDefaultMarkerName()
    • getComponentClass

      protected Class<T> getComponentClass()