writer2latex.xmerge

Class OfficeDocument

Implemented Interfaces:
Document, OfficeConstants, OutputFile

public class OfficeDocument
extends java.lang.Object
implements Document, OfficeConstants

An implementation of Document for StarOffice documents.

Fields inherited from interface writer2latex.xmerge.OfficeConstants

ATTRIBUTE_CONFIG_NAME, ATTRIBUTE_CONFIG_TYPE, ATTRIBUTE_DEFAULT_CELL_STYLE, ATTRIBUTE_FO_FONT_FAMILY, ATTRIBUTE_FO_FONT_FAMILY_GENERIC, ATTRIBUTE_MANIFEST_FILE_PATH, ATTRIBUTE_MANIFEST_FILE_TYPE, ATTRIBUTE_OFFICE_CLASS, ATTRIBUTE_SPACE_COUNT, ATTRIBUTE_STYLE_FONT_PITCH, ATTRIBUTE_STYLE_NAME, ATTRIBUTE_TABLE_BASE_CELL_ADDRESS, ATTRIBUTE_TABLE_BOOLEAN_VALUE, ATTRIBUTE_TABLE_CELL_RANGE_ADDRESS, ATTRIBUTE_TABLE_CURRENCY, ATTRIBUTE_TABLE_DATE_VALUE, ATTRIBUTE_TABLE_EXPRESSION, ATTRIBUTE_TABLE_FORMULA, ATTRIBUTE_TABLE_NAME, ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED, ATTRIBUTE_TABLE_NUM_ROWS_REPEATED, ATTRIBUTE_TABLE_STRING_VALUE, ATTRIBUTE_TABLE_STYLE_NAME, ATTRIBUTE_TABLE_TIME_VALUE, ATTRIBUTE_TABLE_VALUE, ATTRIBUTE_TABLE_VALUE_TYPE, ATTRIBUTE_TEXT_STYLE_NAME, CELLTYPE_BOOLEAN, CELLTYPE_CURRENCY, CELLTYPE_DATE, CELLTYPE_FLOAT, CELLTYPE_PERCENT, CELLTYPE_STRING, CELLTYPE_TIME, STC_MIME_TYPE, STI_MIME_TYPE, STW_MIME_TYPE, SXC_FILE_EXTENSION, SXC_MIME_TYPE, SXC_TYPE, SXD_MIME_TYPE, SXG_MIME_TYPE, SXI_MIME_TYPE, SXM_MIME_TYPE, SXW_FILE_EXTENSION, SXW_MIME_TYPE, SXW_TYPE, TAG_BOOKMARK, TAG_BOOKMARK_START, TAG_CONFIG_ITEM, TAG_CONFIG_ITEM_MAP_ENTRY, TAG_CONFIG_ITEM_MAP_INDEXED, TAG_CONFIG_ITEM_MAP_NAMED, TAG_CONFIG_ITEM_SET, TAG_HEADING, TAG_HYPERLINK, TAG_LINE_BREAK, TAG_LIST_HEADER, TAG_LIST_ITEM, TAG_MANIFEST_FILE, TAG_MANIFEST_ROOT, TAG_NAMED_EXPRESSIONS, TAG_OFFICE_AUTOMATIC_STYLES, TAG_OFFICE_BODY, TAG_OFFICE_DOCUMENT, TAG_OFFICE_DOCUMENT_CONTENT, TAG_OFFICE_DOCUMENT_META, TAG_OFFICE_DOCUMENT_SETTINGS, TAG_OFFICE_DOCUMENT_STYLES, TAG_OFFICE_FONT_DECLS, TAG_OFFICE_FONT_FACE_DECLS, TAG_OFFICE_MASTER_STYLES, TAG_OFFICE_META, TAG_OFFICE_SETTINGS, TAG_OFFICE_STYLES, TAG_ORDERED_LIST, TAG_PARAGRAPH, TAG_SPACE, TAG_SPAN, TAG_STYLE_FONT_DECL, TAG_TABLE, TAG_TABLE_CELL, TAG_TABLE_COLUMN, TAG_TABLE_NAMED_EXPRESSION, TAG_TABLE_NAMED_RANGE, TAG_TABLE_ROW, TAG_TABLE_SCENARIO, TAG_TAB_STOP, TAG_TEXT, TAG_TEXT_AUTHOR_INITIALS, TAG_TEXT_CREATION_TIME, TAG_TEXT_DATE, TAG_TEXT_EXPRESSION, TAG_TEXT_PAGE_COUNT, TAG_TEXT_PAGE_NUMBER, TAG_TEXT_PAGE_VARIABLE_GET, TAG_TEXT_SEQUENCE, TAG_TEXT_SUBJECT, TAG_TEXT_TEXT_INPUT, TAG_TEXT_TIME, TAG_TEXT_TITLE, TAG_TEXT_USER_FIELD_GET, TAG_TEXT_VARIABLE_GET, TAG_TEXT_VARIABLE_INPUT, TAG_TEXT_VARIABLE_SET, TAG_UNORDERED_LIST

