Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.odftoolkit.odfdom.pkg
Class OdfPackage

    java.lang.Object
      org.odftoolkit.odfdom.pkg.OdfPackage

    public class OdfPackage

extends Object

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 persistend by save().

Nested Class Summary
`static class` | `OdfPackage.OdfFile`

Method Summary
`boolean` | `contains(String packagePath)` Check existence of a file in the package.
`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` | `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 fileDestPath)` Insert byte array into OdfPackage.
`void` | `insert(byte[] fileBytes, String fileDestPath, String mediaType)` Insert byte array into OdfPackage.
`void` | `insert(Document fileDOM, String packagePath)` Insert DOM tree into OdfPackage.
`void` | `insert(Document fileDOM, String packagePath, String mediaType)` Insert DOM tree into OdfPackage.
`void` | `insert(InputStream fileStream, String packagePath)` Inserts InputStream into an OdfPackage.
`void` | `insert(InputStream fileStream, String packagePath, String mediaType)` Inserts InputStream into an OdfPackage.
`void` | `insert(URI sourceURI, String packagePath)` 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, String baseURI)` Save an ODF document to the OutputStream.
`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)

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### loadPackage

    public static OdfPackage loadPackage(String odfPath)
                                  throws Exception

  Loads an OdfPackage from the given filePath.

  Parameters:
    `odfPath` - - the filePath to the ODF package
  Returns:
    the OpenDocument document represented as an OdfPackage
  Throws:
    `Exception` - - if the package could not be loaded

### loadPackage

    public static OdfPackage loadPackage(File odfFile)
                                  throws Exception

  Loads an OdfPackage from the OpenDocument provided by a File.

  Parameters:
    `odfFile` - - a File to loadPackage content from
  Returns:
    the OpenDocument document represented as an OdfPackage
  Throws:
    `Exception` - - if the package could not be loaded

### loadPackage

    public static OdfPackage loadPackage(InputStream odfStream)
                                  throws Exception

  Creates an OdfPackage from the OpenDocument provided by a InputStream.

  Parameters:
    `odfStream` - - an inputStream representing the ODF package
  Returns:
    the OpenDocument document represented as an OdfPackage
  Throws:
    `Exception` - - if the package could not be loaded

### getBaseURI

    public String getBaseURI()

  Get the URI, where this ODF package is stored.

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

### getMediaType

    public String getMediaType()

  Get the media type of the ODF package (equal to media type of ODF root document)

  Returns:
    the mediaType string of this ODF package

### setMediaType

    public void setMediaType(String mediaType)

  Set the media type of the ODF package (equal to media type of ODF root document)

  Parameters:
    `mediaType` - string of this ODF package

### getFileEntry

    public OdfFileEntry getFileEntry(String packagePath)

  Get an OdfFileEntry for the packagePath NOTE: This method should be better moved to a DOM inherited Manifest class

  Parameters:
    `packagePath` - The relative package path within the ODF package
  Returns:
    The manifest file entry will be returned.

