writer2latex.xmerge
Class OfficeZip

java.lang.Object
  extended by writer2latex.xmerge.OfficeZip

 class OfficeZip
extends java.lang.Object

Class used by OfficeDocument to handle reading and writing from a ZIP file, as well as storing ZIP entries.

Author:
Herbie Ong

Nested Class Summary
private  class OfficeZip.Entry
          This inner class is used as a data structure for holding a ZipEntry info and its corresponding bytes.
 
Field Summary
private static int BUFFERSIZE
           
private  int contentIndex
           
private static java.lang.String CONTENTXML
          File name of the XML file in a zipped document.
private  java.util.List entryList
           
private  int manifestIndex
           
private static java.lang.String MANIFESTXML
           
private  int metaIndex
           
private static java.lang.String METAXML
           
private  int settingsIndex
           
private static java.lang.String SETTINGSXML
           
private  int styleIndex
           
private static java.lang.String STYLEXML
           
 
Constructor Summary
OfficeZip()
          Default constructor.
 
Method Summary
private  java.util.zip.ZipEntry createZipEntry(java.lang.String name, byte[] bytes, int method)
          Creates a ZipEntry object based on the given params.
(package private)  byte[] getContentXMLBytes()
          This method returns the CONTENTXML file in a byte array.
private  byte[] getEntryBytes(int index)
          Used by the getContentXMLBytes method and the getStyleXMLBytes method to return the byte array from the corresponding entry in the entryList.
(package private)  byte[] getManifestXMLBytes()
          This method returns the MANIFESTXML file in a byte array.
(package private)  byte[] getMetaXMLBytes()
          This method returns the METAXML file in a byte array.
(package private)  byte[] getNamedBytes(java.lang.String name)
          This method returns the bytes corresponding to the entry named in the parameter.
(package private)  byte[] getSettingsXMLBytes()
          This method returns the SETTINGSXML file in a byte array.
(package private)  byte[] getStyleXMLBytes()
          This method returns the STYLEXML file in a byte array.
(package private)  void read(java.io.InputStream is)
          Read each zip entry in the InputStream object and store in entryList both the ZipEntry object as well as the bits of each entry.
(package private)  void setContentXMLBytes(byte[] bytes)
          Set or replace the byte array for the CONTENTXML file.
private  int setEntryBytes(int index, byte[] bytes, java.lang.String name)
          Used by the setContentXMLBytes method and the setStyleXMLBytes to either replace an existing Entry, or create a new entry in entryList.
(package private)  void setManifestXMLBytes(byte[] bytes)
          Set or replace the byte array for the MANIFESTXML file.
(package private)  void setMetaXMLBytes(byte[] bytes)
          Set or replace the byte array for the METAXML file.
(package private)  void setNamedBytes(java.lang.String name, byte[] bytes)
          This method sets the bytes for the named entry.
(package private)  void setSettingsXMLBytes(byte[] bytes)
          Set or replace the byte array for the SETTINGSXML file.
(package private)  void setStyleXMLBytes(byte[] bytes)
          Set or replace the byte array for the STYLEXML file.
(package private)  void write(java.io.OutputStream os)
          Write out the ZIP entries into the OutputStream object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENTXML

private static final java.lang.String CONTENTXML
File name of the XML file in a zipped document.

See Also:
Constant Field Values

STYLEXML

private static final java.lang.String STYLEXML
See Also:
Constant Field Values

METAXML

private static final java.lang.String METAXML
See Also:
Constant Field Values

SETTINGSXML

private static final java.lang.String SETTINGSXML
See Also:
Constant Field Values

MANIFESTXML

private static final java.lang.String MANIFESTXML
See Also:
Constant Field Values

BUFFERSIZE

private static final int BUFFERSIZE
See Also:
Constant Field Values

entryList

private java.util.List entryList

contentIndex

private int contentIndex

styleIndex

private int styleIndex

metaIndex

private int metaIndex

settingsIndex

private int settingsIndex

manifestIndex

private int manifestIndex
Constructor Detail

OfficeZip

OfficeZip()
Default constructor.

Method Detail

read

void read(java.io.InputStream is)
    throws java.io.IOException

Read each zip entry in the InputStream object and store in entryList both the ZipEntry object as well as the bits of each entry. Call this method before calling the getContentXMLBytes method or the getStyleXMLBytes method.

