|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.odftoolkit.odfdom.pkg.OdfPackage
public class OdfPackage
OdfPackage represents the package view to an OpenDocument document. The OdfPackage will be created from an ODF document and represents a copy of the loaded document, where files can be inserted and deleted. The changes take effect, when the OdfPackage is being made persisted by save().
Nested Class Summary | |
---|---|
static class |
OdfPackage.OdfFile
|
Method Summary | |
---|---|
void |
close()
Close the OdfPackage after it is no longer needed. |
boolean |
contains(String internalPath)
Check existence of a file in the package. |
String |
getBaseURI()
|
byte[] |
getBytes(String internalPath)
Get package (sub-) content as byte array |
OdfPackageDocument |
getCachedDocument(String internalPath)
Deprecated. This method is only added temporary as workaround for the IBM fork using different DOC classes. Until the registering of DOC documents to the PKG layer has been finished. |
Set<String> |
getDocumentPaths()
Method returns the paths of all document within the package. |
Set<String> |
getDocumentPaths(String mediaTypeString)
Method returns the paths of all document within the package matching the given criteria. |
Document |
getDom(String internalPath)
Gets org.w3c.dom.Document for XML file contained in package. |
EntityResolver |
getEntityResolver()
Get EntityResolver to be used in XML Parsers which can resolve content inside the OdfPackage |
ErrorHandler |
getErrorHandler()
Return the current error handler used for ODF validation. |
OdfFileEntry |
getFileEntry(String internalPath)
Get an OdfFileEntry for the internalPath NOTE: This method should be better moved to a DOM inherited Manifest class |
Set<String> |
getFilePaths()
Get a OdfFileEntries from the manifest file (i.e. |
InputStream |
getInputStream()
Gets the InputStream containing whole OdfPackage. |
InputStream |
getInputStream(String internalPath)
Get the latest version of package content as InputStream, as it would be saved. |
InputStream |
getInputStream(String internalPath,
boolean useOriginal)
Get the latest version of package content as InputStream, as it would be saved. |
String |
getManifestAsString()
Get Manifest as String NOTE: This functionality should better be moved to a DOM based Manifest class |
String |
getMediaTypeString()
Get the media type of the ODF package (equal to media type of ODF root document) |
String |
getMediaTypeString(String internalPath)
Get the media type of the ODF file or document (ie. |
OdfPackageDocument |
getRootDocument()
|
URIResolver |
getURIResolver()
Get URIResolver to be used in XSL Transformations which can resolve content inside the OdfPackage |
void |
insert(byte[] fileBytes,
String internalPath,
String mediaTypeString)
Inserts a byte array into OdfPackage. |
void |
insert(Document fileDOM,
String internalPath,
String mediaType)
Insert DOM tree into OdfPackage. |
void |
insert(InputStream fileStream,
String internalPath,
String mediaType)
Inserts InputStream into an OdfPackage. |
void |
insert(URI sourceURI,
String internalPath,
String mediaType)
Inserts an external file into an OdfPackage. |
void |
insertDocument(OdfPackageDocument sourceDocument,
String internalPath)
Embed an OdfPackageDocument to the current OdfPackage. |
OutputStream |
insertOutputStream(String internalPath)
Insert the OutputStream for into OdfPackage. |
OutputStream |
insertOutputStream(String internalPath,
String mediaType)
Insert the OutputStream - to be filled after method - when stream is closed into OdfPackage. |
static boolean |
isExternalReference(String internalPath)
Checks if the given reference is a reference, which points outside the ODF package |
OdfPackageDocument |
loadDocument(String internalPath)
Returns on ODF documents based a given mediatype. |
static OdfPackage |
loadPackage(File pkgFile)
Loads an OdfPackage from the OpenDocument provided by a File. |
static OdfPackage |
loadPackage(File pkgFile,
ErrorHandler errorHandler)
Loads an OdfPackage from the given File. |
static OdfPackage |
loadPackage(InputStream packageStream)
Creates an OdfPackage from the given InputStream. |
static OdfPackage |
loadPackage(InputStream packageStream,
String baseURI,
ErrorHandler errorHandler)
Creates an OdfPackage from the given InputStream. |
static OdfPackage |
loadPackage(String path)
Loads an OdfPackage from the given documentURL. |
void |
remove(String internalPath)
Removes a singel file from the package. |
void |
removeDocument(String internalPath)
Removes a document from the package via its path. |
void |
save(File pkgFile)
Save package to a given File. |
void |
save(OutputStream odfStream)
|
void |
save(String odfPath)
Save the package to given documentURL. |
void |
setErrorHandler(ErrorHandler handler)
Allow an application to register an error event handler. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static OdfPackage loadPackage(String path) throws Exception
OdfPackage relies on the file being available for read access over the whole lifecycle of OdfPackage.
path
- - the documentURL to the ODF package
Exception
- - if the package could not be loadedpublic static OdfPackage loadPackage(File pkgFile) throws Exception
OdfPackage relies on the file being available for read access over the whole lifecycle of OdfPackage.
pkgFile
- - the ODF Package
Exception
- - if the package could not be loadedpublic static OdfPackage loadPackage(InputStream packageStream) throws Exception
Since an InputStream does not provide the arbitrary (non sequentiell) read access needed by OdfPackage, the InputStream is cached. This usually takes more time compared to the other loadPackage methods.
packageStream
- - an inputStream representing the ODF package
Exception
- - if the package could not be loadedpublic static OdfPackage loadPackage(InputStream packageStream, String baseURI, ErrorHandler errorHandler) throws Exception
OdfPackage relies on the file being available for read access over the whole lifecycle of OdfPackage.
packageStream
- - an inputStream representing the ODF packagebaseURI
- allows to explicitly set the base URI from the document, As the URL can not be derived from a stream.
In addition it is possible to set the baseURI to any arbitrary URI, e.g. an URN.
One usage of the baseURI to describe the source of validation exception thrown by the ErrorHandler.errorHandler
- - SAX ErrorHandler used for ODF validation
Exception
- - if the package could not be createdgetErrorHandler()
public static OdfPackage loadPackage(File pkgFile, ErrorHandler errorHandler) throws Exception
OdfPackage relies on the file being available for read access over the whole lifecycle of OdfPackage.
pkgFile
- - the ODF Package. A baseURL is being generated based on its location.errorHandler
- - SAX ErrorHandler used for ODF validation.
Exception
- - if the package could not be createdgetErrorHandler()
public String getBaseURI()
public OdfPackageDocument loadDocument(String internalPath)
internalPath
- path relative to the package root, where the document should be inserted.
@Deprecated public OdfPackageDocument getCachedDocument(String internalPath)
internalPath
- path relative to the package root, where the document should be inserted.
public void removeDocument(String internalPath)
internalPath
- path relative to the package root, where the document should be removed.public OdfPackageDocument getRootDocument()
public String getMediaTypeString(String internalPath)
OdfPackageDocument
.
Note: A directoy is represented by in the package as directory with media type
internalPath
- within the package of the file or document.
public String getMediaTypeString()
public OdfFileEntry getFileEntry(String internalPath)
internalPath
- The relative package path within the ODF package
public Set<String> getFilePaths()
public boolean contains(String internalPath)
internalPath
- The relative package documentURL within the ODF package
public void save(String odfPath) throws Exception
odfPath
- - the path to the ODF package destination
Exception
- - if the package could not be savedpublic void save(File pkgFile) throws Exception
pkgFile
- - the File to save the ODF package to
Exception
- - if the package could not be savedpublic void save(OutputStream odfStream) throws Exception
Exception
public void close()
close
in interface Closeable
public void insert(Document fileDOM, String internalPath, String mediaType)
fileDOM
- - XML DOM tree to be inserted as file.internalPath
- - relative documentURL where the DOM tree should be inserted as XML filemediaType
- - media type of stream. Set to null if unknown
Exception
- when the DOM tree could not be insertedpublic void insertDocument(OdfPackageDocument sourceDocument, String internalPath)
sourceDocument
- the OdfPackageDocument to be embedded.internalPath
- path to the directory the ODF document should be inserted (relative to ODF package root).public Set<String> getDocumentPaths()
public Set<String> getDocumentPaths(String mediaTypeString)
mediaTypeString
- limits the desired set of document paths to documents of the given mediaType
public Document getDom(String internalPath) throws SAXException, ParserConfigurationException, IllegalArgumentException, TransformerConfigurationException, TransformerException, IOException
internalPath
- to a file within the Odf Package (eg. content.xml)
SAXException
ParserConfigurationException
IOException
IllegalArgumentException
TransformerConfigurationException
TransformerException
public void insert(URI sourceURI, String internalPath, String mediaType) throws Exception
sourceURI
- - the source URI to the file to be inserted into the package.internalPath
- - relative documentURL where the tree should be inserted as XML
filemediaType
- - media type of stream. Set to null if unknown
Exception
- In case the file could not be savedpublic void insert(InputStream fileStream, String internalPath, String mediaType) throws Exception
fileStream
- - the stream of the file to be inserted into the ODF package.internalPath
- - relative documentURL where the tree should be inserted as XML
filemediaType
- - media type of stream. Set to null if unknown
Exception
public void insert(byte[] fileBytes, String internalPath, String mediaTypeString)
fileBytes
- - data of the file stream to be stored in package.
If NULL a directory with the given mimetype will be created.internalPath
- - path of the file or directory relative to the package root.mediaTypeString
- - media type of stream. If unknown null can be used.public String getManifestAsString()
public byte[] getBytes(String internalPath)
internalPath
- relative documentURL to the package content
Exception
public InputStream getInputStream(String internalPath)
internalPath
- of the desired stream.
public InputStream getInputStream(String internalPath, boolean useOriginal)
internalPath
- of the desired stream.useOriginal
- true uses the stream as loaded from the ZIP.
False will return even modified file content as a stream.
public InputStream getInputStream() throws Exception
Exception
- - if the package could not be readpublic OutputStream insertOutputStream(String internalPath) throws Exception
internalPath
- - relative documentURL where the DOM tree should be inserted as
XML file
Exception
- when the DOM tree could not be insertedpublic OutputStream insertOutputStream(String internalPath, String mediaType) throws Exception
internalPath
- - relative documentURL where the DOM tree should be inserted as
XML filemediaType
- - media type of stream
Exception
- when the DOM tree could not be insertedpublic void remove(String internalPath)
internalPath
- of the file relative to the package rootpublic EntityResolver getEntityResolver()
public URIResolver getURIResolver()
public static boolean isExternalReference(String internalPath)
internalPath
- the file reference to be checked
public void setErrorHandler(ErrorHandler handler)
If the application does not register an error handler, all error events reported by the ODFDOM (e.g. the SAX Parser) will be silently ignored; however, normal processing may not continue. It is highly recommended that all ODF applications implement an error handler to avoid unexpected bugs.
Applications may register a new or different handler in the middle of a parse, and the ODFDOM will begin using the new handler immediately.
handler
- The error handler.getErrorHandler()
public ErrorHandler getErrorHandler()
setErrorHandler(org.xml.sax.ErrorHandler)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |