org.odftoolkit.odfdom.doc
Class OdfDocument

java.lang.Object
  extended by org.odftoolkit.odfdom.doc.OdfDocument
Direct Known Subclasses:
OdfChartDocument, OdfGraphicsDocument, OdfPresentationDocument, OdfSpreadsheetDocument, OdfTextDocument

public abstract class OdfDocument
extends Object


Nested Class Summary
static class OdfDocument.OdfMediaType
          This enum contains all possible media types of OpenDocument documents.
static class OdfDocument.OdfXMLFile
          This enum contains all possible standardized XML ODF files of the OpenDocument document.
protected static class OdfDocument.Resource
           
 
Constructor Summary
OdfDocument()
           
 
Method Summary
 void embedDocument(String pkgPathToChildDocument, OdfDocument newOdfDocument)
          Add an OdfDocument as an embedded OdfDocument to the current OdfDocument
 String getBaseURI()
          Get the URI, where this ODF document is stored.
 OdfFileDom getContentDom()
          Return the ODF type-based content DOM of the current OdfDocument
 InputStream getContentStream()
          Gets the ODF content.xml file as stream.
 String getDocumentPackagePath()
          Get the relative path for an embedded ODF document.
 OdfStyles getDocumentStyles()
           
 OdfDocument getEmbeddedDocument(String pathToObject)
          Returns an embedded OdfDocument of the current OdfDocument matching to the internal package path given as an parameter.
 List<OdfDocument> getEmbeddedDocuments()
          Method returns all embedded OdfDocuments, which match a valid OdfMediaType, of the current OdfDocument.
 List<OdfDocument> getEmbeddedDocuments(OdfDocument.OdfMediaType mediaType)
          Method returns all embedded OdfDocuments of the current OdfDocument matching the according MediaType.
 String getMediaType()
          Get the media type from document
 InputStream getMetaStream()
          Gets the ODF metadata.xml file as stream.
 OdfBody getOfficeBody()
           
 OdfMasterStyles getOfficeMasterStyles()
          return the office:master-styles element of this document.
 OdfStyles getOrCreateDocumentStyles()
           
 OdfPackage getPackage()
          Retreives the OdfPackage for this OdfDocument.
protected  OdfDocument getRootDocument()
          Retreives the root OdfDocument that determines the mediatype of the package.
 InputStream getSettingsStream()
          Gets the ODF settings.xml file as stream.
 OdfFileDom getStylesDom()
          Return the ODF type-based content DOM of the current OdfDocument
 InputStream getStylesStream()
          Gets the ODF style.xml file as stream.
protected  String getXMLFilePath(OdfDocument.OdfXMLFile file)
          Get the relative path for an embedded ODF document including its file name.
 XPath getXPath()
          Create an XPath instance to select one or more nodes from an ODF document.
static OdfDocument loadDocument(File file)
          Creates an OdfDocument from the OpenDocument provided by a File.
static OdfDocument loadDocument(InputStream inStream)
          Creates an OdfDocument from the OpenDocument provided by a resource Stream.
static OdfDocument loadDocument(OdfPackage odfPackage)
          Creates an OdfDocument from the OpenDocument provided by an ODF package.
static OdfDocument loadDocument(String path)
          Loads an OdfDocument from the provided path.
protected static OdfDocument loadTemplate(OdfDocument.Resource res)
          Loads an OpenDocument from the given resource
 void save(File file)
          Save the document to given file.
 void save(OutputStream out)
          Save the document to an OutputStream.
 void save(String path)
          Save the document to given path.Delegate to the root document and save possible embedded OdfDocuments.
protected  void setMediaType(OdfDocument.OdfMediaType odfMediaType)
          Sets the media type of the OdfDocument
protected  void setPackage(OdfPackage pkg)
          Sets the OdfPackage that contains this OdfDocument.
protected  void setRootDocument(OdfDocument root)
          Sets the root OdfDocument that determines the mediatype of the package.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OdfDocument

public OdfDocument()
Method Detail

loadTemplate

protected static OdfDocument loadTemplate(OdfDocument.Resource res)
                                   throws Exception
Loads an OpenDocument from the given resource

Parameters:
res - a resource containing the document
useTempFile - a flag to indicate whether or not to use temporary files
Returns:
the OpenDocument document
Throws:
Exception - - if the document could not be created.

loadDocument

public static OdfDocument loadDocument(String path)
                                throws Exception
Loads an OdfDocument from the provided path.

Parameters:
path - - the path from where the document can be loaded
Returns:
the OpenDocument from the given path
Throws:
Exception - - if the document could not be created.

loadDocument

public static OdfDocument loadDocument(InputStream inStream)
                                throws Exception
Creates an OdfDocument from the OpenDocument provided by a resource Stream.

Parameters:
inStream - - the InputStream of the ODF document.
Returns:
the document created from the given InputStream
Throws:
Exception - - if the document could not be created.

loadDocument

public static OdfDocument loadDocument(File file)
                                throws Exception
Creates an OdfDocument from the OpenDocument provided by a File.

Parameters:
file - - a file representing the ODF document.
Returns:
the document created from the given File
Throws:
Exception - - if the document could not be created.

loadDocument

public static OdfDocument loadDocument(OdfPackage odfPackage)
                                throws Exception
Creates an OdfDocument from the OpenDocument provided by an ODF package.

Parameters:
odfPackage - - the ODF package containing the ODF document.
Returns:
the root document of the given OdfPackage
Throws:
Exception - - if the ODF document could not be created.

setRootDocument

protected void setRootDocument(OdfDocument root)
Sets the root OdfDocument that determines the mediatype of the package.

Parameters:
root - the OdfDocument that has its file on the root level of the package