Keep track of the CONTENTXML and STYLEXML using contentIndex and styleIndex, respectively.

Parameters:
is - InputStream object to read.
Throws:
java.io.IOException - If any I/O error occurs.

getContentXMLBytes

byte[] getContentXMLBytes()
This method returns the CONTENTXML file in a byte array. It returns null if there is no CONTENTXML in this zip file.

Returns:
CONTENTXML in a byte array.

getStyleXMLBytes

byte[] getStyleXMLBytes()
This method returns the STYLEXML file in a byte array. It returns null if there is no STYLEXML in this zip file.

Returns:
STYLEXML in a byte array.

getMetaXMLBytes

byte[] getMetaXMLBytes()
This method returns the METAXML file in a byte array. It returns null if there is no METAXML in this zip file.

Returns:
METAXML in a byte array.

getSettingsXMLBytes

byte[] getSettingsXMLBytes()
This method returns the SETTINGSXML file in a byte array. It returns null if there is no SETTINGSXML in this zip file.

Returns:
SETTINGSXML in a byte array.

getManifestXMLBytes

byte[] getManifestXMLBytes()
This method returns the MANIFESTXML file in a byte array. It returns null if there is no MANIFESTXML in this zip file.

Returns:
MANIFESTXML in a byte array.

getNamedBytes

byte[] getNamedBytes(java.lang.String name)
This method returns the bytes corresponding to the entry named in the parameter.

Parameters:
name - The name of the entry in the Zip file to retrieve.
Returns:
The data for the named entry in a byte array or null if no entry is found.

setNamedBytes

void setNamedBytes(java.lang.String name,
                   byte[] bytes)
This method sets the bytes for the named entry. It searches for a matching entry in the LinkedList. If no entry is found, a new one is created. Writing of data is defferred to setEntryBytes().

Parameters:
name - The name of the entry to search for.
bytes - The new data to write.

getEntryBytes

private byte[] getEntryBytes(int index)
Used by the getContentXMLBytes method and the getStyleXMLBytes method to return the byte array from the corresponding entry in the entryList.

Parameters:
index - Index of Entry object in entryList.
Returns:
byte array associated in that Entry object or null, if there is not such Entry.

setContentXMLBytes

void setContentXMLBytes(byte[] bytes)
Set or replace the byte array for the CONTENTXML file.

Parameters:
bytes - byte array for the CONTENTXML file.

setStyleXMLBytes

void setStyleXMLBytes(byte[] bytes)
Set or replace the byte array for the STYLEXML file.

Parameters:
bytes - byte array for the STYLEXML file.

setMetaXMLBytes

void setMetaXMLBytes(byte[] bytes)
Set or replace the byte array for the METAXML file.

Parameters:
bytes - byte array for the METAXML file.

setSettingsXMLBytes

void setSettingsXMLBytes(byte[] bytes)
Set or replace the byte array for the SETTINGSXML file.

Parameters:
bytes - byte array for the SETTINGSXML file.

setManifestXMLBytes

void setManifestXMLBytes(byte[] bytes)
Set or replace the byte array for the MANIFESTXML file.

Parameters:
bytes - byte array for the MANIFESTXML file.

setEntryBytes

private int setEntryBytes(int index,
                          byte[] bytes,
                          java.lang.String name)

Used by the setContentXMLBytes method and the setStyleXMLBytes to either replace an existing Entry, or create a new entry in entryList.

If there is an Entry object within entryList that corresponds to the index, replace the ZipEntry info.

Parameters:
index - Index of Entry to modify.
bytes - Entry value.
name - Name of Entry.
Returns:
Index of value added or modified in entryList

write

void write(java.io.OutputStream os)
     throws java.io.IOException
Write out the ZIP entries into the OutputStream object.

Parameters:
os - OutputStream object to write ZIP.
Throws:
java.io.IOException - If any ZIP I/O error occurs.

createZipEntry

private java.util.zip.ZipEntry createZipEntry(java.lang.String name,
                                              byte[] bytes,
                                              int method)
Creates a ZipEntry object based on the given params.

Parameters:
name - Name for the ZipEntry.
bytes - byte array for ZipEntry.
method - ZIP method to be used for ZipEntry.
Returns:
A ZipEntry object.