Metadata Elements

This section explains how to process metadata elements using the KeyView API.

Standardized Elements

When KeyView understands the meaning of a metadata field in a document, it outputs that data in a standardized element - a MetadataElement where:

  • isStandard() returns true.
  • getStandardKey() returns the standard key, which indicates the meaning of the element. For a list of standard keys, refer to the documentation for the MetadataKey enum in the JavaDocs, or see Standardized Metadata Elements.

  • getKey() returns a string that is uniquely determined by the standard key. If you are handling the value of a standardized element based on its standard key, you can ignore this value. It is provided so that standardized elements can optionally be handled in the same way as non-standardized elements.

  • getHasStandardAlternative() returns false.
  • getIsSuperseded() returns a Boolean that specifies whether this element has been superseded, meaning that this element exists only to preserve backwards compatibility. An element can be superseded to fix issues with the key or value type. When this value is true, the same metadata is available through an improved MetadataElement in the same MetadataList.

Each standardized element is guaranteed to occur at most once in the metadata output. For example, the metadata output will contain zero or one MetadataElement objects with the standardized name TITLE.

Non-standardized Elements

Non-standard elements represent native metadata fields. Some non-standard elements might have been used to create a standardized element, and therefore have a standardized alternative. User-created metadata fields, and fields that are unique to one file format, are usually available only as non-standard elements. For a non-standard metadata element:

  • isStandard() returns false.
  • getStandardKey() returns OTHER.
  • getKey() returns a string representation of a field's key. If a field key exists in the document, that value is returned. Otherwise, KeyView generates a value.
  • getHasStandardAlternative() returns a Boolean that specifies whether the element has a standardized alternative. When this method returns true, this element contains metadata that also exists in a standardized MetadataElement in the same MetadataList.
  • getIsSuperseded() returns a Boolean that specifies whether this element has been superseded, meaning that this element exists only to preserve backwards compatibility. An element can be superseded to fix issues with the key or value type. When this value is true, the same metadata is available through an improved MetadataElement in the same MetadataList.

Field Values

To obtain a field value as a string, you can call the method getValueAsString() on a MetadataElement object.

However, you might prefer to process metadata field values as appropriate types through a visitor pattern. To do this, write a class that inherits from the MetadataVisitor class and handles each of the possible metadata types. Then, pass your class to the accept() method of a MetadataList or MetadataElement object.

For example code that demonstrates how to do this, see the FilterTest sample program.