Class XMPMetadata

java.lang.Object
org.apache.tika.metadata.Metadata
org.apache.tika.xmp.XMPMetadata
All Implemented Interfaces:
Serializable, ClimateForcast, CreativeCommons, Geographic, HttpHeaders, Message, TIFF, TikaMimeKeys

public class XMPMetadata extends Metadata
Provides a conversion of the Metadata map from Tika to the XMP data model by also providing the Metadata API for clients to ease transition. But clients can also work directly on the XMP data model, by getting the XMPMeta reference from this class. Usually the instance would be initialized by providing the Metadata object that had been returned from Tika-core which populates the XMP data model with all properties that can be converted.

This class is not serializable!

See Also:
  • Constructor Details

    • XMPMetadata

      public XMPMetadata()
      Initializes with an empty XMP packet
    • XMPMetadata

      public XMPMetadata(Metadata meta) throws TikaException
      Throws:
      TikaException
      See Also:
    • XMPMetadata

      public XMPMetadata(Metadata meta, String mimetype) throws TikaException
      Initializes the data by converting the Metadata information to XMP. If a mimetype is provided, a specific converter can be used, that converts all available metadata. If there is no mimetype provided or no specific converter available a generic conversion is done which will convert only those properties that are in known namespaces and are using the correct prefixes
      Parameters:
      meta - the Metadata information from Tika-core
      mimetype - mimetype information
      Throws:
      TikaException - case an error occurred during conversion
  • Method Details

    • registerNamespace

      public static String registerNamespace(String namespaceURI, String suggestedPrefix) throws com.adobe.internal.xmp.XMPException
      Register a namespace URI with a suggested prefix. It is not an error if the URI is already registered, no matter what the prefix is. If the URI is not registered but the suggested prefix is in use, a unique prefix is created from the suggested one. The actual registered prefix is always returned. The function result tells if the registered prefix is the suggested one. Note: No checking is presently done on either the URI or the prefix.
      Parameters:
      namespaceURI - The URI for the namespace. Must be a valid XML URI.
      suggestedPrefix - The suggested prefix to be used if the URI is not yet registered. Must be a valid XML name.
      Returns:
      Returns the registered prefix for this URI, is equal to the suggestedPrefix if the namespace hasn't been registered before, otherwise the existing prefix.
      Throws:
      com.adobe.internal.xmp.XMPException - If the parameters are not accordingly set
    • getNamespacePrefix

      public static String getNamespacePrefix(String namespaceURI)
      Obtain the prefix for a registered namespace URI. It is not an error if the namespace URI is not registered.
      Parameters:
      namespaceURI - The URI for the namespace. Must not be null or the empty string.
      Returns:
      Returns the prefix registered for this namespace URI or null.
    • getNamespaceURI

      public static String getNamespaceURI(String namespacePrefix)
      Obtain the URI for a registered namespace prefix. It is not an error if the namespace prefix is not registered.
      Parameters:
      namespacePrefix - The prefix for the namespace. Must not be null or the empty string.
      Returns:
      Returns the URI registered for this prefix or null.
    • getNamespaces

      public static Map<String,String> getNamespaces()
      Returns:
      Returns the registered prefix/namespace-pairs as map, where the keys are the namespaces and the values are the prefixes.
    • getPrefixes

      public static Map<String,String> getPrefixes()
      Returns:
      Returns the registered namespace/prefix-pairs as map, where the keys are the prefixes and the values are the namespaces.
    • deleteNamespace

      public static void deleteNamespace(String namespaceURI)
      Deletes a namespace from the registry.

      Does nothing if the URI is not registered, or if the namespaceURI parameter is null or the empty string.

      Note: Not yet implemented.

      Parameters:
      namespaceURI - The URI for the namespace.
    • process

      public void process(Metadata meta) throws TikaException
      Throws:
      TikaException
      See Also:
    • process

      public void process(Metadata meta, String mimetype) throws TikaException
      Converts the Metadata information to XMP. If a mimetype is provided, a specific converter can be used, that converts all available metadata. If there is no mimetype provided or no specific converter available a generic conversion is done which will convert only those properties that are in known namespaces and are using the correct prefixes
      Parameters:
      meta - the Metadata information from Tika-core
      mimetype - mimetype information
      Throws:
      TikaException - case an error occurred during conversion
    • getXMPData

      public com.adobe.internal.xmp.XMPMeta getXMPData()
      Provides direct access to the XMP data model, in case a client prefers to work directly on it instead of using the Metadata API
      Returns:
      the "internal" XMP data object
    • isMultiValued

      public boolean isMultiValued(Property property)
      Description copied from class: Metadata
      Returns true if named value is multivalued.
      Overrides:
      isMultiValued in class Metadata
      Parameters:
      property - metadata property
      Returns:
      true is named value is multivalued, false if single value or null
      See Also:
    • isMultiValued

      public boolean isMultiValued(String name)
      Checks if the named property is an array.
      Overrides:
      isMultiValued in class Metadata
      Parameters:
      name - name of metadata
      Returns:
      true is named value is multivalued, false if single value or null
      See Also:
    • names

      public String[] names()
      For XMP it is not clear what that API should return, therefor not implemented
      Overrides:
      names in class Metadata
      Returns:
      Metadata names
    • get

      public String get(String name)
      Returns the value of a simple property or the first one of an array. The given name must contain a namespace prefix of a registered namespace.
      Overrides:
      get in class Metadata
      Parameters:
      name - of the metadata.
      Returns:
      the value associated to the specified metadata name.
      See Also:
    • get

      public String get(Property property)
      Description copied from class: Metadata
      Returns the value (if any) of the identified metadata property.
      Overrides:
      get in class Metadata
      Parameters:
      property - property definition
      Returns:
      property value, or null if the property is not set
      See Also:
    • getInt

      public Integer getInt(Property property)
      Description copied from class: Metadata
      Returns the value of the identified Integer based metadata property.
      Overrides:
      getInt in class Metadata
      Parameters:
      property - simple integer property definition
      Returns:
      property value as a Integer, or null if the property is not set, or not a valid Integer
      See Also:
    • getDate

      public Date getDate(Property property)
      Description copied from class: Metadata
      Returns the value of the identified Date based metadata property.
      Overrides:
      getDate in class Metadata
      Parameters:
      property - simple date property definition
      Returns:
      property value as a Date, or null if the property is not set, or not a valid Date
      See Also:
    • getValues

      public String[] getValues(Property property)
      Description copied from class: Metadata
      Get the values associated to a metadata name.
      Overrides:
      getValues in class Metadata
      Parameters:
      property - of the metadata.
      Returns:
      the values associated to a metadata name.
      See Also:
    • getValues

      public String[] getValues(String name)
      Returns the value of a simple property or all if the property is an array and the elements are of simple type. The given name must contain a namespace prefix of a registered namespace.
      Overrides:
      getValues in class Metadata
      Parameters:
      name - of the metadata.
      Returns:
      the values associated to a metadata name.
      See Also:
    • add

      public void add(String name, String value)
      As this API could only possibly work for simple properties in XMP, it just calls the set method, which replaces any existing value
      Overrides:
      add in class Metadata
      Parameters:
      name - the metadata name.
      value - the metadata value.
      See Also:
    • set

      public void set(String name, String value)
      Sets the given property. If the property already exists, it is overwritten. Only simple properties that use a registered prefix are stored in the XMP.
      Overrides:
      set in class Metadata
      Parameters:
      name - the metadata name.
      value - the metadata value, or null
      See Also:
    • set

      public void set(Property property, String value)
      Description copied from class: Metadata
      Sets the value of the identified metadata property.
      Overrides:
      set in class Metadata
      Parameters:
      property - property definition
      value - property value
      See Also:
    • set

      public void set(Property property, int value)
      Description copied from class: Metadata
      Sets the integer value of the identified metadata property.
      Overrides:
      set in class Metadata
      Parameters:
      property - simple integer property definition
      value - property value
      See Also:
    • set

      public void set(Property property, double value)
      Description copied from class: Metadata
      Sets the real or rational value of the identified metadata property.
      Overrides:
      set in class Metadata
      Parameters:
      property - simple real or simple rational property definition
      value - property value
      See Also:
    • set

      public void set(Property property, Date date)
      Description copied from class: Metadata
      Sets the date value of the identified metadata property.
      Overrides:
      set in class Metadata
      Parameters:
      property - simple integer property definition
      date - property value
      See Also:
    • set

      public void set(Property property, String[] values)
      Sets array properties. If the property already exists, it is overwritten. Only array properties that use a registered prefix are stored in the XMP.
      Overrides:
      set in class Metadata
      Parameters:
      property - property definition
      values - property values
      See Also:
    • setAll

      public void setAll(Properties properties)
      It will set all simple and array properties that have QName keys in registered namespaces.
      Overrides:
      setAll in class Metadata
      Parameters:
      properties - properties to copy from
      See Also:
    • remove

      public void remove(Property property)
      See Also:
    • remove

      public void remove(String name)
      Removes the given property from the XMP data. If it is a complex property the whole subtree is removed
      Overrides:
      remove in class Metadata
      Parameters:
      name - metadata name to remove
      See Also:
    • size

      public int size()
      Returns the number of top-level namespaces
      Overrides:
      size in class Metadata
      Returns:
      number of metadata names
    • equals

      public boolean equals(Object o)
      This method is not implemented, yet. It is very tedious to check for semantic equality of XMP packets
      Overrides:
      equals in class Metadata
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Metadata
    • toString

      public String toString()
      Serializes the XMP data in compact form without packet wrapper
      Overrides:
      toString in class Metadata
      See Also: