public class OdfPackage extends Object
Modifier and Type | Class and Description |
---|---|
static class |
OdfPackage.OdfFile |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the OdfPackage after it is no longer needed.
|
boolean |
contains(String packagePath)
Check existence of a file in the package.
|
static OdfPackage |
create() |
String |
getBaseURI()
Get the URI, where this ODF package is stored.
|
byte[] |
getBytes(String packagePath)
Get package (sub-) content as byte array
|
Document |
getDom(String packagePath)
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
|
Set<String> |
getFileEntries()
Get a OdfFileEntries from the manifest file (i.e.
|
OdfFileEntry |
getFileEntry(String packagePath)
Get an OdfFileEntry for the packagePath NOTE: This method should be
better moved to a DOM inherited Manifest class
|
InputStream |
getInputStream()
Gets the InputStream containing whole OdfPackage.
|
InputStream |
getInputStream(String packagePath)
Get subcontent as InputStream
|
String |
getManifestAsString()
Get Manifest as String NOTE: This functionality should better be moved to
a DOM based Manifest class
|
HashMap<String,OdfFileEntry> |
getManifestEntries() |
String |
getMediaType()
Get the media type of the ODF package (equal to media type of ODF root
document)
|
URIResolver |
getURIResolver()
Get URIResolver to be used in XSL Transformations which can resolve
content inside the OdfPackage
|
boolean |
hasDom(String packagePath)
returns true if a DOM tree has been requested for given sub-content of
OdfPackage
|
void |
insert(byte[] fileBytes,
String packagePath,
String mediaType)
Insert byte array into OdfPackage.
|
void |
insert(Document fileDOM,
String packagePath,
String mediaType)
Insert DOM tree into OdfPackage.
|
void |
insert(InputStream fileStream,
String packagePath,
String mediaType)
Inserts InputStream into an OdfPackage.
|
void |
insert(URI sourceURI,
String packagePath,
String mediaType)
Inserts InputStream into an OdfPackage.
|
OutputStream |
insertOutputStream(String packagePath)
Insert the OutputStream for into OdfPackage.
|
OutputStream |
insertOutputStream(String packagePath,
String mediaType)
Insert the OutputStream - to be filled after method - when stream is
closed into OdfPackage.
|
static boolean |
isExternalReference(String fileRef)
Checks if the given reference is a reference, which points outside the
ODF package
|
static OdfPackage |
loadPackage(File odfFile)
Loads an OdfPackage from the OpenDocument provided by a File.
|
static OdfPackage |
loadPackage(InputStream odfStream)
Creates an OdfPackage from the OpenDocument provided by a InputStream.
|
static OdfPackage |
loadPackage(String odfPath)
Loads an OdfPackage from the given filePath.
|
void |
remove(String packagePath) |
void |
save(File odfFile)
Save package to a given File.
|
void |
save(OutputStream odfStream) |
void |
save(String odfPath)
Save the package to given filePath.
|
void |
setMediaType(String mediaType)
Set the media type of the ODF package (equal to media type of ODF root
document)
|
public static OdfPackage create() throws Exception
Exception
public static OdfPackage loadPackage(String odfPath) throws Exception
OdfPackage relies on the file being available for read access over the whole lifecycle of OdfPackage.
odfPath
- - the filePath to the ODF packageException
- - if the package could not be loadedpublic static OdfPackage loadPackage(File odfFile) throws Exception
OdfPackage relies on the file being available for read access over the whole lifecycle of OdfPackage.
odfFile
- - a File to loadPackage content fromException
- - if the package could not be loadedpublic static OdfPackage loadPackage(InputStream odfStream) 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.
odfStream
- - an inputStream representing the ODF packageException
- - if the package could not be loadedpublic String getBaseURI()
public String getMediaType()
public void setMediaType(String mediaType)
mediaType
- string of this ODF packagepublic OdfFileEntry getFileEntry(String packagePath)
packagePath
- The relative package path within the ODF packagepublic Set<String> getFileEntries()
public boolean contains(String packagePath)
packagePath
- The relative package filePath within the ODF packagepublic void save(String odfPath) throws Exception
odfPath
- - the path to the ODF package destinationException
- - if the package could not be savedpublic void save(File odfFile) throws Exception
odfFile
- - the File to save the ODF package toException
- - if the package could not be savedpublic void save(OutputStream odfStream) throws Exception
Exception
public void close()
public void insert(Document fileDOM, String packagePath, String mediaType) throws Exception
fileDOM
- - XML DOM tree to be inserted as filepackagePath
- - relative filePath where the DOM tree should be inserted as
XML filemediaType
- - media type of stream. Set to null if unknownException
- when the DOM tree could not be insertedpublic boolean hasDom(String packagePath)
packagePath
- - a path inside the OdfPackage eg to a content.xml streampublic Document getDom(String packagePath) throws SAXException, ParserConfigurationException, Exception, IllegalArgumentException, TransformerConfigurationException, TransformerException
packagePath
- - a path inside the OdfPackage eg to a content.xml streamSAXException
ParserConfigurationException
Exception
IllegalArgumentException
TransformerConfigurationException
TransformerException
public void insert(URI sourceURI, String packagePath, String mediaType) throws Exception
sourceURI
- - the source URI to the file to be inserted into the package.mediaType
- - media type of stream. Set to null if unknownpackagePath
- - relative filePath where the tree should be inserted as XML
fileException
- In case the file could not be savedpublic void insert(InputStream fileStream, String packagePath, String mediaType) throws Exception
fileStream
- - the stream of the file to be inserted into the ODF package.mediaType
- - media type of stream. Set to null if unknownpackagePath
- - relative filePath where the tree should be inserted as XML
fileException
- In case the file could not be savedpublic void insert(byte[] fileBytes, String packagePath, String mediaType) throws Exception
fileBytes
- - data of the file stream to be stored in packagemediaType
- - media type of stream. Set to null if unknownpackagePath
- - relative filePath where the DOM tree should be inserted as
XML fileException
- when the DOM tree could not be insertedpublic HashMap<String,OdfFileEntry> getManifestEntries()
public String getManifestAsString()
public byte[] getBytes(String packagePath) throws Exception
packagePath
- relative filePath to the package contentException
public InputStream getInputStream(String packagePath) throws Exception
packagePath
- of the desired stream.Exception
public InputStream getInputStream() throws Exception
Exception
- - if the package could not be readpublic OutputStream insertOutputStream(String packagePath) throws Exception
packagePath
- - relative filePath where the DOM tree should be inserted as
XML fileException
- when the DOM tree could not be insertedpublic OutputStream insertOutputStream(String packagePath, String mediaType) throws Exception
packagePath
- - relative filePath where the DOM tree should be inserted as
XML filemediaType
- - media type of streamException
- when the DOM tree could not be insertedpublic void remove(String packagePath)
public static boolean isExternalReference(String fileRef)
fileRef
- the file reference to be checkedpublic EntityResolver getEntityResolver()
public URIResolver getURIResolver()
Copyright © 2014 myGrid. All rights reserved.