Class ParseContextConfig
This wrapper provides a safe way for parsers to access runtime configuration without directly depending on tika-serialization. It performs these critical checks:
- If ParseContext has JSON config for the requested key but ConfigDeserializer is not on the classpath, throws TikaConfigException with a clear error message
- If ConfigDeserializer is available, delegates to it for deserialization
- If no config is present, returns the default config
Usage in parsers:
PDFParserConfig localConfig = ParseContextConfig.getConfig(
context, "pdf-parser", PDFParserConfig.class, defaultConfig);
- Since:
- Apache Tika 4.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TgetConfig(ParseContext context, String configKey, Class<T> configClass, T defaultConfig) Retrieves runtime configuration from ParseContext.static booleanhasConfig(ParseContext context, String configKey) Checks if runtime configuration exists for the given key.static booleanChecks if ConfigDeserializer is available on the classpath.
-
Constructor Details
-
ParseContextConfig
public ParseContextConfig()
-
-
Method Details
-
getConfig
public static <T> T getConfig(ParseContext context, String configKey, Class<T> configClass, T defaultConfig) throws TikaConfigException, IOException Retrieves runtime configuration from ParseContext.Resolution is per config key and config class: the resolved-config cache, then JSON config (deserialized and cached). A class-keyed entry set programmatically via
context.set(configClass, config)is honored only when no JSON config exists for the key, since several components may share one config class.This method performs defensive checking: if the ParseContext has JSON configuration for the requested key but the ConfigDeserializer is not available on the classpath, it throws TikaConfigException to prevent silent failures.
- Type Parameters:
T- the configuration type- Parameters:
context- the parse context (may be null)configKey- the configuration key (e.g., "pdf-parser", "html-parser")configClass- the configuration classdefaultConfig- the default configuration to use if no runtime config exists- Returns:
- the runtime config merged with defaults, or the default config if no runtime config
- Throws:
TikaConfigException- if ParseContext has JSON config but ConfigDeserializer is not on classpathIOException- if deserialization fails
-
hasConfig
Checks if runtime configuration exists for the given key.Unlike
getConfig(org.apache.tika.parser.ParseContext, java.lang.String, java.lang.Class<T>, T), this method does NOT throw if ConfigDeserializer is missing - it only checks for the presence of config.- Parameters:
context- the parse contextconfigKey- the configuration key- Returns:
- true if JSON config exists for this key
-
isConfigDeserializerAvailable
public static boolean isConfigDeserializerAvailable()Checks if ConfigDeserializer is available on the classpath.- Returns:
- true if tika-serialization is available
-