Class OdfTextDocument
- All Implemented Interfaces:
Closeable
,AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
This enum contains all possible media types of OdfSpreadsheetDocument documents.Nested classes/interfaces inherited from class org.odftoolkit.odfdom.doc.OdfDocument
OdfDocument.UnicodeGroup
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.doc.OdfDocument
mHasCollaboration
Fields inherited from class org.odftoolkit.odfdom.dom.OdfSchemaDocument
mContentDom, mJsonOperationQueue, mMetaDom, mSettingsDom, mStylesDom
Fields inherited from class org.odftoolkit.odfdom.pkg.OdfPackageDocument
mDocumentMediaType, mDocumentPathInPackage, mPackage, ROOT_DOCUMENT_PATH
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
OdfTextDocument
(OdfPackage pkg, String internalPath, OdfTextDocument.OdfMediaType odfMediaType) To avoid data duplication a new document is only created, if not already opened.protected
OdfTextDocument
(OdfPackage pkg, String internalPath, OdfTextDocument.OdfMediaType odfMediaType, Boolean enableCollaboration) To avoid data duplication a new document is only created, if not already opened. -
Method Summary
Modifier and TypeMethodDescriptionAppend text to the end of a text document.void
changeMode
(OdfTextDocument.OdfMediaType mediaType) Changes the document to the given mediatype.Get the content root of a text document.In LO/AO Tabs are counted from the start of text and the fo:left-margin have to be added.static OdfTextDocument
loadDocument
(File file) Creates an OdfTextDocument from the OpenDocument provided by a File.static OdfTextDocument
loadDocument
(InputStream inputStream) Creates an OdfTextDocument from the OpenDocument provided by a resource Stream.static OdfTextDocument
loadDocument
(InputStream inputStream, Boolean enableCollaboration) Creates an OdfTextDocument from the OpenDocument provided by a resource Stream.static OdfTextDocument
loadDocument
(InputStream inputStream, Map<String, Object> configuration) Creates an OdfTextDocument from the OpenDocument provided by a resource Stream.static OdfTextDocument
loadDocument
(InputStream inputStream, Map<String, Object> configuration, Boolean enableCollaboration) Creates an OdfTextDocument from the OpenDocument provided by a resource Stream.static OdfTextDocument
loadDocument
(String documentPath) Loads an OdfTextDocument from the provided path.Creates a new paragraphnewParagraph
(String text) Creates a new paragraph and append textstatic OdfTextDocument
Creates an empty text document.static OdfTextDocument
newTextDocument
(Boolean enableCollaboration) Creates an empty text document.static OdfTextDocument
newTextDocument
(OdfTextDocument.OdfMediaType mimeType) Creates an empty text document.static OdfTextDocument
Creates an empty text master document.static OdfTextDocument
Creates an empty text master document.static OdfTextDocument
Creates an empty text template.static OdfTextDocument
Creates an empty text web.Methods inherited from class org.odftoolkit.odfdom.doc.OdfDocument
addAnnotation, close, getAnnotation, getFontNames, getLocale, getOdfMediaType, getOfficeMetadata, getSelectionManager, getTableByName, getTableList, getTableList, getUnicodeGroup, getUniqueAnnotationName, hasCollaboration, loadDocument, loadDocument, loadDocument, loadDocument, loadSubDocument, loadSubDocuments, loadSubDocuments, loadTemplate, loadTemplate, newImage, removeAnnotation, removeCachedView, save, save, setLocale, setOdfMediaType, toString, updateMetaData
Methods inherited from class org.odftoolkit.odfdom.dom.OdfSchemaDocument
getBaseURI, getBookmarkRDFMetadata, getContentDom, getContentStream, getDocumentStyles, getFileDom, getInContentMetadata, getInContentMetadataFromCache, getJsonOperationQueue, getManifestRDFMetadata, getMasterPages, getMetaDom, getMetaStream, getOfficeMasterStyles, getOperations, getOrCreateDocumentStyles, getRDFMetadata, getRootComponent, getRootComponentElement, getSettingsDom, getSettingsStream, getStyleByDisplayName, getStyleByName, getStylesDom, getStylesStream, getTables, getTables, getXMLFilePath, setContentDom, setJsonOperationQueue, setMetaDom, setRootComponent, setSettingsDom, setStylesDom
Methods inherited from class org.odftoolkit.odfdom.pkg.OdfPackageDocument
flushDoms, getAbsoluteFilePath, getCachedDom, getDocumentPath, getFileDom, getMediaTypeString, getPackage, getXMLFileMetadata, insertDocument, isExternalReference, isRootDocument, normalizeDocumentPath, removeDocument, save, setMediaTypeString
-
Constructor Details
-
OdfTextDocument
protected OdfTextDocument(OdfPackage pkg, String internalPath, OdfTextDocument.OdfMediaType odfMediaType, Boolean enableCollaboration) throws SAXException To avoid data duplication a new document is only created, if not already opened. A document is cached by this constructor using the internal path as key.- Throws:
SAXException
-
OdfTextDocument
protected OdfTextDocument(OdfPackage pkg, String internalPath, OdfTextDocument.OdfMediaType odfMediaType) throws SAXException To avoid data duplication a new document is only created, if not already opened. A document is cached by this constructor using the internal path as key.- Throws:
SAXException
-
-
Method Details
-
newTextDocument
Creates an empty text document.- Returns:
- ODF text document based on a default template
- Throws:
Exception
- - if the document could not be created
-
newTextDocument
Creates an empty text document.- Parameters:
enableCollaboration
- - user changes equivalent for creating this document are gathered- Returns:
- ODF text document based on a default template
- Throws:
Exception
- - if the document could not be created
-
newTextDocument
public static OdfTextDocument newTextDocument(OdfTextDocument.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
Creates an empty text template.- Returns:
- ODF text template based on a default
- Throws:
Exception
- - if the template could not be created
-
newTextMasterDocument
Creates an empty text master document.- Returns:
- ODF text master based on a default
- Throws:
Exception
- - if the document could not be created
-
newTextMasterTemplateDocument
Creates an empty text master document.- Returns:
- ODF text master based on a default
- Throws:
Exception
- - if the document could not be created
-
newTextWebDocument
Creates an empty text web.- Returns:
- ODF text web based on a default
- Throws:
Exception
- - if the document could not be created
-
loadDocument
Creates an OdfTextDocument from the OpenDocument provided by a resource Stream.Since an InputStream does not provide the arbitrary (non sequential) read access needed by OdfTextDocument, 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 OdfTextDocument loadDocument(InputStream inputStream, Boolean enableCollaboration) throws Exception Creates an OdfTextDocument from the OpenDocument provided by a resource Stream.Since an InputStream does not provide the arbitrary (non sequential) read access needed by OdfTextDocument, 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.enableCollaboration
- - user changes equivalent for creating this document are gathered- Returns:
- the text document created from the given InputStream
- Throws:
Exception
- - if the document could not be created.
-
loadDocument
public static OdfTextDocument loadDocument(InputStream inputStream, Map<String, Object> configuration) throws ExceptionCreates an OdfTextDocument from the OpenDocument provided by a resource Stream.Since an InputStream does not provide the arbitrary (non sequential) read access needed by OdfTextDocument, 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.configuration
- - key/value pairs of user given run-time settings (configuration)- Returns:
- the text document created from the given InputStream
- Throws:
Exception
- - if the document could not be created.
-
loadDocument
public static OdfTextDocument loadDocument(InputStream inputStream, Map<String, Object> configuration, Boolean enableCollaboration) throws ExceptionCreates an OdfTextDocument from the OpenDocument provided by a resource Stream.Since an InputStream does not provide the arbitrary (non sequential) read access needed by OdfTextDocument, 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.configuration
- - key/value pairs of user given run-time settings (configuration)enableCollaboration
- - user changes equivalent for creating this document are gathered- Returns:
- the text document created from the given InputStream
- Throws:
Exception
- - if the document could not be created.
-
loadDocument
Loads an OdfTextDocument from the provided path.OdfTextDocument relies on the file being available for read access over the whole life-cycle of OdfTextDocument.
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 ODFDOM.
- Throws:
Exception
- - if the document could not be created.
-
loadDocument
Creates an OdfTextDocument from the OpenDocument provided by a File.OdfTextDocument relies on the file being available for read access over the whole lifecycle of OdfTextDocument.
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
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 classOdfDocument
- Returns:
- content root, representing the office:text tag
- Throws:
Exception
- if the file DOM could not be created.
-
newParagraph
Creates a new paragraph and append text- Parameters:
text
-- Returns:
- the new paragraph
- Throws:
Exception
- if the file DOM could not be created.
-
newParagraph
Creates a new paragraph- Returns:
- The new paragraph
- Throws:
Exception
- if the file DOM could not be created.
-
addText
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
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
-
hasTabsRelativeToIndent
In LO/AO Tabs are counted from the start of text and the fo:left-margin have to be added. Microsoft Office does not behave this way. For the filter a compatibility flag was added to the settings.xml <config:config-item config:name="TabsRelativeToIndent" config:type="boolean">false</config:config-item>
-