public abstract class Document extends OdfSchemaDocument implements TableContainer
Modifier and Type | Class and Description |
---|---|
static class |
Document.OdfMediaType
This enum contains all possible media types of Document documents.
|
static class |
Document.ScriptType
Unicode characters are in general divided by office applications into three different types:
|
OdfSchemaDocument.OdfXMLFile
OdfPackageDocument.Resource
Modifier and Type | Field and Description |
---|---|
SelectionManager |
selectionManager |
mContentDom, mDocumentStyles, mMetaDom, mSettingsDom, mStylesDom
mDocumentMediaType, mDocumentPathInPackage, mPackage, ROOT_DOCUMENT_PATH
Modifier | Constructor and Description |
---|---|
protected |
Document(OdfPackage pkg,
String internalPath,
Document.OdfMediaType mediaType) |
Modifier and Type | Method and Description |
---|---|
Table |
addTable()
Add a new Table to this container.
|
Table |
addTable(int numRows,
int numCols)
Add a new Table to this container with a specified row number and column number.
|
void |
close()
Close the OdfPackage and release all temporary created data.
|
protected IdentityHashMap<OdfElement,Component> |
getComponentMap()
Return the component repository of this document.
|
OdfElement |
getContentRoot()
Get the content root of a document.
|
protected <T extends OdfElement> |
getContentRoot(Class<T> clazz)
Get the content root of a document.
|
Document |
getEmbeddedDocument(String documentPath)
Returns an embedded OdfPackageDocument from the given package path.
|
List<Document> |
getEmbeddedDocuments()
Method returns all embedded OdfPackageDocuments, which match a valid OdfMediaType, of the root
OdfPackageDocument.
|
List<Document> |
getEmbeddedDocuments(Document.OdfMediaType mediaType)
Method returns all embedded OdfPackageDocuments of the root OdfPackageDocument matching the
according MediaType.
|
Locale |
getLocale(Document.ScriptType scriptType)
Get a locale information of a specific script type.
|
protected Document.OdfMediaType |
getOdfMediaType()
Gets the media type of the Document
|
Meta |
getOfficeMetadata()
Get the meta data feature instance of the current document
|
static Document.ScriptType |
getScriptType(Locale locale) |
Section |
getSectionByName(String name)
This method will search both the document content and header/footer, return a section with a
specific name.
|
Iterator<Section> |
getSectionIterator()
This method will search both the document content and header/footer, return an iterator of
section objects.
|
SelectionManager |
getSelectionManager() |
Table.TableBuilder |
getTableBuilder()
Return the table builder of this document.
|
Table |
getTableByName(String name)
Return an instance of table feature with the specific table name.
|
protected TableContainer |
getTableContainerImpl() |
List<Table> |
getTableList()
Return a list of table features in this document.
|
void |
insertDocument(OdfPackageDocument sourceDocument,
String documentPath)
Embed an OdfPackageDocument to the current OdfPackageDocument.
|
static Document |
loadDocument(File file)
Creates a Document from the Document provided by a File.
|
static Document |
loadDocument(File file,
String password)
Creates a Document from the Document provided by a File.
|
static Document |
loadDocument(InputStream inStream)
Creates a Document from the Document provided by a resource Stream.
|
static Document |
loadDocument(OdfPackage odfPackage)
Creates a Document from the Document provided by an ODF package.
|
static Document |
loadDocument(OdfPackage odfPackage,
String internalPath)
Creates a Document from the Document provided by an ODF package.
|
static Document |
loadDocument(String documentPath)
Loads a Document from the provided path.
|
static Document |
loadDocument(String documentPath,
String password)
Loads a Document from the provided path.
|
TableTemplate |
LoadTableTemplateFromForeignTable(InputStream templateFileInputStream,
String tableName)
Construct a
TableTemplate |
protected static Document |
loadTemplate(OdfPackageDocument.Resource res,
Document.OdfMediaType odfMediaType)
Loads an Document from the given resource.
|
String |
newImage(URI imageUri)
Insert an Image from the specified uri to the end of the Document.
|
boolean |
removeElementLinkedResource(OdfElement odfElement)
Remove an ODF element from the document.
|
void |
save(File file)
Save the document to a given file.
|
void |
save(File file,
String password)
Save the document to a given file with given password.
|
void |
save(OutputStream out)
Save the document to an OutputStream.
|
void |
setLocale(Locale locale)
Set a locale information.
|
void |
setLocale(Locale locale,
Document.ScriptType scriptType)
Set a locale of a specific script type.
|
protected void |
setOdfMediaType(Document.OdfMediaType odfMediaType)
Sets the media type of the Document
|
void |
setPassword(String password)
Sets password of this document.
|
void |
setSelectionManager(SelectionManager selectionManager) |
String |
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getTableContainerElement
public SelectionManager selectionManager
protected Document(OdfPackage pkg, String internalPath, Document.OdfMediaType mediaType)
protected static Document loadTemplate(OdfPackageDocument.Resource res, Document.OdfMediaType odfMediaType) throws Exception
res
- a resource containing a package with a root documentodfMediaType
- the media type of the root documentException
- - if the document could not be created.public static Document loadDocument(String documentPath, String password) throws Exception
Document relies on the file being available for read access over the whole life cycle of Document.
documentPath
- - the path from where the document can be loadedpassword
- - file password.Exception
- - if the document could not be created.public static Document loadDocument(String documentPath) throws Exception
Document relies on the file being available for read access over the whole life cycle of Document.
documentPath
- - the path from where the document can be loadedException
- - if the document could not be created.public static Document loadDocument(InputStream inStream) throws Exception
Since an InputStream does not provide the arbitrary (non sequentiell) read access needed by Document, 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.
inStream
- - the InputStream of the ODF document.Exception
- - if the document could not be created.public static Document loadDocument(File file) throws Exception
Document relies on the file being available for read access over the whole lifecycle of Document.
file
- - a file representing the ODF document.Exception
- - if the document could not be created.public static Document loadDocument(File file, String password) throws Exception
Document relies on the file being available for read access over the whole lifecycle of Document.
file
- - a file representing the ODF document.password
- - file password.Exception
- - if the document could not be created.public static Document loadDocument(OdfPackage odfPackage) throws Exception
odfPackage
- - the ODF package containing the ODF document.Exception
- - if the ODF document could not be created.public static Document loadDocument(OdfPackage odfPackage, String internalPath) throws Exception
odfPackage
- - the ODF package containing the ODF document.internalPath
- - the path to the ODF document relative to the package root.Exception
- - if the ODF document could not be created.public void setPassword(String password)
password
- the password of this document.public Document getEmbeddedDocument(String documentPath)
documentPath
- path to the ODF document within the package. The path is relative to the
current document.public List<Document> getEmbeddedDocuments()
public List<Document> getEmbeddedDocuments(Document.OdfMediaType mediaType)
mediaType
- media type which is used as a filterpublic void insertDocument(OdfPackageDocument sourceDocument, String documentPath)
insertDocument
in class OdfPackageDocument
documentPath
- to the directory the ODF document should be inserted (relative to the
current document).sourceDocument
- the OdfPackageDocument to be embedded.protected void setOdfMediaType(Document.OdfMediaType odfMediaType)
odfMediaType
- media type to be setprotected Document.OdfMediaType getOdfMediaType()
public Meta getOfficeMetadata()
office:meta
in the meta.xmlpublic void save(OutputStream out) throws Exception
If the input file has been cached (this is the case when loading from an InputStream), the input file can be overwritten.
If not, the OutputStream may not point to the input file! Otherwise this will result in unwanted behaviour and broken files.
When save the embedded document to a stand alone document, all the file entries of the embedded document will be copied to a new document package. If the embedded document is outside of the current document directory, you have to embed it to the sub directory and refresh the link of the embedded document. you should reload it from the stream to get the saved embedded document.
out
- - the OutputStream to write the file toException
- if the document could not be savedpublic void save(File file) throws Exception
If the input file has been cached (this is the case when loading from an InputStream), the input file can be overwritten.
Otherwise it's allowed to overwrite the input file as long as the same path name is used that was used for loading (no symbolic link foo2.odt pointing to the loaded file foo1.odt, no network path X:\foo.odt pointing to the loaded file D:\foo.odt).
When saving the embedded document to a stand alone document, all files of the embedded document will be copied to a new document package. If the embedded document is outside of the current document directory, you have to embed it to the sub directory and refresh the link of the embedded document. You should reload it from the given file to get the saved embedded document.
save
in class OdfPackageDocument
file
- - the file to save the documentException
- if the document could not be savedpublic void save(File file, String password) throws Exception
If the input file has been cached (this is the case when loading from an InputStream), the input file can be overwritten.
Otherwise it's allowed to overwrite the input file as long as the same path name is used that was used for loading (no symbolic link foo2.odt pointing to the loaded file foo1.odt, no network path X:\foo.odt pointing to the loaded file D:\foo.odt).
When saving the embedded document to a stand alone document, all files of the embedded document will be copied to a new document package. If the embedded document is outside of the current document directory, you have to embed it to the sub directory and refresh the link of the embedded document. You should reload it from the given file to get the saved embedded document.
file
- the file to save the document.file
- the password of this document.Exception
- if the document could not be savedpublic void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class OdfSchemaDocument
protected <T extends OdfElement> T getContentRoot(Class<T> clazz) throws Exception
You may prefer to use the getContentRoot methods of subclasses of Document. Their return parameters are already casted to respective subclasses of OdfElement.
clazz
- the type of the content root, depend on the document typeException
- if the file DOM could not be created.public OdfElement getContentRoot() throws Exception
You may prefer to use the getContentRoot methods of subclasses of Document.
Exception
- if the file DOM could not be created.public String newImage(URI imageUri)
imageUri
- The URI of the image that will be added to the document, add image stream to
the package, in the 'Pictures/' graphic directory with the same image file name as in the
URI. If the imageURI is relative first the user.dir is taken to make it absolute.public void setLocale(Locale locale)
The locale information will affect the language and country setting of the document. Thus the font settings, the spell checkings and etc will be affected.
locale
- - an instance of Localepublic static Document.ScriptType getScriptType(Locale locale)
public void setLocale(Locale locale, Document.ScriptType scriptType)
If the locale is not belone to the script type, nothing will happen.
locale
- - Locale informationscriptType
- - The script typepublic Locale getLocale(Document.ScriptType scriptType)
scriptType
- - The script typepublic Iterator<Section> getSectionIterator()
The sections defined in embed document won't be covered.
public Section getSectionByName(String name)
This method won't search in the embed document.
Null will be returned if there is no section found.
name
- - the name of a sectionpublic boolean removeElementLinkedResource(OdfElement odfElement)
odfElement
- - the odf element that would be moved.public Table addTable()
TableContainer
addTable
in interface TableContainer
public Table addTable(int numRows, int numCols)
TableContainer
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.
addTable
in interface TableContainer
numRows
- the row numbernumCols
- the column numberTable
public Table getTableByName(String name)
TableContainer
getTableByName
in interface TableContainer
name
- of the table being searched for.public List<Table> getTableList()
TableContainer
getTableList
in interface TableContainer
public Table.TableBuilder getTableBuilder()
TableContainer
getTableBuilder
in interface TableContainer
protected TableContainer getTableContainerImpl()
protected IdentityHashMap<OdfElement,Component> getComponentMap()
public TableTemplate LoadTableTemplateFromForeignTable(InputStream templateFileInputStream, String tableName) throws Exception
TableTemplate feature by extracting style template from an pre-defined table in a foreign document. The styles loaded by the template will be copied into the document as well and can be referenced by table directly.
The imported table need to be at least a 5*5 table (e.g. A1E5). Each type
of style in the template will be set according to the style reference in
a specific table cell, as following:
first column - A2
last column - E2
first row - A2
last row - E2
even rows - B3
odd rows - B2
even columns - C2
odd columns - B2
body - B2
first-row-start-column -A1
first-row-end-column -E1
last-row-start-column -A5
last-row-end-column -E5
templateFileInputStream
- - the InputStream of the ODF document.tableName
- - the table name which will be used to load styles as
templateException
- - if content DOM could not be initializedpublic SelectionManager getSelectionManager()
public void setSelectionManager(SelectionManager selectionManager)
Copyright © 2010–2018 Apache Software Foundation; Copyright © 2018–2020 The Document Foundation. All rights reserved.