### getFileEntries

    public Set<String> getFileEntries()

  Get a OdfFileEntries from the manifest file (i.e. /META/manifest.xml")

  Returns:
    The manifest file entries will be returned.

### contains

    public boolean contains(String packagePath)

  Check existence of a file in the package.

  Parameters:
    `packagePath` - The relative package filePath within the ODF package
  Returns:
    True if there is an entry and a file for the given filePath

### save

    public void save(String odfPath)
              throws Exception

  Save the package to given filePath.

  Parameters:
    `odfPath` - - the path to the ODF package destination
  Throws:
    `Exception` - - if the package could not be saved

### save

    public void save(File odfFile)
              throws Exception

  Save package to a given File.

  Parameters:
    `odfFile` - - the File to save the ODF package to
  Throws:
    `Exception` - - if the package could not be saved

### save

    public void save(OutputStream odfStream,
                     String baseURI)
              throws Exception

  Save an ODF document to the OutputStream.

  Parameters:
    `odfStream` - - the OutputStream to insert content to
    `baseURI` - - a URI for the package to be stored
  Throws:
    `Exception` - - if the package could not be saved

### insert

    public void insert(Document fileDOM,
                       String packagePath)
                throws Exception

  Insert DOM tree into OdfPackage. An existing file will be replaced.

  Parameters:
    `fileDOM` - - XML DOM tree to be inserted as file
    `packagePath` - - relative filePath where the DOM tree should be inserted as XML file
  Throws:
    `Exception` - when the DOM tree could not be inserted

### insert

    public void insert(Document fileDOM,
                       String packagePath,
                       String mediaType)
                throws Exception

  Insert DOM tree into OdfPackage. An existing file will be replaced.

  Parameters:
    `fileDOM` - - XML DOM tree to be inserted as file
    `packagePath` - - relative filePath where the DOM tree should be inserted as XML file
    `mediaType` - - media type of stream. Set to null if unknown
  Throws:
    `Exception` - when the DOM tree could not be inserted

### hasDom

    public boolean hasDom(String packagePath)

  returns true if a DOM tree has been requested for given sub-content of OdfPackage

  Parameters:
    `packagePath` - - a path inside the OdfPackage eg to a content.xml stream
  Returns:
    - wether the package class internally has a DOM representation for the given path

### getDom

    public Document getDom(String packagePath)
                    throws SAXException,
                           ParserConfigurationException,
                           Exception,
                           IllegalArgumentException,
                           TransformerConfigurationException,
                           TransformerException

  Gets org.w3c.dom.Document for XML file contained in package.

  Parameters:
    `packagePath` - - a path inside the OdfPackage eg to a content.xml stream
  Returns:
    an org.w3c.dom.Document
  Throws:
    `SAXException`
    `ParserConfigurationException`
    `Exception`
    `IllegalArgumentException`
    `TransformerConfigurationException`
    `TransformerException`

### insert

    public void insert(URI sourceURI,
                       String packagePath)
                throws Exception

  Inserts InputStream into an OdfPackage. An existing file will be replaced.

  Parameters:
    `sourceURI` - - the source URI to the file to be inserted into the package.
    `packagePath` - - relative filePath where the tree should be inserted as XML file
  Throws:
    `Exception` - In case the file could not be saved

### insert

    public void insert(URI sourceURI,
                       String packagePath,
                       String mediaType)
                throws Exception

  Inserts InputStream into an OdfPackage. An existing file will be replaced.

  Parameters:
    `sourceURI` - - the source URI to the file to be inserted into the package.
    `mediaType` - - media type of stream. Set to null if unknown
    `packagePath` - - relative filePath where the tree should be inserted as XML file
  Throws:
    `Exception` - In case the file could not be saved

### insert

    public void insert(InputStream fileStream,
                       String packagePath)
                throws Exception

  Inserts InputStream into an OdfPackage. An existing file will be replaced.

  Parameters:
    `fileStream` - - the stream of the file to be inserted into the ODF package.
    `packagePath` - - relative filePath where the tree should be inserted as XML file
  Throws:
    `Exception` - In case the file could not be saved

### insert

    public void insert(InputStream fileStream,
                       String packagePath,
                       String mediaType)
                throws Exception

  Inserts InputStream into an OdfPackage. An existing file will be replaced.

  Parameters:
    `fileStream` - - the stream of the file to be inserted into the ODF package.
    `mediaType` - - media type of stream. Set to null if unknown
    `packagePath` - - relative filePath where the tree should be inserted as XML file
  Throws:
    `Exception` - In case the file could not be saved

### insert

    public void insert(byte[] fileBytes,
                       String fileDestPath)
                throws Exception

  Insert byte array into OdfPackage. An existing file will be replaced.

  Parameters:
    `fileBytes` - - data of the file stream to be stored in package
    `fileDestPath` - - relative filePath where the DOM tree should be inserted as XML file
  Throws:
    `Exception` - when the DOM tree could not be inserted

### insert

    public void insert(byte[] fileBytes,
                       String fileDestPath,
                       String mediaType)
                throws Exception

  Insert byte array into OdfPackage. An existing file will be replaced.

  Parameters:
    `fileBytes` - - data of the file stream to be stored in package
    `mediaType` - - media type of stream. Set to null if unknown
    `fileDestPath` - - relative filePath where the DOM tree should be inserted as XML file
  Throws:
    `Exception` - when the DOM tree could not be inserted

### getBytes

    public byte[] getBytes(String packagePath)
                    throws Exception

  Get package (sub-) content as byte array

  Parameters:
    `packagePath` - relative filePath to the package content
  Returns:
    the unzipped package content as byte array
  Throws:
    `Exception`

### getInputStream

    public InputStream getInputStream(String packagePath)
                               throws Exception

  Get subcontent as InputStream

  Parameters:
    `packagePath` - of the desired stream.
  Returns:
    Inputstream of the ODF file within the package for the given path.
  Throws:
    `Exception`

### getInputStream

    public InputStream getInputStream()
                               throws Exception

  Gets the InputStream containing whole OdfPackage.

  Returns:
    the ODF package as input stream
  Throws:
    `Exception` - - if the package could not be read

### insertOutputStream

    public OutputStream insertOutputStream(String packagePath)
                                    throws Exception

  Insert the OutputStream for into OdfPackage. An existing file will be replaced.

  Parameters:
    `packagePath` - - relative filePath where the DOM tree should be inserted as XML file
  Returns:
    outputstream for the data of the file to be stored in package
  Throws:
    `Exception` - when the DOM tree could not be inserted

### insertOutputStream

    public OutputStream insertOutputStream(String packagePath,
                                           String mediaType)
                                    throws Exception

  Insert the OutputStream - to be filled after method - when stream is closed into OdfPackage. An existing file will be replaced.

  Parameters:
    `packagePath` - - relative filePath where the DOM tree should be inserted as XML file
    `mediaType` - - media type of stream
  Returns:
    outputstream for the data of the file to be stored in package
  Throws:
    `Exception` - when the DOM tree could not be inserted

### remove

    public void remove(String packagePath)

### isExternalReference

    public static boolean isExternalReference(String fileRef)

  Checks if the given reference is a reference, which points outside the ODF package

  Parameters:
    `fileRef` - the file reference to be checked
  Returns:
    true if the reference is an package external reference

### getEntityResolver

    public EntityResolver getEntityResolver()

  get EntityResolver to be used in XML Parsers which can resolve content inside the OdfPackage

  Returns:
    a SAX EntityResolver

### getURIResolver

    public URIResolver getURIResolver()

  get URIResolver to be used in XSL Transformations which can resolve content inside the OdfPackage

  Returns:
    a TraX Resolver

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2009. All Rights Reserved.