Class Xmp

All Implemented Interfaces:
AutoCloseable

public class Xmp extends ChilkatObject
<section class="xmp-summary">

Read, modify, add, remove, and save XMP metadata in JPG and TIFF files.

Chilkat.Xmp is a legacy class for working with embedded XMP metadata in JPG and TIFF image files. It can load image files or image data from memory, locate embedded XMP documents, return XMP metadata as Chilkat.Xml, create new XMP documents, add or update simple string and integer properties, manage arrays and structured properties, add namespace mappings, remove selected XMP properties or entire embedded XMP documents, and save the updated image back to a file or byte buffer.

Legacy class: Chilkat.Xmp is maintained for existing JPG/TIFF XMP workflows, but it is not planned to be extended to support additional file types.

Load JPG or TIFF metadata

Load a JPG or TIFF file from disk or memory and inspect how many embedded XMP documents were found.

Access XMP as XML

Retrieve embedded XMP documents as Chilkat.Xml objects for inspection, editing, or direct XML-level processing.

Add simple properties

Add or update namespace-qualified string and integer properties such as dc:subject, photoshop:Credit, or tiff:XResolution.

Arrays and structures

Work with XMP arrays such as bag, seq, and alt, and manage structured property values.

Namespaces

Use built-in namespace mappings or add custom namespace-to-URI mappings for application-specific XMP properties.

Remove and save

Remove properties, arrays, structures, or embedded XMP documents, then persist changes to a file or return the updated image as a byte buffer.

Common pattern: Load a JPG or TIFF with LoadAppFile or LoadFromBuffer, retrieve an embedded XMP document with GetEmbedded or create one with NewXmp, modify it using the add/remove property methods, then call SaveAppFile or SaveToBuffer to persist the updated image metadata.

Persistence note: Changes made to the XMP XML object are not written back to the image file until SaveAppFile is called. For memory workflows, use SaveToBuffer to obtain the updated JPG or TIFF bytes.

</section>

Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when done; an unclosed instance is freed when it becomes unreachable.

