Class OdfPresentationDocument
- java.lang.Object
-
- org.odftoolkit.odfdom.pkg.OdfPackageDocument
-
- org.odftoolkit.odfdom.dom.OdfSchemaDocument
-
- org.odftoolkit.odfdom.doc.OdfDocument
-
- org.odftoolkit.odfdom.doc.OdfPresentationDocument
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class OdfPresentationDocument extends OdfDocument
This class represents an empty ODF presentation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OdfPresentationDocument.OdfMediaType
This enum contains all possible media types of OdfPresentationDocument 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
Constructors Modifier Constructor Description protected
OdfPresentationDocument(OdfPackage pkg, String internalPath, OdfPresentationDocument.OdfMediaType odfMediaType)
To avoid data duplication a new document is only created, if not already opened.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendPresentation(OdfPresentationDocument srcDoc)
Append all the slides of the specified presentation document to the current document.void
changeMode(OdfPresentationDocument.OdfMediaType type)
Switches this instance to the given type.Node
cloneForeignElement(Node element, OdfFileDom dom, boolean deep)
Make a content copy of the specified element, and the returned element should have the specified ownerDocument.OdfSlide
copyForeignSlide(int destIndex, OdfPresentationDocument srcDoc, int srcIndex)
Make a copy of slide which locates at the specified position of the source presentation document and insert it to the current presentation document at the new position.OdfSlide
copySlide(int source, int dest, String newName)
Make a copy of the slide at a specified position to another position in this presentation.boolean
deleteSlideByIndex(int index)
Delete the slide at a specified position in this presentation.boolean
deleteSlideByName(String name)
Delete all the slides with a specified name in this presentation.OfficePresentationElement
getContentRoot()
Get the content root of a presentation document.OdfSlide
getSlideByIndex(int index)
Return the slide at a specified position in this presentation.OdfSlide
getSlideByName(String name)
Return the slide which have a specified slide name in this presentation.int
getSlideCount()
Get the number of the slides in this presentation.Iterator<OdfSlide>
getSlides()
Return a list iterator containing all slides in this presentation.static OdfPresentationDocument
loadDocument(File file)
Creates an OdfPresentationDocument from the OpenDocument provided by a File.static OdfPresentationDocument
loadDocument(InputStream inputStream)
Creates an OdfPresentationDocument from the OpenDocument provided by a resource Stream.static OdfPresentationDocument
loadDocument(String documentPath)
Loads an OdfPresentationDocument from the provided path.void
moveSlide(int source, int dest)
Move the slide at a specified position to the destination position.static OdfPresentationDocument
newPresentationDocument()
Creates an empty presentation document.static OdfPresentationDocument
newPresentationTemplateDocument()
Creates an empty presentation template.OdfSlide
newSlide(int index, String name, OdfSlide.SlideLayout slideLayout)
New a slide at the specified position with the specified name, and use the specified slide template.-
Methods inherited from class org.odftoolkit.odfdom.doc.OdfDocument
addAnnotation, close, getAnnotation, getFontNames, getLocale, getOdfMediaType, getOfficeMetadata, getTableByName, getTableList, getTableList, getUnicodeGroup, getUniqueAnnotationName, hasCollaboration, loadDocument, loadDocument, loadDocument, 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 Detail
-
OdfPresentationDocument
protected OdfPresentationDocument(OdfPackage pkg, String internalPath, OdfPresentationDocument.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 internalpath as key.- Throws:
SAXException
-
-
Method Detail
-
newPresentationDocument
public static OdfPresentationDocument newPresentationDocument() throws Exception
Creates an empty presentation document.- Returns:
- ODF presentation document based on a default template
- Throws:
Exception
- - if the document could not be created
-
newPresentationTemplateDocument
public static OdfPresentationDocument newPresentationTemplateDocument() throws Exception
Creates an empty presentation template.- Returns:
- ODF presentation template based on a default
- Throws:
Exception
- - if the template could not be created
-
loadDocument
public static OdfPresentationDocument loadDocument(InputStream inputStream) throws Exception
Creates an OdfPresentationDocument from the OpenDocument provided by a resource Stream.Since an InputStream does not provide the arbitrary (non sequentiell) read access needed by OdfPresentationDocument, 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 presentation document, ClassCastException might be thrown.
- Parameters:
inputStream
- - the InputStream of the ODF presentation document.- Returns:
- the presentation document created from the given InputStream
- Throws:
Exception
- - if the document could not be created.
-
loadDocument
public static OdfPresentationDocument loadDocument(String documentPath) throws Exception
Loads an OdfPresentationDocument from the provided path.OdfPresentationDocument relies on the file being available for read access over the whole lifecycle of OdfPresentationDocument.
If the resource stream is not a ODF presentation document, ClassCastException might be thrown.
- Parameters:
documentPath
- - the path from where the document can be loaded- Returns:
- the presentation 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
public static OdfPresentationDocument loadDocument(File file) throws Exception
Creates an OdfPresentationDocument from the OpenDocument provided by a File.OdfPresentationDocument relies on the file being available for read access over the whole lifecycle of OdfPresentationDocument.
If the resource stream is not a ODF presentation document, ClassCastException might be thrown.
- Parameters:
file
- - a file representing the ODF presentation document.- Returns:
- the presentation document created from the given File
- Throws:
Exception
- - if the document could not be created.
-
getContentRoot
public OfficePresentationElement getContentRoot() throws Exception
Get the content root of a presentation document.- Overrides:
getContentRoot
in classOdfDocument
- Returns:
- content root, representing the office:presentation tag
- Throws:
Exception
- if the file DOM could not be created.
-
changeMode
public void changeMode(OdfPresentationDocument.OdfMediaType type)
Switches this instance to the given type. This method can be used to e.g. convert a document instance to a template and vice versa. Changes take affect in the package when saving the document.- Parameters:
type
- the compatible ODF mediatype.
-
getSlideByIndex
public OdfSlide getSlideByIndex(int index)
Return the slide at a specified position in this presentation. Return null if the index is out of range.- Parameters:
index
- the index of the slide to be returned- Returns:
- a draw slide at the specified position
-
getSlideCount
public int getSlideCount()
Get the number of the slides in this presentation.- Returns:
- the number of slides
-
getSlideByName
public OdfSlide getSlideByName(String name)
Return the slide which have a specified slide name in this presentation.According to the odf specification "The draw:name attribute specifies a name by which this element can be referenced. It is optional but if present, must be unique within the document instance. If not present, an application may generate a unique name."
If the name is null, then return null because all the slide must has its own unique name.
- Parameters:
name
- the specified slide name- Returns:
- the slide whose name equals to the specified name
-
getSlides
public Iterator<OdfSlide> getSlides()
Return a list iterator containing all slides in this presentation.- Returns:
- a list iterator containing all slides in this presentation
-
deleteSlideByIndex
public boolean deleteSlideByIndex(int index)
Delete the slide at a specified position in this presentation.- Parameters:
index
- the index of the slide that need to be deleteThrow IndexOutOfBoundsException if the slide index is out of the presentation document slide count.
- Returns:
- false if the operation was not successful
-
deleteSlideByName
public boolean deleteSlideByName(String name)
Delete all the slides with a specified name in this presentation.- Parameters:
name
- the name of the slide that need to be delete- Returns:
- false if the operation was not successful
-
copySlide
public OdfSlide copySlide(int source, int dest, String newName)
Make a copy of the slide at a specified position to another position in this presentation. The original slide which at the dest index and after the dest index will move after.- Parameters:
source
- the source position of the slide need to be copieddest
- the destination position of the slide need to be copiednewName
- the new name of the copied slide- Returns:
- the new slide at the destination position with the specified name, and it has the same
content with the slide at the source position.
Throw IndexOutOfBoundsException if the slide index is out of the presentation document slide count. If copy the slide at the end of document, destIndex should set the same value with the slide count.
-
moveSlide
public void moveSlide(int source, int dest)
Move the slide at a specified position to the destination position.- Parameters:
source
- the current index of the slide that need to be moveddest
- The index of the destination position before the move actionThrow IndexOutOfBoundsException if the slide index is out of the presentation document slide count.
-
appendPresentation
public void appendPresentation(OdfPresentationDocument srcDoc)
Append all the slides of the specified presentation document to the current document.- Parameters:
srcDoc
- the specifiedOdfPresentationDocument
that need to be appended
-
copyForeignSlide
public OdfSlide copyForeignSlide(int destIndex, OdfPresentationDocument srcDoc, int srcIndex)
Make a copy of slide which locates at the specified position of the source presentation document and insert it to the current presentation document at the new position. The original slide which at the dest index and after the dest index will move after.- Parameters:
destIndex
- the new position of the copied slide in the current documentsrcDoc
- the source document of the copied slidesrcIndex
- the slide index of the source document that need to be copied- Returns:
- the new slide which has the same content with the source slide
Throw IndexOutOfBoundsException if the slide index is out of the presentation document slide count If insert the foreign slide at the end of document, destIndex should set the same value with the slide count of the current presentation document.
-
cloneForeignElement
public Node cloneForeignElement(Node element, OdfFileDom dom, boolean deep)
Make a content copy of the specified element, and the returned element should have the specified ownerDocument.- Parameters:
element
- The element that need to be copieddom
- The specified DOM tree that the returned element belong todeep
- If true, recursively clone the subtree under the element, false, only clone the element itself- Returns:
- Returns a duplicated element which is not in the DOM tree with the specified element
-
newSlide
public OdfSlide newSlide(int index, String name, OdfSlide.SlideLayout slideLayout)
New a slide at the specified position with the specified name, and use the specified slide template. SeeOdfDrawPage.SlideLayout
.If index is invalid, such as larger than the current document slide number or is negative, then append the new slide at the end of the document.
The slide name can be null.
- Parameters:
index
- the new slide positionname
- the new slide nameslideLayout
- the new slide template- Returns:
- the new slide which locate at the specified position with the specified name and apply
the specified slide template. If slideLayout is null, then use the default slide template
which is a blank slide.
Throw IndexOutOfBoundsException if index is out of the presentation document slide count.
-
-