org.jempbox.xmp
Class XMPMetadata

java.lang.Object
  extended byorg.jempbox.xmp.XMPMetadata

public class XMPMetadata
extends Object

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.1 $
Author:
Ben Litchfield (ben@benlitchfield.com)

Field Summary
static String ENCODING_UTF16BE
          Supported encoding for persisted XML.
static String ENCODING_UTF16LE
          Supported encoding for persisted XML.
static String ENCODING_UTF8
          Supported encoding for persisted XML.
protected  Document xmpDocument
          The DOM representation of the metadata.
 
Constructor Summary
XMPMetadata()
          Default constructor, creates blank XMP doc.
XMPMetadata(Document doc)
          Constructor from an existing XML document.
 
Method Summary
 XMPSchemaBasic addBasicSchema()
          Create and add a new Basic Schema to this metadata.
 XMPSchemaDublinCore addDublinCoreSchema()
          Create and add a new Dublin Core Schema to this metadata.
 XMPSchemaPDF addPDFSchema()
          Create and add a new PDF Schema to this metadata.
 String getEncoding()
          Get the current encoding that will be used to write the XML.
 List getSchemas()
          This will get a list of XMPSchema(or subclass) objects.
 Document getXMPDocument()
          Get the XML document from this object.
static XMPMetadata load(InputStream is)
          Load metadata from the filesystem.
static XMPMetadata load(String file)
          Load metadata from the filesystem.
static void main(String[] args)
          Test main program.
 void save(String file)
          Save the XMP document to a file.
 void setEncoding(String xmlEncoding)
          The encoding used to write the XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODING_UTF8

public static final String ENCODING_UTF8
Supported encoding for persisted XML.

See Also:
Constant Field Values

ENCODING_UTF16BE

public static final String ENCODING_UTF16BE
Supported encoding for persisted XML.

See Also:
Constant Field Values

ENCODING_UTF16LE

public static final String ENCODING_UTF16LE
Supported encoding for persisted XML.

See Also:
Constant Field Values

xmpDocument

protected Document xmpDocument
The DOM representation of the metadata.

Constructor Detail

XMPMetadata

public XMPMetadata()
            throws IOException
Default constructor, creates blank XMP doc.

Throws:
IOException - If there is an error creating the initial document.

XMPMetadata

public XMPMetadata(Document doc)
Constructor from an existing XML document.

Parameters:
doc - The root XMP document.
Method Detail

save

public void save(String file)
          throws Exception
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.

getXMPDocument

public Document getXMPDocument()
Get the XML document from this object.

Returns:
This object as an XML document.

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.

setEncoding

public void setEncoding(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 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(String file)
                        throws IOException
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

public static XMPMetadata load(InputStream is)
                        throws IOException
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

public static void main(String[] args)
                 throws Exception
Test main program.

Parameters:
args - The command line arguments.
Throws:
Exception - If there is an error.

getSchemas

public List getSchemas()
                throws 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:
IOException - If there is an error creating a specific schema.