org.odftoolkit.simple
Class TextDocument

java.lang.Object
  extended by org.odftoolkit.odfdom.pkg.OdfPackageDocument
      extended by org.odftoolkit.odfdom.dom.OdfSchemaDocument
          extended by org.odftoolkit.simple.Document
              extended by org.odftoolkit.simple.TextDocument
All Implemented Interfaces:
Closeable, ListContainer

public class TextDocument
extends Document
implements ListContainer

This class represents an empty ODF text document.


Nested Class Summary
static class TextDocument.OdfMediaType
          This enum contains all possible media types of SpreadsheetDocument documents.
 
Nested classes/interfaces inherited from class org.odftoolkit.simple.Document
Document.ScriptType
 
Nested classes/interfaces inherited from class org.odftoolkit.odfdom.dom.OdfSchemaDocument
OdfSchemaDocument.OdfXMLFile
 
Nested classes/interfaces inherited from class org.odftoolkit.odfdom.pkg.OdfPackageDocument
OdfPackageDocument.Resource
 
Field Summary
 
Fields inherited from class org.odftoolkit.odfdom.dom.OdfSchemaDocument
mContentDom, mDocumentStyles, mMetaDom, mSettingsDom, mStylesDom
 
Fields inherited from class org.odftoolkit.odfdom.pkg.OdfPackageDocument
mDocumentMediaType, mDocumentPathInPackage, mPackage, ROOT_DOCUMENT_PATH
 
Constructor Summary
protected TextDocument(OdfPackage pkg, String internalPath, TextDocument.OdfMediaType odfMediaType)
          To avoid data duplication a new document is only created, if not already opened.
 
Method Summary
 List addList()
          Add a new List to this container.
 List addList(ListDecorator decorator)
          Add a List with specified ListDecorator to this container.
 OdfTextParagraph addText(String text)
          Append text to the end of a text document.
 Section appendSection(Section section, boolean isResourceCopied)
          Copy a section and append it at the end of the text document, whether the section is in this document or in a different document.
 void changeMode(TextDocument.OdfMediaType mediaType)
          Changes the document to the given mediatype.
 void clearList()
          Remove all Lists from this container.
 OfficeTextElement getContentRoot()
          Get the content root of a text document.
 OdfElement getListContainerElement()
          Get the ODF element which can have as child element directly according to ODF specification.
 Iterator<List> getListIterator()
          Return an Iterator of the Lists in this ListContainer.
static TextDocument loadDocument(File file)
          Creates an TextDocument from the OpenDocument provided by a File.
static TextDocument loadDocument(InputStream inputStream)
          Creates an TextDocument from the OpenDocument provided by a resource Stream.
static TextDocument loadDocument(String documentPath)
          Loads an TextDocument from the provided path.
 OdfTextParagraph newParagraph()
          Creates a new paragraph
 OdfTextParagraph newParagraph(String text)
          Creates a new paragraph and append text
static TextDocument newTextDocument()
          Creates an empty text document.
static TextDocument newTextDocument(TextDocument.OdfMediaType mimeType)
          Creates an empty text document.
static TextDocument newTextMasterDocument()
          Creates an empty text master document.
static TextDocument newTextTemplateDocument()
          Creates an empty text template.
static TextDocument newTextWebDocument()
          Creates an empty text web.
 boolean removeList(List list)
          Remove the existing List from this container.
 
Methods inherited from class org.odftoolkit.simple.Document
close, getContentRoot, getEmbeddedDocument, getEmbeddedDocuments, getEmbeddedDocuments, getLocale, getOdfMediaType, getOfficeMetadata, getScriptType, getSectionByName, getSectionIterator, getTableBuilder, getTableByName, getTableList, insertDocument, loadDocument, loadDocument, loadTemplate, newImage, removeElementLinkedResource, save, save, setLocale, setLocale, setOdfMediaType, toString
 
Methods inherited from class org.odftoolkit.odfdom.dom.OdfSchemaDocument
getBaseURI, getContentDom, getContentStream, getDocumentStyles, getFileDom, getMetaDom, getMetaStream, getOfficeMasterStyles, getOrCreateDocumentStyles, getSettingsDom, getSettingsStream, getStylesDom, getStylesStream, getXMLFilePath
 
Methods inherited from class org.odftoolkit.odfdom.pkg.OdfPackageDocument
flushDoms, getDocumentPath, getFileDom, getMediaTypeString, getPackage, isExternalReference, isRootDocument, loadSubDocument, normalizeDocumentPath, removeDocument, save, setMediaTypeString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextDocument

protected TextDocument(OdfPackage pkg,
                       String internalPath,
                       TextDocument.OdfMediaType odfMediaType)
To avoid data duplication a new document is only created, if not already opened. A document is cached by this constructor using the internalpath as key.

Method Detail

newTextDocument

public static TextDocument newTextDocument()
                                    throws Exception
Creates an empty text document.

Returns:
ODF text document based on a default template
Throws:
Exception - - if the document could not be created

newTextDocument

public static TextDocument newTextDocument(TextDocument.OdfMediaType mimeType)
                                    throws Exception
Creates an empty text document.

Returns:
ODF text document based on a default template
Throws:
Exception - - if the document could not be created

newTextTemplateDocument

public static TextDocument newTextTemplateDocument()
                                            throws Exception
Creates an empty text template.

