public class TextDocument extends Document implements ListContainer, ParagraphContainer, VariableContainer, ChartContainer, FormContainer, ControlContainer
| Modifier and Type | Class and Description |
|---|---|
static class |
TextDocument.OdfMediaType
This enum contains all possible media types of SpreadsheetDocument documents.
|
Document.ScriptTypeOdfSchemaDocument.OdfXMLFileOdfPackageDocument.ResourceselectionManagermContentDom, mDocumentStyles, mMetaDom, mSettingsDom, mStylesDommDocumentMediaType, mDocumentPathInPackage, mPackage, ROOT_DOCUMENT_PATH| Modifier | Constructor and Description |
|---|---|
protected |
TextDocument(OdfPackage pkg,
String internalPath,
TextDocument.OdfMediaType odfMediaType)
To avoid data duplication a new document is only created, if not already opened.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addColumnBreak()
Appends a new column break to this document.
|
void |
addColumnBreak(Paragraph refParagraph)
Appends a new column break to this document after the reference paragraph.
|
List |
addList()
Add a new List to this container.
|
List |
addList(ListDecorator decorator)
Add a List with specified ListDecorator to this container.
|
void |
addPageBreak()
Appends a new page break to this document.
|
void |
addPageBreak(Paragraph refParagraph)
Appends a new page break to this document after the reference paragraph.
|
void |
addPageBreak(Paragraph refParagraph,
MasterPage master)
Appends a new page break to this document after the reference paragraph, and the master page
style will be applied to the new page.
|
Paragraph |
addParagraph(String text)
Creates a new paragraph and append text.
|
Table |
addTable(int numRows,
int numCols,
int headerRowNumber,
int headerColumnNumber)
Add a new Table to this container with a specified row number and column number.
|
OdfTextParagraph |
addText(String text)
Deprecated.
As of Simple version 0.5, replaced by
Paragraph.appendTextContent(String content) |
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.
|
Section |
appendSection(String name)
Create an empty section and append it at the end of the text document.
|
void |
changeMode(TextDocument.OdfMediaType mediaType)
Changes the document to the given mediatype.
|
void |
clearList()
Remove all Lists from this container.
|
Chart |
createChart(String title,
DataSet dataset,
Rectangle rect)
Creates a new Chart for this container.
|
Chart |
createChart(String title,
SpreadsheetDocument document,
CellRangeAddressList cellRangeAddr,
boolean firstRowAsLabel,
boolean firstColumnAsLabel,
boolean rowAsDataSeries,
Rectangle rect)
Creates a new Chart for this container.
|
Chart |
createChart(String title,
String[] labels,
String[] legends,
double[][] data,
Rectangle rect)
Creates a new Chart for this container.
|
TextTableOfContentElement |
createDefaultTOC(Paragraph refParagraph,
boolean before)
Create a new Table Of Content to this document before the reference paragraph.
|
Control |
createDrawControl()
Create an instance of control and and append it at the end of this container.
|
Form |
createForm(String name)
Create a form with specified name in this text document.
|
TextTableOfContentElement |
createTOCwithStyle(Paragraph refParagraph,
TOCStyle additionalStyle,
boolean before)
Create a new Table Of Content to this document before the reference paragraph.
|
VariableField |
declareVariable(String name,
VariableField.VariableType type)
Declare a new variable field to this container.
|
void |
deleteChartById(String chartId)
Deletes chart by chart id.
|
void |
deleteChartByTitle(String title)
Deletes chart(s) by chart title.
|
boolean |
getApplyDesignMode()
Get the attribute
form:apply-design-mode which specifies whether forms are
presented in editable or non-editable state. |
boolean |
getAutomaticFocus()
Get the attribute
form:automatic-focus which specifies whether the consumer
loading the document should set the focus to a form control. |
Chart |
getChartById(String chartId)
Gets chart with specified id.
|
List<Chart> |
getChartByTitle(String title)
Gets chart list with specified title.
|
int |
getChartCount()
Returns the chart count of this container
|
OfficeTextElement |
getContentRoot()
Get the content root of a text document.
|
OdfElement |
getDrawControlContainerElement()
Get the ODF element which can have DrawControlElement as child element directly.
|
Footer |
getFooter()
Get the Standard Page footer of this text document.
|
Footer |
getFooter(boolean isFirstPage)
Get the footer of this text document.
|
Form |
getFormByName(String name)
Return a form whose name is a given value.
|
OfficeFormsElement |
getFormContainerElement()
Get the ODF element
OfficeFormsElement which can have FormFormElement
as child element directly according to ODF specification. |
Iterator<Form> |
getFormIterator()
Get a form iterator to traverse all the forms in this document.
|
Header |
getHeader()
Get the Standard Page header of this text document.
|
Header |
getHeader(boolean isFirstPage)
Get the header of this text document.
|
OdfElement |
getListContainerElement()
Get the ODF element which can have
|
Iterator<List> |
getListIterator()
Return an Iterator of the Lists in this ListContainer.
|
Paragraph |
getParagraphByIndex(int index,
boolean isEmptyParagraphSkipped)
Return a paragraph with a given index.
|
Paragraph |
getParagraphByReverseIndex(int reverseIndex,
boolean isEmptyParagraphSkipped)
Return a paragraph with a given index.
|
OdfElement |
getParagraphContainerElement()
Get the ODF element which can have
|
Iterator<Paragraph> |
getParagraphIterator()
Return an Iterator of the paragraph in this container.
|
OdfElement |
getTableContainerElement()
Get the ODF element which can have
|
OdfElement |
getVariableContainerElement()
Get the ODF element which can have variable declare section as child element directly according
to ODF specification.
|
VariableField |
getVariableFieldByName(String name)
Return the declared variable by name.
|
void |
insertContentFromDocumentAfter(TextDocument sourceDocument,
Paragraph referenceParagraph,
boolean isCopyStyle)
Copy text content of the source TextDocument and insert it to the current TextDocument after
the reference Paragraph, with Styles or without Styles.
|
void |
insertContentFromDocumentBefore(TextDocument sourceDocument,
Paragraph referenceParagraph,
boolean isCopyStyle)
Copy text content of the source TextDocument and insert it to the current TextDocument before
the reference Paragraph, with Styles or without Styles.
|
OdfElement |
insertOdfElement(OdfElement referenceOdfElement,
Document sourceDocument,
OdfElement sourceOdfElement,
boolean before)
Copy a OdfElement and insert it before or after the Reference OdfElement in the TextDocument,
whether the OdfElement is in this TextDocument or in a different Document.
|
Paragraph |
insertParagraph(Paragraph referenceParagraph,
Paragraph sourceParagraph,
boolean before)
Copy a Paragraph and insert it before or after the Reference Paragraph in the text document,
whether the Paragraph is in this document or in a different document.
|
Table |
insertTable(Paragraph referenceParagraph,
Table sourceTable,
boolean before)
Copy a Table and insert it before or after the Reference Paragraph in the text document,
whether the Table is in this TextDocument or in a different Document.
|
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()
Deprecated.
As of Simple version 0.5, replaced by
Paragraph.newParagraph(ParagraphContainer) |
OdfTextParagraph |
newParagraph(String text)
Deprecated.
As of Simple version 0.5, replaced by
addParagraph(String 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 |
removeForm(Form form)
Remove a form with the specified name in this document.
|
boolean |
removeList(List list)
Remove the existing List from this container.
|
boolean |
removeParagraph(Paragraph para)
Remove paragraph from this document
|
void |
setApplyDesignMode(boolean isDesignMode)
Set the attribute
form:apply-design-mode which specifies whether forms are
presented in editable or non-editable state. |
void |
setAutomaticFocus(boolean isAutoFocus)
Set the attribute
form:automatic-focus which specifies whether the consumer
loading the document should set the focus to a form control. |
void |
setPageColumns(int columnsNumber,
double spacing)
Defines several columns to the page whose style is specified.
|
addTable, addTable, close, getComponentMap, getContentRoot, getEmbeddedDocument, getEmbeddedDocuments, getEmbeddedDocuments, getLocale, getOdfMediaType, getOfficeMetadata, getScriptType, getSectionByName, getSectionIterator, getSelectionManager, getTableBuilder, getTableByName, getTableContainerImpl, getTableList, insertDocument, loadDocument, loadDocument, loadDocument, loadDocument, LoadTableTemplateFromForeignTable, loadTemplate, newImage, removeElementLinkedResource, save, save, save, setLocale, setLocale, setOdfMediaType, setPassword, setSelectionManager, toStringgetBaseURI, getBookmarkRDFMetadata, getContentDom, getContentStream, getDocumentStyles, getFileDom, getInContentMetadata, getInContentMetadataFromCache, getManifestRDFMetadata, getMasterPages, getMetaDom, getMetaStream, getOfficeMasterStyles, getOrCreateDocumentStyles, getRDFMetadata, getSettingsDom, getSettingsStream, getStylesDom, getStylesStream, getTables, getXMLFilePathflushDoms, getDocumentPath, getFileDom, getMediaTypeString, getPackage, getXMLFileMetadata, isExternalReference, isRootDocument, loadSubDocument, normalizeDocumentPath, removeDocument, save, setMediaTypeStringprotected TextDocument(OdfPackage pkg, String internalPath, TextDocument.OdfMediaType odfMediaType)
public static TextDocument newTextDocument() throws Exception
Exception - - if the document could not be createdpublic static TextDocument newTextDocument(TextDocument.OdfMediaType mimeType) throws Exception
Exception - - if the document could not be createdpublic static TextDocument newTextTemplateDocument() throws Exception
Exception - - if the template could not be createdpublic static TextDocument newTextMasterDocument() throws Exception
Exception - - if the document could not be createdpublic static TextDocument newTextWebDocument() throws Exception
Exception - - if the document could not be createdpublic static TextDocument loadDocument(InputStream inputStream) throws Exception
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.
inputStream - - the InputStream of the ODF text document.Exception - - if the document could not be created.public static TextDocument loadDocument(String documentPath) throws Exception
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.
documentPath - - the path from where the document can be loadedException - - if the document could not be created.public static TextDocument loadDocument(File file) throws Exception
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.
file - - a file representing the ODF text document.Exception - - if the document could not be created.public OfficeTextElement getContentRoot() throws Exception
getContentRoot in class DocumentException - if the file DOM could not be created.public OdfTextParagraph newParagraph(String text) throws Exception
addParagraph(String text)text - Exception - if the file DOM could not be created.addParagraph(String)public OdfTextParagraph newParagraph() throws Exception
Paragraph.newParagraph(ParagraphContainer)Exception - if the file DOM could not be created.Paragraph.newParagraph(ParagraphContainer),
addParagraph(String)public OdfTextParagraph addText(String text) throws Exception
Paragraph.appendTextContent(String content)text - initial text for the paragraph.Exception - if the file DOM could not be created.Paragraph.appendTextContent(String),
Paragraph.appendTextContentNotCollapsed(String),
getParagraphByIndex(int, boolean),
getParagraphByReverseIndex(int, boolean)public void changeMode(TextDocument.OdfMediaType mediaType)
mediaType - the related ODF mimetypepublic Section appendSection(Section section, boolean isResourceCopied)
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.
section - - the section objectisResourceCopied - - whether the linked resource is copied or not.public Section appendSection(String name)
name - - specify the section nameRuntimeException - if content DOM could not be initializedpublic Header getHeader()
public Header getHeader(boolean isFirstPage)
isFirstPage - if isFirstPage is true, return the First Page header, otherwise
return Standard Page header.public Footer getFooter()
public Footer getFooter(boolean isFirstPage)
isFirstPage - if isFirstPage is true, return the First Page footer, otherwise
return Standard Page footer.public OdfElement getTableContainerElement()
TableContainergetTableContainerElement in interface TableContainerpublic OdfElement getListContainerElement()
ListContainergetListContainerElement in interface ListContainerpublic List addList()
ListContaineraddList in interface ListContainerpublic List addList(ListDecorator decorator)
ListContaineraddList in interface ListContainerdecorator - the specified ListDecoratorpublic void clearList()
ListContainerclearList in interface ListContainerpublic Iterator<List> getListIterator()
ListContainergetListIterator in interface ListContainerIteratorpublic boolean removeList(List list)
ListContainerremoveList in interface ListContainerpublic void addPageBreak()
public void addPageBreak(Paragraph refParagraph)
refParagraph - the reference paragraph after where the page break inserted.public void setPageColumns(int columnsNumber,
double spacing)
columnsNumber - the number of columns (are of width identical)spacing - column spacing in cm (ex. 2.40 for 2,4 cm)public void addColumnBreak()
public void addColumnBreak(Paragraph refParagraph)
refParagraph - the reference paragraph after where the column break inserted.public void addPageBreak(Paragraph refParagraph, MasterPage master)
refParagraph - the reference paragraph after where the page break inserted.master - the master page style applied to the new page.public Paragraph addParagraph(String text)
addParagraph in interface ParagraphContainertext - the text content of this paragraphpublic boolean removeParagraph(Paragraph para)
removeParagraph in interface ParagraphContainerpara - the instance of paragraphpublic OdfElement getParagraphContainerElement()
ParagraphContainergetParagraphContainerElement in interface ParagraphContainerpublic Paragraph getParagraphByIndex(int index, boolean isEmptyParagraphSkipped)
ParagraphContainerAn index of zero represents the first paragraph.
If empty paragraph is skipped, the empty paragraph won't be counted.
getParagraphByIndex in interface ParagraphContainerindex - - the index started from 0.isEmptyParagraphSkipped - - whether the empty paragraph is skipped or notpublic Paragraph getParagraphByReverseIndex(int reverseIndex, boolean isEmptyParagraphSkipped)
ParagraphContainerAn index of zero represents the last paragraph.
If empty paragraph is skipped, the empty paragraph won't be counted.
getParagraphByReverseIndex in interface ParagraphContainerreverseIndex - - the index started from 0 in reverse order.isEmptyParagraphSkipped - - whether the empty paragraph is skipped or notpublic Iterator<Paragraph> getParagraphIterator()
ParagraphContainergetParagraphIterator in interface ParagraphContainerpublic VariableField declareVariable(String name, VariableField.VariableType type)
VariableContainerdeclareVariable in interface VariableContainername - the unique name of this variable field.type - the type of this variable field.public VariableField getVariableFieldByName(String name)
VariableContainergetVariableFieldByName in interface VariableContainername - the unique name of this variable field.public OdfElement getVariableContainerElement()
VariableContainerThe variable declare section may be
getVariableContainerElement in interface VariableContainerpublic Chart createChart(String title, DataSet dataset, Rectangle rect)
ChartContainercreateChart in interface ChartContainertitle - chart title.dataset - chart data set.rect - chart rectangle.public Chart createChart(String title, SpreadsheetDocument document, CellRangeAddressList cellRangeAddr, boolean firstRowAsLabel, boolean firstColumnAsLabel, boolean rowAsDataSeries, Rectangle rect)
ChartContainercreateChart in interface ChartContainertitle - chart title.document - the data source spreadsheet document.cellRangeAddr - the cell range address list which is used as chart data set.firstRowAsLabel - whether uses first row as label.firstColumnAsLabel - whether uses first column as label.rowAsDataSeries - whether uses data as series.rect - chart rectangle.public Chart createChart(String title, String[] labels, String[] legends, double[][] data, Rectangle rect)
ChartContainercreateChart in interface ChartContainertitle - chart rectangle.labels - label stringslegends - legend stringsdata - chart data set.rect - chart rectangle.public void deleteChartById(String chartId)
ChartContainerdeleteChartById in interface ChartContainerchartId - the id of specified chart.public void deleteChartByTitle(String title)
ChartContainerdeleteChartByTitle in interface ChartContainertitle - the title of specified chart(s).public Chart getChartById(String chartId)
ChartContainergetChartById in interface ChartContainerchartId - the id of this chart.public List<Chart> getChartByTitle(String title)
ChartContainergetChartByTitle in interface ChartContainertitle - the title of specified chart(s).public int getChartCount()
ChartContainergetChartCount in interface ChartContainerpublic TextTableOfContentElement createDefaultTOC(Paragraph refParagraph, boolean before)
refParagraph - the reference paragraph where the TOC be inserted.before - true:insert TOC before the reference paragraph. false:insert TOC after the
reference paragraph.public TextTableOfContentElement createTOCwithStyle(Paragraph refParagraph, TOCStyle additionalStyle, boolean before)
refParagraph - the reference paragraph before where the TOC inserted.additionalStyle - the additional paragraph styles that you want to include in the TOCbefore - true:insert TOC before the reference paragraph. false:insert TOC after the
reference paragraph.public Paragraph insertParagraph(Paragraph referenceParagraph, Paragraph sourceParagraph, boolean before)
referenceParagraph - - where the Paragraph be insertedsourceParagraph - - the Paragraph which will be copiedbefore - true:insert Paragraph before the reference paragraph. false:insert Paragraph
after the reference paragraph.public Table insertTable(Paragraph referenceParagraph, Table sourceTable, boolean before)
referenceParagraph - - where the Paragraph be insertedsourceParagraph - - the Paragraph which will be copiedbefore - true:insert Paragraph before the reference paragraph. false:insert Paragraph
after the reference paragraph.public OdfElement insertOdfElement(OdfElement referenceOdfElement, Document sourceDocument, OdfElement sourceOdfElement, boolean before)
referenceOdfElement - - where the OdfElement be insertedsourceDocument - - the source Document which contain the sourceOdfElementsourceOdfElement - - the OdfElement which will be copiedbefore - true:insert OdfElement before the reference OdfElement. false:insert OdfElement
after the reference OdfElement.public void insertContentFromDocumentAfter(TextDocument sourceDocument, Paragraph referenceParagraph, boolean isCopyStyle)
sourceDocument - the source TextDocumentreferenceParagraph - where the text content of the source TextDocument be insertedisCopyStyle - true:copy the styles in source document to current TextDocment. false:don't
copy the styles in source document to current TextDocment.public void insertContentFromDocumentBefore(TextDocument sourceDocument, Paragraph referenceParagraph, boolean isCopyStyle)
srcDoc - the source TextDocumentreferenceParagraph - where the text content of the source TextDocument be insertedisCopyStyle - true:copy the styles in source document to current TextDocment. false:don't
copy the styles in source document to current TextDocment.public Form createForm(String name)
createForm in interface FormContainername - - form name, represents attribute form:nameFormContainer.createForm(String)public Iterator<Form> getFormIterator()
getFormIterator in interface FormContainerFormContainer.getFormIterator()public boolean removeForm(Form form)
removeForm in interface FormContainerform - - the form to be removedFormContainer.removeForm(Form)public Form getFormByName(String name)
FormContainergetFormByName in interface FormContainername - - the name of the formpublic OfficeFormsElement getFormContainerElement()
FormContainerOfficeFormsElement which can have FormFormElement
as child element directly according to ODF specification. This element will help to find the
position to insert a new FormFormElement element.getFormContainerElement in interface FormContainerpublic boolean getApplyDesignMode()
FormContainerform:apply-design-mode which specifies whether forms are
presented in editable or non-editable state.getApplyDesignMode in interface FormContainerpublic boolean getAutomaticFocus()
FormContainerform:automatic-focus which specifies whether the consumer
loading the document should set the focus to a form control.getAutomaticFocus in interface FormContainerpublic void setApplyDesignMode(boolean isDesignMode)
FormContainerform:apply-design-mode which specifies whether forms are
presented in editable or non-editable state.setApplyDesignMode in interface FormContainerisDesignMode - - true if forms in document are presented in editable state; false if forms
in document are presented in completed statepublic void setAutomaticFocus(boolean isAutoFocus)
FormContainerform:automatic-focus which specifies whether the consumer
loading the document should set the focus to a form control.setAutomaticFocus in interface FormContainerisAutoFocus - -true if sets the focus to a form control after loading the document; false
if else.public Control createDrawControl()
ControlContainercreateDrawControl in interface ControlContainerpublic OdfElement getDrawControlContainerElement()
ControlContainergetDrawControlContainerElement in interface ControlContainerpublic Table addTable(int numRows, int numCols, int headerRowNumber, int headerColumnNumber)
The table will be inserted at the end of the tableContainer. An unique table name will be
given, you may set a custom table name using the setTableName method.
numRows - the row numbernumCols - the column numberheaderRowNumber - the header row numberheaderColumnNumber - the header column numberTableCopyright © 2010–2018 Apache Software Foundation; Copyright © 2018–2020 The Document Foundation. All rights reserved.