Constructor Summary

OfficeDocument(String name)
Default constructor.
OfficeDocument(String name, boolean namespaceAware, boolean validating)
Constructor with arguments to set namespaceAware and validating flags.

Method Summary

void
addEmbeddedObject(EmbeddedObject embObj)
Adds a new embedded object to the document.
Document
getContentDOM()
Return a DOM Document object of the content.xml file.
protected String
getDocumentMimeType()
Method to return the MIME type of the document.
EmbeddedObject
getEmbeddedObject(String name)
Returns the embedded object corresponding to the name provided.
Iterator
getEmbeddedObjects()
Returns all the embedded objects (graphics, formulae, etc.) present in this document.
protected String
getFileExtension()
Returns the file extension for this type of Document.
String
getFileName()
Return the file name of the Document, possibly with the standard extension.
Document
getMetaDOM()
Return a DOM Document object of the meta.xml file.
String
getName()
Return the name of the Document.
protected String
getOfficeClassAttribute()
Return the office:class attribute value.
Document
getSettingsDOM()
Return a DOM Document object of the settings.xml file.
Document
getStyleDOM()
Return a DOM Document object of the style.xml file.
void
initContentDOM()
Initializes a new DOM Document with the content containing minimum OpenOffice XML tags.
void
initSettingsDOM()
Initializes a new DOM Document with the content containing minimum OpenOffice XML tags.
void
initStyleDOM()
Initializes a new DOM Document with styles containing minimum OpenOffice XML tags.
boolean
isPackageFormat()
Package or flat format?
void
read(InputStream is)
Read the Office Document from the given InputStream.
void
read(InputStream is, boolean isZip)
Read the Office Document from the given InputStream.
void
setContentDOM(Node newDom)
Sets the content tree of the document.
void
setMetaDOM(Node newDom)
Sets the meta tree of the document.
void
setSettingsDOM(Node newDom)
Sets the settings tree of the document.
void
setStyleDOM(Node newDom)
Sets the style tree of the document.
void
write(OutputStream os)
Write out Office ZIP file format.
void
write(OutputStream os, boolean isZip)
Write out Office ZIP file format.

Constructor Details

OfficeDocument

public OfficeDocument(String name)
Default constructor.
Parameters:
name - Document name.

OfficeDocument

public OfficeDocument(String name,
                      boolean namespaceAware,
                      boolean validating)
Constructor with arguments to set namespaceAware and validating flags.
Parameters:
name - Document name (may or may not contain extension).
namespaceAware - Value for namespaceAware flag.
validating - Value for validating flag.

Method Details

addEmbeddedObject

public void addEmbeddedObject(EmbeddedObject embObj)
Adds a new embedded object to the document.
Parameters:
embObj - An instance of EmbeddedObject.

getContentDOM

public Document getContentDOM()
Return a DOM Document object of the content.xml file. Note that a content DOM is not created when the constructor is called. So, either the read method or the initContentDOM method will need to be called ahead on this object before calling this method.
Returns:
DOM Document object.

