Package org.apache.jempbox.xmp
Class XMPMetadata
java.lang.Object
org.apache.jempbox.xmp.XMPMetadata
- Direct Known Subclasses:
XMPMetadataPDFA
This 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
FieldsModifier and TypeFieldDescriptionprotected String
The encoding of the XMP document.static final String
Supported encoding for persisted XML.static final String
Supported encoding for persisted XML.static final String
Supported encoding for persisted XML.A mapping of namespaces.protected Document
The DOM representation of the metadata. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, creates blank XMP doc.XMPMetadata
(Document doc) Constructor from an existing XML document. -
Method Summary
Modifier and TypeMethodDescriptionAdd a new Job Ticket schema.Create and add a new Basic Schema to this metadata.Create and add a new Dublin Core Schema to this metadata.Add a new Dynamic Media schema.Create and add a new IPTC schema to this metadata.Add a new Media Management schema.Add a new Paged Text schema.Create and add a new PDF Schema to this metadata.Create and add a new Photoshop schema to this metadata.Add a new Rights Managment schema.void
Add a custom schema to the root rdf.void
addXMLNSMapping
(String namespace, Class<?> xmpSchema) Will add a XMPSchema to the set of identified schemas.byte[]
Get the XML document as a byte array.protected XMPSchema
basicAddSchema
(XMPSchema schema) Generic add schema method.Get the Job Ticket Schema.Get the Basic Schema.Get the Dublin Core Schema.Get the Dynamic Media Schema.Get the current encoding that will be used to write the XML.Get the Media Management Schema.Get the Paged Text Schema.Get the PDF Schema.Get the Schema Rights Schema.getSchemaByClass
(Class<?> targetSchema) Tries to retrieve a schema from this by classname.This will get a list of XMPSchema(or subclass) objects.getSchemasByNamespaceURI
(String namespaceURI) Will return all schemas that fit the given namespaceURI.Get the XML document from this object.boolean
This will return true if the XMP contains an unknown schema.static XMPMetadata
load
(InputStream is) Load metadata from the filesystem.static XMPMetadata
Load metadata from the filesystem.static XMPMetadata
load
(InputSource is) Load a schema from an input source.static void
Test main program.void
merge
(XMPMetadata metadata) Merge this metadata with the given metadata object.void
save
(OutputStream outStream) Save the XMP document to a stream.void
Save the XMP document to a file.void
setEncoding
(String xmlEncoding) The encoding used to write the XML.
-
Field Details
-
ENCODING_UTF8
Supported encoding for persisted XML.- See Also:
-
ENCODING_UTF16BE
Supported encoding for persisted XML.- See Also:
-
ENCODING_UTF16LE
Supported encoding for persisted XML.- See Also:
-
xmpDocument
The DOM representation of the metadata. -
encoding
The encoding of the XMP document. Default is UTF8. -
nsMappings
A mapping of namespaces.
-
-
Constructor Details
-
XMPMetadata
Default constructor, creates blank XMP doc.- Throws:
IOException
- If there is an error creating the initial document.
-
XMPMetadata
Constructor from an existing XML document.- Parameters:
doc
- The root XMP document.
-
-
Method Details
-
addXMLNSMapping
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
Get the PDF Schema.- Returns:
- The first PDF schema in the list.
- Throws:
IOException
- If there is an error accessing the schema.
-
getBasicSchema
Get the Basic Schema.- Returns:
- The first Basic schema in the list.
- Throws:
IOException
- If there is an error accessing the schema.
-
getDublinCoreSchema
Get the Dublin Core Schema.- Returns:
- The first Dublin schema in the list.
- Throws:
IOException
- If there is an error accessing the schema.
-
getMediaManagementSchema
Get the Media Management Schema.- Returns:
- The first Media Management schema in the list.
- Throws:
IOException
- If there is an error accessing the schema.
-
getRightsManagementSchema
Get the Schema Rights Schema.- Returns:
- The first Schema Rights schema in the list.
- Throws:
IOException
- If there is an error accessing the schema.
-
getBasicJobTicketSchema
Get the Job Ticket Schema.- Returns:
- The first Job Ticket schema in the list.
- Throws:
IOException
- If there is an error accessing the schema.
-
getDynamicMediaSchema
Get the Dynamic Media Schema.- Returns:
- The first Dynamic Media schema in the list.
- Throws:
IOException
- If there is an error accessing the schema.
-
getPagedTextSchema
Get the Paged Text Schema.- Returns:
- The first Paged Text schema in the list.
- Throws:
IOException
- If there is an error accessing the schema.
-
addMediaManagementSchema
Add a new Media Management schema.- Returns:
- The newly added schema.
-
addRightsManagementSchema
Add a new Rights Managment schema.- Returns:
- The newly added schema.
-
addBasicJobTicketSchema
Add a new Job Ticket schema.- Returns:
- The newly added schema.
-
addDynamicMediaSchema
Add a new Dynamic Media schema.- Returns:
- The newly added schema.
-
addPagedTextSchema
Add a new Paged Text schema.- Returns:
- The newly added schema.
-
addSchema
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
Save the XMP document to a file.- Parameters:
file
- The file to save the XMP document to.- Throws:
Exception
- If there is an error while writing to the stream.
-
save
Save the XMP document to a stream.- Parameters:
outStream
- The stream to save the XMP document to.- Throws:
TransformerException
- If there is an error while writing to the stream.
-
asByteArray
Get the XML document as a byte array.- Returns:
- The metadata as an XML byte stream.
- Throws:
Exception
- If there is an error creating the stream.
-
getXMPDocument
Get the XML document from this object.- Returns:
- This object as an XML document.
-
basicAddSchema
Generic add schema method.- Parameters:
schema
- The schema to add.- Returns:
- The newly added schema.
-
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
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
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
Create and add a new IPTC schema to this metadata.- Returns:
- A new blank IPTC schema that is now part of the metadata.
-
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
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
Get the current encoding that will be used to write the XML.- Returns:
- The current encoding to write the XML to.
-
load
Load metadata from the filesystem.- Parameters:
file
- The file to load the metadata from.- Returns:
- The loaded XMP document.
- Throws:
IOException
- If there is an error reading the data.
-
load
Load a schema from an input source.- Parameters:
is
- The input source to load the schema from.- Returns:
- The loaded/parsed schema.
- Throws:
IOException
- If there was an error while loading the schema.
-
load
Load metadata from the filesystem.- Parameters:
is
- The stream to load the data from.- Returns:
- The loaded XMP document.
- Throws:
IOException
- If there is an error reading the data.
-
main
Test main program.- Parameters:
args
- The command line arguments.- Throws:
Exception
- If there is an error.
-
getSchemas
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:
IOException
- If there is an error creating a specific schema.
-
getSchemasByNamespaceURI
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:
IOException
- If an operation on the document fails.
-
hasUnknownSchema
This will return true if the XMP contains an unknown schema.- Returns:
- True if an unknown schema is found, false otherwise
- Throws:
IOException
- If there is an error
-
getSchemaByClass
Tries to retrieve a schema from this by classname.- Parameters:
targetSchema
- Class for targetSchema.- Returns:
- XMPSchema or null if no target is found.
- Throws:
IOException
- if there was an error creating the schemas of this.
-
merge
Merge this metadata with the given metadata object.- Parameters:
metadata
- The metadata to merge with this document.- Throws:
IOException
- If there is an error merging the data.
-