Class KeyPrefix

java.lang.Object
org.apache.tika.metadata.KeyPrefix

public final class KeyPrefix extends Object
A Tika-owned prefix under which keys are passed through from the source: the prefix is fixed, but each key name comes verbatim from the document or tool, so keys are unbounded and can't be Property constants. Declaring one self-registers it, so the open set is enumerable (as Property makes the closed set) and lintable: a String write is legitimate iff its key is a registered Property or its prefix is a registered KeyPrefix.

Writes under a prefix go through Metadata.add(KeyPrefix, String, String) (or its Instant overload for source-typed dates) — append-only, with built-in skip-and-WARN handling of blank, over-length, or flooding source-derived names.

KeyPrefix instances are declaration-time constants. Declare one as a static final field, the same way a curated Property constant is declared — never construct one from document-derived text, and never construct one per-parse: the registry is static and unbounded, so per-parse construction grows it forever. An identical redeclaration (class re-init in another classloader) returns the incumbent; a conflicting one throws IllegalStateException.

Since:
Apache Tika 4.0.0
  • Method Details

    • file

      public static KeyPrefix file(String prefix, String description)
      Declares a FILE-provenance prefix: names read from the document itself. An identical redeclaration (same provenance and description, e.g. class re-initialization in another classloader) returns the incumbent instance.
      Throws:
      IllegalArgumentException - if prefix is null, empty, reserved, or lacks a trailing delimiter
      IllegalStateException - if prefix is already registered with a different provenance or description
    • tool

      public static KeyPrefix tool(String prefix, String description)
      Declares a TOOL-provenance prefix: names coined by an external tool or service. An identical redeclaration returns the incumbent instance; see file(java.lang.String, java.lang.String).
      Throws:
      IllegalArgumentException - if prefix is null, empty, reserved, or lacks a trailing delimiter
      IllegalStateException - if prefix is already registered with a different provenance or description
    • get

      public static KeyPrefix get(String prefix)
      The registered prefix instance for prefix, or null.
    • key

      public String key(String suffix)
      The full key for a source-derived suffix.
      Throws:
      IllegalArgumentException - if suffix is null or empty
    • prefix

      public String prefix()
    • provenance

      public KeyPrefix.Provenance provenance()
    • description

      public String description()
    • toString

      public String toString()
      The prefix, so a String→KeyPrefix flip doesn't turn existing logging/concatenation into KeyPrefix@<hex> with no compile signal.
      Overrides:
      toString in class Object
    • registered

      public static Collection<KeyPrefix> registered()
      Declared prefixes, from loaded classes only.