Class PresetRegistry

java.lang.Object
org.apache.tika.config.loader.PresetRegistry

public final class PresetRegistry extends Object
Named, vetted parse-context fragments a caller selects whole, by name only ("presets"). A preset is operator config, not caller input: resolved with the same trust as the config's own parse-context block, and fully resolved at load so a bad preset fails startup, not its first request.

Nothing is active unless the config's presets block names it: true activates the classpath-catalog definition of that name (error if absent), an object defines the preset in place (replacing any catalog definition wholesale), false/null is an explicit no-op. Catalog jars can never activate themselves. Presets do not compose.

The catalog is discovered from META-INF/tika/preset-catalog.properties resources (hand-authored, unlike the annotation processor's generated META-INF/tika/*.idx), each line name=/classpath/resource.json; blank lines and # comments ignored.

 "presets": {
   "some-catalog-preset": true,
   "ocr-heavy": { "pages": { "text": "EXTRACT_AND_OCR" } }
 }
 
Since:
Apache Tika 4.1.0
  • Field Details

  • Method Details

    • load

      public static PresetRegistry load(TikaJsonConfig config, ClassLoader classLoader) throws TikaConfigException
      Builds the active roster from the config's presets block (see the class javadoc for the value semantics), resolving every active preset.
      Parameters:
      config - the loaded config, may be null (empty roster)
      classLoader - for catalog scanning and component resolution; null for the thread context loader
      Throws:
      TikaConfigException
    • isValidName

      public static boolean isValidName(String name)
      Legal preset name: the NAME rule, and not "config"-prefixed (tika-server gates /config endpoints on that path fragment). Public so wire deserializers can bound a preset-name field with the same rule.
    • names

      public Set<String> names()
    • hasPreset

      public boolean hasPreset(String name)
    • parseContextJson

      public String parseContextJson(String name)
      The preset's parse-context-shaped JSON, or null for an unknown name.
    • newParseContext

      public ParseContext newParseContext(String name) throws TikaConfigException
      A fully resolved ParseContext for the preset, or null for an unknown name. Fresh per call: callers mutate the result per request.
      Throws:
      TikaConfigException
    • suppliesContentHandlerFactory

      public boolean suppliesContentHandlerFactory(String name)
      True if the preset binds a ContentHandlerFactory (it then owns the output format on routes with no explicit format segment).