Access Metadata Fields
This section explains how to process metadata fields using the KeyView API.
Standardized Fields
When KeyView understands the meaning of a metadata field in a document, it outputs that data in a standardized field. For a MetadataElement
that represents a standardized field:
-
isStandard()
returnstrue
. -
getStandardKey()
returns the standardized field key, which indicates the meaning of the field. For a full list of the standardized metadata fields, refer to the documentation for theMetadataKey
enum in the JavaDocs. -
getKey()
returns a string that is uniquely determined by the standard field key. If you are handling the value of a standardized field based on its standardized name, you can ignore this value. It is provided so that standardized fields can optionally be handled in the same way as non-standardized fields.
Each standardized field 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 fields
Non-standardized fields include user created fields, or fields that are specific to that type of document. KeyView handles these in the following way:
isStandard()
returnsfalse
.getStandardKey()
returnsOTHER
to signify that it is a non-standardized field.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 to describe the field.
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.