Returns:
ODF text template based on a default
Throws:
Exception - - if the template could not be created

newTextMasterDocument

public static TextDocument newTextMasterDocument()
                                          throws Exception
Creates an empty text master document.

Returns:
ODF text master based on a default
Throws:
Exception - - if the document could not be created

newTextWebDocument

public static TextDocument newTextWebDocument()
                                       throws Exception
Creates an empty text web.

Returns:
ODF text web based on a default
Throws:
Exception - - if the document could not be created

loadDocument

public static TextDocument loadDocument(InputStream inputStream)
                                 throws Exception
Creates an TextDocument from the OpenDocument provided by a resource Stream.

Since an InputStream does not provide the arbitrary (non sequentiell) read access needed by TextDocument, the InputStream is cached. This usually takes more time compared to the other createInternalDocument methods. An advantage of caching is that there are no problems overwriting an input file.

If the resource stream is not a ODF text document, ClassCastException might be thrown.

Parameters:
inputStream - - the InputStream of the ODF text document.
Returns:
the text document created from the given InputStream
Throws:
Exception - - if the document could not be created.

loadDocument

public static TextDocument loadDocument(String documentPath)
                                 throws Exception
Loads an TextDocument from the provided path.

TextDocument relies on the file being available for read access over the whole lifecycle of TextDocument.

If the resource stream is not a ODF text document, ClassCastException might be thrown.

Parameters:
documentPath - - the path from where the document can be loaded
Returns:
the text document from the given path or NULL if the media type is not supported by SIMPLE.
Throws:
Exception - - if the document could not be created.

loadDocument

public static TextDocument loadDocument(File file)
                                 throws Exception
Creates an TextDocument from the OpenDocument provided by a File.

TextDocument relies on the file being available for read access over the whole lifecycle of TextDocument.

If the resource stream is not a ODF text document, ClassCastException might be thrown.

Parameters:
file - - a file representing the ODF text document.
Returns:
the text document created from the given File
Throws:
Exception - - if the document could not be created.

getContentRoot

public OfficeTextElement getContentRoot()
                                 throws Exception
Get the content root of a text document. Start here to get or create new elements of a text document like paragraphs, headings, tables or lists.

Overrides:
getContentRoot in class Document
Returns:
content root, representing the office:text tag
Throws:
Exception - if the file DOM could not be created.

newParagraph

public OdfTextParagraph newParagraph(String text)
                              throws Exception
Creates a new paragraph and append text

Parameters:
text -
Returns:
the new paragraph
Throws:
Exception - if the file DOM could not be created.

newParagraph

public OdfTextParagraph newParagraph()
                              throws Exception
Creates a new paragraph

Returns:
The new paragraph
Throws:
Exception - if the file DOM could not be created.

addText

public OdfTextParagraph addText(String text)
                         throws Exception
Append text to the end of a text document. If there is no paragraph at the end of a document, a new one will be created.

Parameters:
text - initial text for the paragraph.
Returns:
The paragraph at the end of the text document, where the text has been added to.
Throws:
Exception - if the file DOM could not be created.

changeMode

public void changeMode(TextDocument.OdfMediaType mediaType)
Changes the document to the given mediatype. This method can only be used to convert a document to a related mediatype, e.g. template.

Parameters:
mediaType - the related ODF mimetype

appendSection

public Section appendSection(Section section,
                             boolean isResourceCopied)
Copy a section and append it at the end of the text document, whether the section is in this document or in a different document.

The IDs and names in this section would be changed to ensure unique.

If the section contains a linked resource, isResourceCopied would specify whether the linked resource would be copied or not, when the copy and append happens within a same document.

Parameters:
section - - the section object
isResourceCopied - - whether the linked resource is copied or not.

getListContainerElement

public OdfElement getListContainerElement()
Description copied from interface: ListContainer
Get the ODF element which can have as child element directly according to ODF specification. This Element will help to find the position to insert a new List. For example, element is usable with element, so TextDocument will return OfficeTextElement. While Presentation Notes is an indirectly ListContainer, which holds List with the help of its grand-child element , so for Notes, DrawTextBoxElement should be return.

Specified by:
getListContainerElement in interface ListContainer
Returns:
container element which can hold .

addList

public List addList()
Description copied from interface: ListContainer
Add a new List to this container.

Specified by:
addList in interface ListContainer
Returns:
added list.

addList

public List addList(ListDecorator decorator)
Description copied from interface: ListContainer
Add a List with specified ListDecorator to this container.

Specified by:
addList in interface ListContainer
Parameters:
decorator - the specified ListDecorator
Returns:
added list.

clearList

public void clearList()
Description copied from interface: ListContainer
Remove all Lists from this container.

Specified by:
clearList in interface ListContainer

getListIterator

public Iterator<List> getListIterator()
Description copied from interface: ListContainer
Return an Iterator of the Lists in this ListContainer. The Lists are iterated in the same order that they occur in the ListContainer.

Specified by:
getListIterator in interface ListContainer
Returns:
an Iterator of the Lists in this ListContainer
See Also:
Iterator

removeList

public boolean removeList(List list)
Description copied from interface: ListContainer
Remove the existing List from this container.

Specified by:
removeList in interface ListContainer
Returns:
true, if the container contains this List.


Copyright © 2010-2011 ODF Toolkit Project. All Rights Reserved.