Package org.apache.jempbox.xmp
Class XMPMetadata
- java.lang.Object
-
- org.apache.jempbox.xmp.XMPMetadata
-
- Direct Known Subclasses:
XMPMetadataPDFA
public class XMPMetadata extends java.lang.ObjectThis class represents the top level XMP data structure and gives access to the various schemas that are available as part of the XMP specification.- Version:
- $Revision: 1.10 $
- Author:
- Ben Litchfield
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringencodingThe encoding of the XMP document.static java.lang.StringENCODING_UTF16BESupported encoding for persisted XML.static java.lang.StringENCODING_UTF16LESupported encoding for persisted XML.static java.lang.StringENCODING_UTF8Supported encoding for persisted XML.protected java.util.Map<java.lang.String,java.lang.Class<?>>nsMappingsA mapping of namespaces.protected org.w3c.dom.DocumentxmpDocumentThe DOM representation of the metadata.
-
Constructor Summary
Constructors Constructor Description XMPMetadata()Default constructor, creates blank XMP doc.XMPMetadata(org.w3c.dom.Document doc)Constructor from an existing XML document.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description XMPSchemaBasicJobTicketaddBasicJobTicketSchema()Add a new Job Ticket schema.XMPSchemaBasicaddBasicSchema()Create and add a new Basic Schema to this metadata.XMPSchemaDublinCoreaddDublinCoreSchema()Create and add a new Dublin Core Schema to this metadata.XMPSchemaDynamicMediaaddDynamicMediaSchema()Add a new Dynamic Media schema.XMPSchemaIptc4xmpCoreaddIptc4xmpCoreSchema()Create and add a new IPTC schema to this metadata.XMPSchemaMediaManagementaddMediaManagementSchema()Add a new Media Management schema.XMPSchemaPagedTextaddPagedTextSchema()Add a new Paged Text schema.XMPSchemaPDFaddPDFSchema()Create and add a new PDF Schema to this metadata.XMPSchemaPhotoshopaddPhotoshopSchema()Create and add a new Photoshop schema to this metadata.XMPSchemaRightsManagementaddRightsManagementSchema()Add a new Rights Managment schema.voidaddSchema(XMPSchema schema)Add a custom schema to the root rdf.voidaddXMLNSMapping(java.lang.String namespace, java.lang.Class<?> xmpSchema)Will add a XMPSchema to the set of identified schemas.byte[]asByteArray()Get the XML document as a byte array.protected XMPSchemabasicAddSchema(XMPSchema schema)Generic add schema method.XMPSchemaBasicJobTicketgetBasicJobTicketSchema()Get the Job Ticket Schema.XMPSchemaBasicgetBasicSchema()Get the Basic Schema.XMPSchemaDublinCoregetDublinCoreSchema()Get the Dublin Core Schema.XMPSchemaDynamicMediagetDynamicMediaSchema()Get the Dynamic Media Schema.java.lang.StringgetEncoding()Get the current encoding that will be used to write the XML.XMPSchemaMediaManagementgetMediaManagementSchema()Get the Media Management Schema.XMPSchemaPagedTextgetPagedTextSchema()Get the Paged Text Schema.XMPSchemaPDFgetPDFSchema()Get the PDF Schema.XMPSchemaRightsManagementgetRightsManagementSchema()Get the Schema Rights Schema.XMPSchemagetSchemaByClass(java.lang.Class<?> targetSchema)Tries to retrieve a schema from this by classname.java.util.List<XMPSchema>getSchemas()This will get a list of XMPSchema(or subclass) objects.java.util.List<XMPSchema>getSchemasByNamespaceURI(java.lang.String namespaceURI)Will return all schemas that fit the given namespaceURI.org.w3c.dom.DocumentgetXMPDocument()Get the XML document from this object.booleanhasUnknownSchema()This will return true if the XMP contains an unknown schema.static XMPMetadataload(java.io.InputStream is)Load metadata from the filesystem.static XMPMetadataload(java.lang.String file)Load metadata from the filesystem.static XMPMetadataload(org.xml.sax.InputSource is)Load a schema from an input source.static voidmain(java.lang.String[] args)Test main program.voidmerge(XMPMetadata metadata)Merge this metadata with the given metadata object.voidsave(java.io.OutputStream outStream)Save the XMP document to a stream.voidsave(java.lang.String file)Save the XMP document to a file.voidsetEncoding(java.lang.String xmlEncoding)The encoding used to write the XML.
-
-
-
Field Detail
-
ENCODING_UTF8
public static final java.lang.String ENCODING_UTF8
Supported encoding for persisted XML.- See Also:
- Constant Field Values
-
ENCODING_UTF16BE
public static final java.lang.String ENCODING_UTF16BE
Supported encoding for persisted XML.- See Also:
- Constant Field Values
-
ENCODING_UTF16LE
public static final java.lang.String ENCODING_UTF16LE
Supported encoding for persisted XML.- See Also:
- Constant Field Values
-
xmpDocument
protected org.w3c.dom.Document xmpDocument
The DOM representation of the metadata.
-
encoding
protected java.lang.String encoding
The encoding of the XMP document. Default is UTF8.
-
nsMappings
protected java.util.Map<java.lang.String,java.lang.Class<?>> nsMappings
A mapping of namespaces.
-
-
Constructor Detail
-
XMPMetadata
public XMPMetadata() throws java.io.IOExceptionDefault constructor, creates blank XMP doc.- Throws:
java.io.IOException- If there is an error creating the initial document.
-
XMPMetadata
public XMPMetadata(org.w3c.dom.Document doc)
Constructor from an existing XML document.- Parameters:
doc- The root XMP document.
-
-
Method Detail
-
addXMLNSMapping
public void addXMLNSMapping(java.lang.String namespace, java.lang.Class<?> xmpSchema)Will add a XMPSchema to the set of identified schemas. The class needs to have a constructor with parameter Element- Parameters:
namespace- The namespace URI of the schmema for instance http://purl.org/dc/elements/1.1/.xmpSchema- The schema to associated this identifier with.
-
getPDFSchema
public XMPSchemaPDF getPDFSchema() throws java.io.IOException
Get the PDF Schema.- Returns:
- The first PDF schema in the list.
- Throws:
java.io.IOException- If there is an error accessing the schema.
-
getBasicSchema
public XMPSchemaBasic getBasicSchema() throws java.io.IOException
Get the Basic Schema.- Returns:
- The first Basic schema in the list.
- Throws:
java.io.IOException- If there is an error accessing the schema.
-
getDublinCoreSchema
public XMPSchemaDublinCore getDublinCoreSchema() throws java.io.IOException
Get the Dublin Core Schema.- Returns:
- The first Dublin schema in the list.
- Throws:
java.io.IOException- If there is an error accessing the schema.
-
getMediaManagementSchema
public XMPSchemaMediaManagement getMediaManagementSchema() throws java.io.IOException
Get the Media Management Schema.- Returns:
- The first Media Management schema in the list.
- Throws:
java.io.IOException- If there is an error accessing the schema.
-
getRightsManagementSchema
public XMPSchemaRightsManagement getRightsManagementSchema() throws java.io.IOException
Get the Schema Rights Schema.- Returns:
- The first Schema Rights schema in the list.
- Throws:
java.io.IOException- If there is an error accessing the schema.
-
getBasicJobTicketSchema
public XMPSchemaBasicJobTicket getBasicJobTicketSchema() throws java.io.IOException
Get the Job Ticket Schema.- Returns:
- The first Job Ticket schema in the list.
- Throws:
java.io.IOException- If there is an error accessing the schema.
-
getDynamicMediaSchema
public XMPSchemaDynamicMedia getDynamicMediaSchema() throws java.io.IOException
Get the Dynamic Media Schema.- Returns:
- The first Dynamic Media schema in the list.
- Throws:
java.io.IOException- If there is an error accessing the schema.
-
getPagedTextSchema
public XMPSchemaPagedText getPagedTextSchema() throws java.io.IOException
Get the Paged Text Schema.- Returns:
- The first Paged Text schema in the list.
- Throws:
java.io.IOException- If there is an error accessing the schema.
-
addMediaManagementSchema
public XMPSchemaMediaManagement addMediaManagementSchema()
Add a new Media Management schema.- Returns:
- The newly added schema.
-
addRightsManagementSchema
public XMPSchemaRightsManagement addRightsManagementSchema()
Add a new Rights Managment schema.- Returns:
- The newly added schema.
-
addBasicJobTicketSchema
public XMPSchemaBasicJobTicket addBasicJobTicketSchema()
Add a new Job Ticket schema.- Returns:
- The newly added schema.
-
addDynamicMediaSchema
public XMPSchemaDynamicMedia addDynamicMediaSchema()
Add a new Dynamic Media schema.- Returns:
- The newly added schema.
-
addPagedTextSchema
public XMPSchemaPagedText addPagedTextSchema()
Add a new Paged Text schema.- Returns:
- The newly added schema.
-
addSchema
public void addSchema(XMPSchema schema)
Add a custom schema to the root rdf. The schema has to have been created as a child of this XMPMetadata.- Parameters:
schema- The schema to add.
-
save
public void save(java.lang.String file) throws java.lang.ExceptionSave the XMP document to a file.- Parameters:
file- The file to save the XMP document to.- Throws:
java.lang.Exception- If there is an error while writing to the stream.
-
save
public void save(java.io.OutputStream outStream) throws javax.xml.transform.TransformerExceptionSave the XMP document to a stream.- Parameters:
outStream- The stream to save the XMP document to.- Throws:
javax.xml.transform.TransformerException- If there is an error while writing to the stream.
-
asByteArray
public byte[] asByteArray() throws java.lang.ExceptionGet the XML document as a byte array.- Returns:
- The metadata as an XML byte stream.
- Throws:
java.lang.Exception- If there is an error creating the stream.
-
getXMPDocument
public org.w3c.dom.Document getXMPDocument()
Get the XML document from this object.- Returns:
- This object as an XML document.
-
basicAddSchema
protected XMPSchema basicAddSchema(XMPSchema schema)
Generic add schema method.- Parameters:
schema- The schema to add.- Returns:
- The newly added schema.
-
addPDFSchema
public XMPSchemaPDF addPDFSchema()
Create and add a new PDF Schema to this metadata. Typically a XMP document will only have one PDF schema (but multiple are supported) so it is recommended that you first check the existence of a PDF scheme by using getPDFSchema()- Returns:
- A new blank PDF schema that is now part of the metadata.
-
addDublinCoreSchema
public XMPSchemaDublinCore addDublinCoreSchema()
Create and add a new Dublin Core Schema to this metadata. Typically a XMP document will only have one schema for each type (but multiple are supported) so it is recommended that you first check the existence of a this scheme by using getDublinCoreSchema()- Returns:
- A new blank PDF schema that is now part of the metadata.
-
addBasicSchema
public XMPSchemaBasic addBasicSchema()
Create and add a new Basic Schema to this metadata. Typically a XMP document will only have one schema for each type (but multiple are supported) so it is recommended that you first check the existence of a this scheme by using getDublinCoreSchema()- Returns:
- A new blank PDF schema that is now part of the metadata.
-
addIptc4xmpCoreSchema
public XMPSchemaIptc4xmpCore addIptc4xmpCoreSchema()
Create and add a new IPTC schema to this metadata.- Returns:
- A new blank IPTC schema that is now part of the metadata.
-
addPhotoshopSchema
public XMPSchemaPhotoshop addPhotoshopSchema()
Create and add a new Photoshop schema to this metadata.- Returns:
- A new blank Photoshop schema that is now part of the metadata.
-
setEncoding
public void setEncoding(java.lang.String xmlEncoding)
The encoding used to write the XML. Default value:UTF-8
See the ENCODING_XXX constants- Parameters:
xmlEncoding- The encoding to write the XML as.
-
getEncoding
public java.lang.String getEncoding()
Get the current encoding that will be used to write the XML.- Returns:
- The current encoding to write the XML to.
-
load
public static XMPMetadata load(java.lang.String file) throws java.io.IOException
Load metadata from the filesystem.- Parameters:
file- The file to load the metadata from.- Returns:
- The loaded XMP document.
- Throws:
java.io.IOException- If there is an error reading the data.
-
load
public static XMPMetadata load(org.xml.sax.InputSource is) throws java.io.IOException
Load a schema from an input source.- Parameters:
is- The input source to load the schema from.- Returns:
- The loaded/parsed schema.
- Throws:
java.io.IOException- If there was an error while loading the schema.
-
load
public static XMPMetadata load(java.io.InputStream is) throws java.io.IOException
Load metadata from the filesystem.- Parameters:
is- The stream to load the data from.- Returns:
- The loaded XMP document.
- Throws:
java.io.IOException- If there is an error reading the data.
-
main
public static void main(java.lang.String[] args) throws java.lang.ExceptionTest main program.- Parameters:
args- The command line arguments.- Throws:
java.lang.Exception- If there is an error.
-
getSchemas
public java.util.List<XMPSchema> getSchemas() throws java.io.IOException
This will get a list of XMPSchema(or subclass) objects.- Returns:
- A non null read-only list of schemas that are part of this metadata.
- Throws:
java.io.IOException- If there is an error creating a specific schema.
-
getSchemasByNamespaceURI
public java.util.List<XMPSchema> getSchemasByNamespaceURI(java.lang.String namespaceURI) throws java.io.IOException
Will return all schemas that fit the given namespaceURI. Which is only done by using the namespace mapping (nsMapping) and not by actually checking the xmlns property.- Parameters:
namespaceURI- The namespaceURI to filter for.- Returns:
- A list containing the found schemas or an empty list if non are found or the namespaceURI could not be found in the namespace mapping.
- Throws:
java.io.IOException- If an operation on the document fails.
-
hasUnknownSchema
public boolean hasUnknownSchema() throws java.io.IOExceptionThis will return true if the XMP contains an unknown schema.- Returns:
- True if an unknown schema is found, false otherwise
- Throws:
java.io.IOException- If there is an error
-
getSchemaByClass
public XMPSchema getSchemaByClass(java.lang.Class<?> targetSchema) throws java.io.IOException
Tries to retrieve a schema from this by classname.- Parameters:
targetSchema- Class for targetSchema.- Returns:
- XMPSchema or null if no target is found.
- Throws:
java.io.IOException- if there was an error creating the schemas of this.
-
merge
public void merge(XMPMetadata metadata) throws java.io.IOException
Merge this metadata with the given metadata object.- Parameters:
metadata- The metadata to merge with this document.- Throws:
java.io.IOException- If there is an error merging the data.
-
-