getDocumentMimeType

protected String getDocumentMimeType()
Method to return the MIME type of the document.
Returns:
String The document's MIME type.

getEmbeddedObject

public EmbeddedObject getEmbeddedObject(String name)
Returns the embedded object corresponding to the name provided. The name should be stripped of any preceding path characters, such as '/', '.' or '#'.
Parameters:
name - The name of the embedded object to retrieve.
Returns:
An EmbeddedObject instance representing the named object.

getEmbeddedObjects

public Iterator getEmbeddedObjects()
Returns all the embedded objects (graphics, formulae, etc.) present in this document.
Returns:
An Iterator of EmbeddedObject objects.

getFileExtension

protected String getFileExtension()
Returns the file extension for this type of Document.
Returns:
The file extension of Document.

getFileName

public String getFileName()
Return the file name of the Document, possibly with the standard extension.
Specified by:
getFileName in interface OutputFile
Returns:
The file name of Document.

getMetaDOM

public Document getMetaDOM()
Return a DOM Document object of the meta.xml file. Note that a content DOM is not created when the constructor is called. So, either the read method or the initContentDOM method will need to be called ahead on this object before calling this method.
Returns:
DOM Document object.

getName

public String getName()
Return the name of the Document.
Specified by:
getName in interface Document
Returns:
The name of Document.

getOfficeClassAttribute

protected String getOfficeClassAttribute()
Return the office:class attribute value.
Returns:
The attribute value.

getSettingsDOM

public Document getSettingsDOM()
Return a DOM Document object of the settings.xml file. Note that a content DOM is not created when the constructor is called. So, either the read method or the initContentDOM method will need to be called ahead on this object before calling this method.
Returns:
DOM Document object.

getStyleDOM

public Document getStyleDOM()
Return a DOM Document object of the style.xml file. Note that this may return null if there is no style DOM. Note that a style DOM is not created when the constructor is called. Depending on the InputStream, a read method may or may not build a style DOM. When creating a new style DOM, call the initStyleDOM method first.
Returns:
DOM Document object.

initContentDOM

public final void initContentDOM()
            throws IOException
Initializes a new DOM Document with the content containing minimum OpenOffice XML tags.

initSettingsDOM

public final void initSettingsDOM()
            throws IOException
Initializes a new DOM Document with the content containing minimum OpenOffice XML tags.

initStyleDOM

public final void initStyleDOM()
            throws IOException
Initializes a new DOM Document with styles containing minimum OpenOffice XML tags.

isPackageFormat

public boolean isPackageFormat()
Package or flat format?
Returns:
true if the document is in package format, false if it's flat xml

read

public void read(InputStream is)
            throws IOException
Read the Office Document from the given InputStream. FIX3 (HJ): Perform simple type detection to determine package or flat format
Specified by:
read in interface Document
Parameters:
is - Office document InputStream.

read

public void read(InputStream is,
                 boolean isZip)
            throws IOException
Read the Office Document from the given InputStream.
Parameters:
is - Office document InputStream.
isZip - boolean Identifies whether a file is zipped or not

setContentDOM

public void setContentDOM(Node newDom)
Sets the content tree of the document.
Parameters:
newDom - Node containing the new content tree.

setMetaDOM

public void setMetaDOM(Node newDom)
Sets the meta tree of the document.
Parameters:
newDom - Node containing the new meta tree.

setSettingsDOM

public void setSettingsDOM(Node newDom)
Sets the settings tree of the document.
Parameters:
newDom - Node containing the new settings tree.

setStyleDOM

public void setStyleDOM(Node newDom)
Sets the style tree of the document.
Parameters:
newDom - Node containing the new style tree.

write

public void write(OutputStream os)
            throws IOException
Write out Office ZIP file format.
Specified by:
write in interface OutputFile
Parameters:
os - XML OutputStream.

write

public void write(OutputStream os,
                  boolean isZip)
            throws IOException
Write out Office ZIP file format.
Parameters:
os - XML OutputStream.
isZip - boolean