See Also:
Online reference
  • Constructor Details

    • Xmp

      public Xmp()
      Creates a new Xmp object.
  • Method Details

    • getNumEmbedded

      public int getNumEmbedded()
      The number of XMP metadata documents found within the JPG or TIFF file loaded by LoadAppFile.
      Returns:
      the value of the NumEmbedded property (read-only)
    • getStructInnerDescrip

      public boolean getStructInnerDescrip()
      Determines whether structures are stored with rdf:parseType=Resource, or within an rdf:Description sub-node.
      Returns:
      the value of the StructInnerDescrip property
    • setStructInnerDescrip

      public void setStructInnerDescrip​(boolean value)
      Sets the StructInnerDescrip property; see getStructInnerDescrip().
      Parameters:
      value - the new value
    • getUncommonOptions

      public String getUncommonOptions()
      A property to be used for future uncommon needs. The default value is the empty string.
      Returns:
      the value of the UncommonOptions property
    • setUncommonOptions

      public void setUncommonOptions​(String value)
      Sets the UncommonOptions property; see getUncommonOptions().
      Parameters:
      value - the new value (not null)
    • addArray

      public void addArray​(Xml xml, String arrType, String propName, StringArray values)
      Adds or replaces an XMP property array. The XMP metadata to be updated is contained in the XML object passed in the 1st argument. The 2nd argument specifies the array type, which can be bag, seq, or alt. The property name should be prefixed with the namespace, such as dc:subject.
      Parameters:
      xml - the xml argument (not null)
      arrType - the arrType argument (not null)
      propName - the propName argument (not null)
      values - the values argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addNsMapping

      public void addNsMapping​(String ns, String uri)
      Adds a namespace to URI mapping. When a property is added via AddSimpleString or any of the other methods, the property name is namespace qualified. When adding the first property in a namespace, the rdf:Description is automatically added and the URI is obtained from the namespace-to-URI mappings. The standard (and commonly used) namespace mappings are defined by default. This is only used if the namespace is custom or not already handled.
      Parameters:
      ns - the ns argument (not null)
      uri - the uri argument (not null)
    • addSimpleInt

      public void addSimpleInt​(Xml iXml, String propName, int propVal)
      Adds or updates an XMP integer property. The XMP metadata to be updated is contained in the XML object passed in the 1st argument. The property name should be prefixed with the namespace, such as tiff:XResolution.
      Parameters:
      iXml - the iXml argument (not null)
      propName - the propName argument (not null)
      propVal - the propVal argument
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addSimpleStr

      public void addSimpleStr​(Xml iXml, String propName, String propVal)
      Adds or updates a simple XMP string property. The XMP metadata to be updated is contained in the XML object passed in the 1st argument. The property name should be prefixed with the namespace, such as photoshop:Credit.
      Parameters:
      iXml - the iXml argument (not null)
      propName - the propName argument (not null)
      propVal - the propVal argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • addStructProp

      public void addStructProp​(Xml iChilkatXml, String structName, String propName, String propValue)
      Adds or updates an XMP structured property value. The XMP metadata to be updated is contained in the XML object passed in the 1st argument. The structure name should be prefixed with the namespace, such as Iptc4xmpCore:CreatorContactInfo. The property name within the structure should also be prefixed with the namespace, such as Iptc4xmpCore:CiAdrCity.
      Parameters:
      iChilkatXml - the iChilkatXml argument (not null)
      structName - the structName argument (not null)
      propName - the propName argument (not null)
      propValue - the propValue argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • append

      public void append​(Xml iXml)
      Appends a new XMP metadata file to the XMP object. Any XMPs appended via this method will be present in the file when SaveAppFile is called. Files containing XMP metadata typically only include a single XMP document, so this method is usually only called when adding XMP metadata to a file for the first time.
      Parameters:
      iXml - the iXml argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • getArray

      public StringArray getArray​(Xml iXml, String propName)
      Finds and returns an XMP array property. The property name should be prefixed with the namespace, such as dc:subject.
      Parameters:
      iXml - the iXml argument (not null)
      propName - the propName argument (not null)
      Returns:
      a new StringArray owned by the caller, or null if not found (no exception is thrown in that case); close it when done
    • getEmbedded

      public Xml getEmbedded​(int index)
      Returns the Nth embedded XMP document as a Chilkat XML object.
      Parameters:
      index - the index argument
      Returns:
      a new Xml owned by the caller (never null); close it when done
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • getProperty

      public Xml getProperty​(Xml iXml, String propName)
      The GetProperty method.
      Parameters:
      iXml - the iXml argument (not null)
      propName - the propName argument (not null)
      Returns:
      a new Xml owned by the caller (never null); close it when done
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • getSimpleInt

      public int getSimpleInt​(Xml iXml, String propName)
      Finds and returns an XMP integer property. The property name should be prefixed with the namespace, such as tiff:ResolutionUnit.
      Parameters:
      iXml - the iXml argument (not null)
      propName - the propName argument (not null)
      Returns:
      the result (see ChilkatObject.getLastMethodSuccess() where the description mentions failure)
    • getSimpleStr

      public String getSimpleStr​(Xml iXml, String propName)
      Finds and returns an XMP simple string property. The property name should be prefixed with the namespace, such as photoshop:Source.
      Parameters:
      iXml - the iXml argument (not null)
      propName - the propName argument (not null)
      Returns:
      the result (never null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • getStructPropNames

      public StringArray getStructPropNames​(Xml iXml, String structName)
      Returns the property names used by an exsting structure within an XMP document. The contents of the structure can be retrieved by calling GetStructValue for each property name returned by GetStructPropNames.
      Parameters:
      iXml - the iXml argument (not null)
      structName - the structName argument (not null)
      Returns:
      a new StringArray owned by the caller (never null); close it when done
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • getStructValue

      public String getStructValue​(Xml iXml, String structName, String propName)
      Returns the value of a single item within an XMP structure property. Property names should always be prefixed with the namespace.
      Parameters:
      iXml - the iXml argument (not null)
      structName - the structName argument (not null)
      propName - the propName argument (not null)
      Returns:
      the result (never null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • loadAppFile

      public void loadAppFile​(String filename)
      Loads a TIFF or JPG file into the XMP object.
      Parameters:
      filename - the filename argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • newXmp

      public Xml newXmp()
      Creates and returns a new/empty XMP metadata document as a Chilkat XML object.
      Returns:
      a new Xml owned by the caller (never null); close it when done
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • removeAllEmbedded

      public void removeAllEmbedded()
      Removes all XMP metadata documents from an XMP object. After calling this method, call SaveAppFile to rewrite the JPG or TIFF file with the XMP metadata removed.
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • removeArray

      public void removeArray​(Xml iXml, String propName)
      Removes an XMP array property from the XMP document.
      Parameters:
      iXml - the iXml argument (not null)
      propName - the propName argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • removeEmbedded

      public void removeEmbedded​(int index)
      Removes a single XMP metadata document from the JPG or TIFF file. Call SaveAppFile to persist the changes to disk.
      Parameters:
      index - the index argument
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • removeNsMapping

      public void removeNsMapping​(String ns)
      Removes a namespace-to-URI mapping.
      Parameters:
      ns - the ns argument (not null)
    • removeSimple

      public void removeSimple​(Xml iXml, String propName)
      Removes a simple XMP property from the XMP document.
      Parameters:
      iXml - the iXml argument (not null)
      propName - the propName argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • removeStruct

      public void removeStruct​(Xml iXml, String structName)
      Removes an XMP structure property from the XMP document.
      Parameters:
      iXml - the iXml argument (not null)
      structName - the structName argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • removeStructProp

      public void removeStructProp​(Xml iXml, String structName, String propName)
      Removes a single member from an XMP structured property.
      Parameters:
      iXml - the iXml argument (not null)
      structName - the structName argument (not null)
      propName - the propName argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why
    • saveAppFile

      public void saveAppFile​(String filename)
      Persists all changes made to the XMP document(s) by saving the XMP object to a file. Changes made by adding, updating, or removing properties are not persisted to the filesystem until this is called.
      Parameters:
      filename - the filename argument (not null)
      Throws:
      ChilkatException - if the operation fails; ChilkatException.getLastErrorText() says why