Class Xmp
- All Implemented Interfaces:
AutoCloseable
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArray(Xml xml, String arrType, String propName, StringArray values)Adds or replaces an XMP property array.voidaddNsMapping(String ns, String uri)Adds a namespace to URI mapping.voidaddSimpleInt(Xml iXml, String propName, int propVal)Adds or updates an XMP integer property.voidaddSimpleStr(Xml iXml, String propName, String propVal)Adds or updates a simple XMP string property.voidaddStructProp(Xml iChilkatXml, String structName, String propName, String propValue)Adds or updates an XMP structured property value.voidAppends a new XMP metadata file to the XMP object.Finds and returns an XMP array property.getEmbedded(int index)Returns the Nth embedded XMP document as a Chilkat XML object.intThe number of XMP metadata documents found within the JPG or TIFF file loaded by LoadAppFile.getProperty(Xml iXml, String propName)The GetProperty method.intgetSimpleInt(Xml iXml, String propName)Finds and returns an XMP integer property.getSimpleStr(Xml iXml, String propName)Finds and returns an XMP simple string property.booleanDetermines whether structures are stored with rdf:parseType=Resource, or within anrdf:Descriptionsub-node.getStructPropNames(Xml iXml, String structName)Returns the property names used by an exsting structure within an XMP document.getStructValue(Xml iXml, String structName, String propName)Returns the value of a single item within an XMP structure property.A property to be used for future uncommon needs.voidloadAppFile(String filename)Loads a TIFF or JPG file into the XMP object.newXmp()Creates and returns a new/empty XMP metadata document as a Chilkat XML object.voidRemoves all XMP metadata documents from an XMP object.voidremoveArray(Xml iXml, String propName)Removes an XMP array property from the XMP document.voidremoveEmbedded(int index)Removes a single XMP metadata document from the JPG or TIFF file.voidremoveNsMapping(String ns)Removes a namespace-to-URI mapping.voidremoveSimple(Xml iXml, String propName)Removes a simple XMP property from the XMP document.voidremoveStruct(Xml iXml, String structName)Removes an XMP structure property from the XMP document.voidremoveStructProp(Xml iXml, String structName, String propName)Removes a single member from an XMP structured property.voidsaveAppFile(String filename)Persists all changes made to the XMP document(s) by saving the XMP object to a file.voidsetStructInnerDescrip(boolean value)Sets theStructInnerDescripproperty; seegetStructInnerDescrip().voidsetUncommonOptions(String value)Sets theUncommonOptionsproperty; seegetUncommonOptions().Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
Xmp
public Xmp()Creates a newXmpobject.
-
-
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
NumEmbeddedproperty (read-only)
-
getStructInnerDescrip
public boolean getStructInnerDescrip()Determines whether structures are stored with rdf:parseType=Resource, or within anrdf:Descriptionsub-node.- Returns:
- the value of the
StructInnerDescripproperty
-
setStructInnerDescrip
public void setStructInnerDescrip(boolean value)Sets theStructInnerDescripproperty; seegetStructInnerDescrip().- Parameters:
value- the new value
-
getUncommonOptions
A property to be used for future uncommon needs. The default value is the empty string.- Returns:
- the value of the
UncommonOptionsproperty
-
setUncommonOptions
Sets theUncommonOptionsproperty; seegetUncommonOptions().- Parameters:
value- the new value (notnull)
-
addArray
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 bebag,seq, oralt. The property name should be prefixed with the namespace, such asdc:subject.- Parameters:
xml- thexmlargument (notnull)arrType- thearrTypeargument (notnull)propName- thepropNameargument (notnull)values- thevaluesargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addNsMapping
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- thensargument (notnull)uri- theuriargument (notnull)
-
addSimpleInt
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 astiff:XResolution.- Parameters:
iXml- theiXmlargument (notnull)propName- thepropNameargument (notnull)propVal- thepropValargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addSimpleStr
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 asphotoshop:Credit.- Parameters:
iXml- theiXmlargument (notnull)propName- thepropNameargument (notnull)propVal- thepropValargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
addStructProp
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 asIptc4xmpCore:CreatorContactInfo. The property name within the structure should also be prefixed with the namespace, such asIptc4xmpCore:CiAdrCity.- Parameters:
iChilkatXml- theiChilkatXmlargument (notnull)structName- thestructNameargument (notnull)propName- thepropNameargument (notnull)propValue- thepropValueargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
append
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- theiXmlargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getArray
Finds and returns an XMP array property. The property name should be prefixed with the namespace, such asdc:subject.- Parameters:
iXml- theiXmlargument (notnull)propName- thepropNameargument (notnull)- Returns:
- a new
StringArrayowned by the caller, ornullif not found (no exception is thrown in that case); close it when done
-
getEmbedded
Returns the Nth embedded XMP document as a Chilkat XML object.- Parameters:
index- theindexargument- Returns:
- a new
Xmlowned by the caller (nevernull); close it when done - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getProperty
The GetProperty method.- Parameters:
iXml- theiXmlargument (notnull)propName- thepropNameargument (notnull)- Returns:
- a new
Xmlowned by the caller (nevernull); close it when done - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getSimpleInt
Finds and returns an XMP integer property. The property name should be prefixed with the namespace, such astiff:ResolutionUnit.- Parameters:
iXml- theiXmlargument (notnull)propName- thepropNameargument (notnull)- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
getSimpleStr
Finds and returns an XMP simple string property. The property name should be prefixed with the namespace, such asphotoshop:Source.- Parameters:
iXml- theiXmlargument (notnull)propName- thepropNameargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getStructPropNames
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- theiXmlargument (notnull)structName- thestructNameargument (notnull)- Returns:
- a new
StringArrayowned by the caller (nevernull); close it when done - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getStructValue
Returns the value of a single item within an XMP structure property. Property names should always be prefixed with the namespace.- Parameters:
iXml- theiXmlargument (notnull)structName- thestructNameargument (notnull)propName- thepropNameargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadAppFile
Loads a TIFF or JPG file into the XMP object.- Parameters:
filename- thefilenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
newXmp
Creates and returns a new/empty XMP metadata document as a Chilkat XML object.- Returns:
- a new
Xmlowned by the caller (nevernull); 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
Removes an XMP array property from the XMP document.- Parameters:
iXml- theiXmlargument (notnull)propName- thepropNameargument (notnull)- 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- theindexargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
removeNsMapping
Removes a namespace-to-URI mapping.- Parameters:
ns- thensargument (notnull)
-
removeSimple
Removes a simple XMP property from the XMP document.- Parameters:
iXml- theiXmlargument (notnull)propName- thepropNameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
removeStruct
Removes an XMP structure property from the XMP document.- Parameters:
iXml- theiXmlargument (notnull)structName- thestructNameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
removeStructProp
Removes a single member from an XMP structured property.- Parameters:
iXml- theiXmlargument (notnull)structName- thestructNameargument (notnull)propName- thepropNameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
saveAppFile
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- thefilenameargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-