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.ScriptType
OdfSchemaDocument.OdfXMLFile
OdfPackageDocument.Resource
selectionManager
mContentDom, mDocumentStyles, mMetaDom, mSettingsDom, mStylesDom
mDocumentMediaType, 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, toString
getBaseURI, getBookmarkRDFMetadata, getContentDom, getContentStream, getDocumentStyles, getFileDom, getInContentMetadata, getInContentMetadataFromCache, getManifestRDFMetadata, getMasterPages, getMetaDom, getMetaStream, getOfficeMasterStyles, getOrCreateDocumentStyles, getRDFMetadata, getSettingsDom, getSettingsStream, getStylesDom, getStylesStream, getTables, getXMLFilePath
flushDoms, getDocumentPath, getFileDom, getMediaTypeString, getPackage, getXMLFileMetadata, isExternalReference, isRootDocument, loadSubDocument, normalizeDocumentPath, removeDocument, save, setMediaTypeString
protected 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 Document
Exception
- 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()
TableContainer
getTableContainerElement
in interface TableContainer
public OdfElement getListContainerElement()
ListContainer
getListContainerElement
in interface ListContainer
public List addList()
ListContainer
addList
in interface ListContainer
public List addList(ListDecorator decorator)
ListContainer
addList
in interface ListContainer
decorator
- the specified ListDecoratorpublic void clearList()
ListContainer
clearList
in interface ListContainer
public Iterator<List> getListIterator()
ListContainer
getListIterator
in interface ListContainer
Iterator
public boolean removeList(List list)
ListContainer
removeList
in interface ListContainer
public 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 ParagraphContainer
text
- the text content of this paragraphpublic boolean removeParagraph(Paragraph para)
removeParagraph
in interface ParagraphContainer
para
- the instance of paragraphpublic OdfElement getParagraphContainerElement()
ParagraphContainer
getParagraphContainerElement
in interface ParagraphContainer
public Paragraph getParagraphByIndex(int index, boolean isEmptyParagraphSkipped)
ParagraphContainer
An index of zero represents the first paragraph.
If empty paragraph is skipped, the empty paragraph won't be counted.
getParagraphByIndex
in interface ParagraphContainer
index
- - the index started from 0.isEmptyParagraphSkipped
- - whether the empty paragraph is skipped or notpublic Paragraph getParagraphByReverseIndex(int reverseIndex, boolean isEmptyParagraphSkipped)
ParagraphContainer
An index of zero represents the last paragraph.
If empty paragraph is skipped, the empty paragraph won't be counted.
getParagraphByReverseIndex
in interface ParagraphContainer
reverseIndex
- - the index started from 0 in reverse order.isEmptyParagraphSkipped
- - whether the empty paragraph is skipped or notpublic Iterator<Paragraph> getParagraphIterator()
ParagraphContainer
getParagraphIterator
in interface ParagraphContainer
public VariableField declareVariable(String name, VariableField.VariableType type)
VariableContainer
declareVariable
in interface VariableContainer
name
- the unique name of this variable field.type
- the type of this variable field.public VariableField getVariableFieldByName(String name)
VariableContainer
getVariableFieldByName
in interface VariableContainer
name
- the unique name of this variable field.public OdfElement getVariableContainerElement()
VariableContainer
The variable declare section may be
getVariableContainerElement
in interface VariableContainer
public Chart createChart(String title, DataSet dataset, Rectangle rect)
ChartContainer
createChart
in interface ChartContainer
title
- 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)
ChartContainer
createChart
in interface ChartContainer
title
- 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)
ChartContainer
createChart
in interface ChartContainer
title
- chart rectangle.labels
- label stringslegends
- legend stringsdata
- chart data set.rect
- chart rectangle.public void deleteChartById(String chartId)
ChartContainer
deleteChartById
in interface ChartContainer
chartId
- the id of specified chart.public void deleteChartByTitle(String title)
ChartContainer
deleteChartByTitle
in interface ChartContainer
title
- the title of specified chart(s).public Chart getChartById(String chartId)
ChartContainer
getChartById
in interface ChartContainer
chartId
- the id of this chart.public List<Chart> getChartByTitle(String title)
ChartContainer
getChartByTitle
in interface ChartContainer
title
- the title of specified chart(s).public int getChartCount()
ChartContainer
getChartCount
in interface ChartContainer
public 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 FormContainer
name
- - form name, represents attribute form:name
FormContainer.createForm(String)
public Iterator<Form> getFormIterator()
getFormIterator
in interface FormContainer
FormContainer.getFormIterator()
public boolean removeForm(Form form)
removeForm
in interface FormContainer
form
- - the form to be removedFormContainer.removeForm(Form)
public Form getFormByName(String name)
FormContainer
getFormByName
in interface FormContainer
name
- - the name of the formpublic OfficeFormsElement getFormContainerElement()
FormContainer
OfficeFormsElement
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 FormContainer
public boolean getApplyDesignMode()
FormContainer
form:apply-design-mode
which specifies whether forms are
presented in editable or non-editable state.getApplyDesignMode
in interface FormContainer
public boolean getAutomaticFocus()
FormContainer
form:automatic-focus
which specifies whether the consumer
loading the document should set the focus to a form control.getAutomaticFocus
in interface FormContainer
public void setApplyDesignMode(boolean isDesignMode)
FormContainer
form:apply-design-mode
which specifies whether forms are
presented in editable or non-editable state.setApplyDesignMode
in interface FormContainer
isDesignMode
- - true if forms in document are presented in editable state; false if forms
in document are presented in completed statepublic void setAutomaticFocus(boolean isAutoFocus)
FormContainer
form:automatic-focus
which specifies whether the consumer
loading the document should set the focus to a form control.setAutomaticFocus
in interface FormContainer
isAutoFocus
- -true if sets the focus to a form control after loading the document; false
if else.public Control createDrawControl()
ControlContainer
createDrawControl
in interface ControlContainer
public OdfElement getDrawControlContainerElement()
ControlContainer
getDrawControlContainerElement
in interface ControlContainer
public 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 numberTable
Copyright © 2010–2018 Apache Software Foundation; Copyright © 2018–2020 The Document Foundation. All rights reserved.