getRootDocument

protected OdfDocument getRootDocument()
Retreives the root OdfDocument that determines the mediatype of the package.

Returns:
the OdfDocument that has its file on the root level of the package

setPackage

protected void setPackage(OdfPackage pkg)
Sets the OdfPackage that contains this OdfDocument.

Parameters:
pkg - the OdfPackage that contains this OdfDocument

getPackage

public OdfPackage getPackage()
Retreives the OdfPackage for this OdfDocument.

Returns:
the OdfPackage that contains this OdfDocument.

setMediaType

protected void setMediaType(OdfDocument.OdfMediaType odfMediaType)
Sets the media type of the OdfDocument

Parameters:
odfMediaType - media type to be set

getDocumentPackagePath

public String getDocumentPackagePath()
Get the relative path for an embedded ODF document.

Returns:
path to the directory of the embedded ODF document (relative to ODF package root).

getXMLFilePath

protected String getXMLFilePath(OdfDocument.OdfXMLFile file)
Get the relative path for an embedded ODF document including its file name.

Parameters:
file - represents one of the standardized XML ODF files.
Returns:
path to embedded ODF XML file relative to ODF package root.

embedDocument

public void embedDocument(String pkgPathToChildDocument,
                          OdfDocument newOdfDocument)
Add an OdfDocument as an embedded OdfDocument to the current OdfDocument

Parameters:
pkgPathToChildDocument - path to the directory of the embedded ODF document (always relative to ODF package root).
newOdfDocument - the OdfDocument to be embedded

getContentStream

public InputStream getContentStream()
                             throws Exception
Gets the ODF content.xml file as stream.

Returns:
- a stream of the ODF content 'content.xml' file
Throws:
Exception - - if the stream can not be extracted

getStylesStream

public InputStream getStylesStream()
                            throws Exception
Gets the ODF style.xml file as stream.

Returns:
- a stream of the ODF style 'styles.xml' file
Throws:
Exception - - if the stream can not be extracted

getSettingsStream

public InputStream getSettingsStream()
                              throws Exception
Gets the ODF settings.xml file as stream.

Returns:
- a stream of the ODF metadata 'setting.xml' file
Throws:
Exception - - if the stream can not be extracted

getMetaStream

public InputStream getMetaStream()
                          throws Exception
Gets the ODF metadata.xml file as stream.

Returns:
- a stream of the ODF metadata 'meta.xml' file
Throws:
Exception - - if the stream can not be extracted

getBaseURI

public String getBaseURI()
Get the URI, where this ODF document is stored.

Returns:
the URI to the ODF document. Returns null if document is not stored yet.

getEmbeddedDocument

public OdfDocument getEmbeddedDocument(String pathToObject)
Returns an embedded OdfDocument of the current OdfDocument matching to the internal package path given as an parameter. Once loaded embedded OdfDocuments are cached for later use.

Parameters:
pathToObject - path to the directory of the embedded ODF document (relative to ODF package root).
Returns:
an embedded OdfDocument

getEmbeddedDocuments

public List<OdfDocument> getEmbeddedDocuments(OdfDocument.OdfMediaType mediaType)
Method returns all embedded OdfDocuments of the current OdfDocument matching the according MediaType. This is done by matching the subfolder entries of the manifest file with the given OdfMediaType.

Parameters:
mediaType - media type which is used as a filter
Returns:
embedded documents of the current OdfDocument matching the given media type

getEmbeddedDocuments

public List<OdfDocument> getEmbeddedDocuments()
Method returns all embedded OdfDocuments, which match a valid OdfMediaType, of the current OdfDocument.

Returns:
a list with all embedded documents of the current odfDocument

getDocumentStyles

public OdfStyles getDocumentStyles()
Returns:
the office:styles element from the styles dom or null if there is no such element.

getOrCreateDocumentStyles

public OdfStyles getOrCreateDocumentStyles()
Returns:
the office:styles element from the styles dom. If there is not yet such an element, it is created.

getXPath

public XPath getXPath()
Create an XPath instance to select one or more nodes from an ODF document. Therefore the namespace context is set to the OdfNamespace

Returns:
an XPath instance with namespace context set to include the standard ODFDOM prefixes.

getContentDom

public OdfFileDom getContentDom()
                         throws Exception
Return the ODF type-based content DOM of the current OdfDocument

Returns:
ODF type-based content DOM
Throws:
Exception - if content DOM could not be initialized

getStylesDom

public OdfFileDom getStylesDom()
                        throws Exception
Return the ODF type-based content DOM of the current OdfDocument

Returns:
ODF type-based styles DOM
Throws:
Exception - if styles DOM could not be initialized

getMediaType

public String getMediaType()
Get the media type from document

Returns:
the mMediaType string of this package

save

public void save(String path)
          throws Exception
Save the document to given path.Delegate to the root document and save possible embedded OdfDocuments.

Parameters:
path - - the path to the file
Throws:
Exception - if the document could not be saved

save

public void save(File file)
          throws Exception
Save the document to given file. Delegate to the root document and save possible embedded OdfDocuments.

Parameters:
file - - the file to save the document
Throws:
Exception - if the document could not be saved

save

public void save(OutputStream out)
          throws Exception
Save the document to an OutputStream. Delegate to the root document and save possible embedded OdfDocuments.

Parameters:
out - - the OutputStream to write the file to
Throws:
Exception - if the document could not be saved

getOfficeBody

public OdfBody getOfficeBody()
Returns:
the office:body element of this document

getOfficeMasterStyles

public OdfMasterStyles getOfficeMasterStyles()
return the office:master-styles element of this document.

Returns:
the office:master-styles element

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009. All Rights Reserved.