Package org.apache.tika.config.loader
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
Base loader for components that support SPI fallback with exclusions.
Handles the common pattern for loading Parsers, Detectors, and EncodingDetectors:
- Check if config section exists
- Find "default-xxx" marker and extract exclusions
- Load explicitly configured components
- Auto-exclude configured component classes from SPI
- Create Default* composite with combined exclusions
- Post-process (e.g., inject dependencies)
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSpiComponentLoader(String sectionName, String defaultMarkerName, Class<T> componentClass) Creates a new SPI component loader. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract TcreateDefaultComposite(Set<Class<? extends T>> exclusions, LoaderContext context) Create the SPI-backed default composite with exclusions.protected TdecorateDefaultComposite(T composite, com.fasterxml.jackson.databind.JsonNode configNode, LoaderContext context) Decorate the default composite with additional behavior.protected Stringprotected Stringprotected ThandleSpecialName(String name, com.fasterxml.jackson.databind.JsonNode configNode, LoaderContext context) Handle special component names that require custom loading.load(TikaJsonConfig config, LoaderContext context) Load components from the JSON config.protected abstract TloadComponent(String name, com.fasterxml.jackson.databind.JsonNode configNode, LoaderContext context) Load a single component from config.protected TpostProcess(T component, LoaderContext context) Post-process a single component (e.g., inject dependencies).postProcessList(List<T> components, LoaderContext context) Post-process a list of components (e.g., inject dependencies).unwrapClass(T component) Unwrap a component to get the underlying class for auto-exclusion purposes.protected abstract TwrapInComposite(List<T> components, LoaderContext context) Wrap a list of components in a composite.
-
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
Description copied from interface:ComponentLoaderLoad components from the JSON config.- Specified by:
loadin interfaceComponentLoader<T>- Parameters:
config- the JSON configurationcontext- 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 componentcontext- 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 loadingcontext- the loader context- Returns:
- the default composite
-
wrapInComposite
Wrap a list of components in a composite. E.g., new CompositeParser(registry, list) or new CompositeDetector(registry, list)- Parameters:
components- the list of componentscontext- the loader context- Returns:
- the composite component
-
postProcess
Post-process a single component (e.g., inject dependencies). Default: returns the component unchanged.- Parameters:
component- the component to post-processcontext- 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-processcontext- 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 nameconfigNode- the JSON configurationcontext- 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 compositeconfigNode- the JSON configuration for the default marker (may be null)context- the loader context- Returns:
- the decorated composite
- Throws:
TikaConfigException- if decoration fails
-
unwrapClass
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
-
getDefaultMarkerName
-
getComponentClass
-