org.odftoolkit.simple
Class PresentationDocument

java.lang.Object
  extended by org.odftoolkit.odfdom.pkg.OdfPackageDocument
      extended by org.odftoolkit.odfdom.dom.OdfSchemaDocument
          extended by org.odftoolkit.simple.Document
              extended by org.odftoolkit.simple.PresentationDocument
All Implemented Interfaces:
Closeable, ChartContainer, TableContainer

public class PresentationDocument
extends Document
implements ChartContainer

This class represents an empty ODF presentation.


Nested Class Summary
static class PresentationDocument.OdfMediaType
          This enum contains all possible media types of PresentationDocument documents.
static class PresentationDocument.PresentationClass
          It represents the defined values of presentation:class.
 
Nested classes/interfaces inherited from class org.odftoolkit.simple.Document
Document.ScriptType
 
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.dom.OdfSchemaDocument
mContentDom, mDocumentStyles, mMetaDom, mSettingsDom, mStylesDom
 
Fields inherited from class org.odftoolkit.odfdom.pkg.OdfPackageDocument
mDocumentMediaType, mDocumentPathInPackage, mPackage, ROOT_DOCUMENT_PATH
 
Constructor Summary
protected PresentationDocument(OdfPackage pkg, String internalPath, PresentationDocument.OdfMediaType odfMediaType)
          To avoid data duplication a new document is only created, if not already opened.
 
Method Summary
 void appendPresentation(PresentationDocument srcDoc)
          Append all the slides of the specified presentation document to the current document.
 void changeMode(PresentationDocument.OdfMediaType type)
          Switches this instance to the given type.
 Slide copyForeignSlide(int destIndex, PresentationDocument 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.
 Slide copySlide(int source, int dest, String newName)
          Make a copy of the slide at a specified position to another position in this presentation.
 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.
 void deleteChartById(String chartId)
          Deletes chart by chart id.
 void deleteChartByTitle(String title)
          Deletes chart(s) by chart title.
 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.
 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
 OfficePresentationElement getContentRoot()
          Get the content root of a presentation document.
 Notes.NotesBuilder getNotesBuilder()
          Return the notes builder of this document.
 Slide.SlideBuilder getSlideBuilder()
          Return the slide builder of this document.
 Slide getSlideByIndex(int index)
          Return the slide at a specified position in this presentation.
 Slide 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<Slide> getSlides()
          Return a list iterator containing all slides in this presentation.
 OdfElement getTableContainerElement()
          Get the ODF element which can have as child element directly according to ODF specification.
static PresentationDocument loadDocument(File file)
          Creates an PresentationDocument from the OpenDocument provided by a File.
static PresentationDocument loadDocument(InputStream inputStream)
          Creates an PresentationDocument from the OpenDocument provided by a resource Stream.
static PresentationDocument loadDocument(String documentPath)
          Loads an PresentationDocument from the provided path.
 void moveSlide(int source, int dest)
          Move the slide at a specified position to the destination position.
static PresentationDocument newPresentationDocument()
          Creates an empty presentation document.
static PresentationDocument newPresentationTemplateDocument()
          Creates an empty presentation template.
 Slide newSlide(int index, String name, Slide.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.simple.Document
addTable, addTable, close, getComponentMap, getContentRoot, getEmbeddedDocument, getEmbeddedDocuments, getEmbeddedDocuments, getLocale, getOdfMediaType, getOfficeMetadata, getScriptType, getSectionByName, getSectionIterator, getTableBuilder, getTableByName, getTableContainerImpl, getTableList, insertDocument, loadDocument, loadDocument, loadTemplate, newImage, removeElementLinkedResource, save, save, setLocale, setLocale, setOdfMediaType, toString
 
Methods inherited from class org.odftoolkit.odfdom.dom.OdfSchemaDocument
getBaseURI, getContentDom, getContentStream, getDocumentStyles, getFileDom, getMasterPages, getMetaDom, getMetaStream, getOfficeMasterStyles, getOrCreateDocumentStyles, getSettingsDom, getSettingsStream, getStylesDom, getStylesStream, getTables, getXMLFilePath
 
Methods inherited from class org.odftoolkit.odfdom.pkg.OdfPackageDocument
flushDoms, getDocumentPath, getFileDom, getMediaTypeString, getPackage, isExternalReference, isRootDocument, loadSubDocument, normalizeDocumentPath, removeDocument, save, setMediaTypeString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PresentationDocument

protected PresentationDocument(OdfPackage pkg,
                               String internalPath,
                               PresentationDocument.OdfMediaType odfMediaType)
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.

Method Detail

newPresentationDocument

public static PresentationDocument 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 PresentationDocument 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 PresentationDocument loadDocument(InputStream inputStream)
                                         throws Exception
Creates an PresentationDocument from the OpenDocument provided by a resource Stream.

Since an InputStream does not provide the arbitrary (non sequentiell) read access needed by PresentationDocument, 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 PresentationDocument loadDocument(String documentPath)
                                         throws Exception
Loads an PresentationDocument from the provided path.

PresentationDocument relies on the file being available for read access over the whole lifecycle of PresentationDocument.

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 SIMPLE.
Throws:
Exception - - if the document could not be created.

loadDocument

public static PresentationDocument loadDocument(File file)
                                         throws Exception
Creates an PresentationDocument from the OpenDocument provided by a File.

PresentationDocument relies on the file being available for read access over the whole lifecycle of PresentationDocument.

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 class Document
Returns:
content root, representing the office:presentation tag
Throws:
Exception - if the file DOM could not be created.

changeMode

public void changeMode(PresentationDocument.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.

getSlideBuilder

public Slide.SlideBuilder getSlideBuilder()
Return the slide builder of this document. Every presentation document has a slide builder.

Returns:
the slide builder of this document.
Since:
0.3.5

getNotesBuilder

public Notes.NotesBuilder getNotesBuilder()
Return the notes builder of this document. Every presentation document has a notes builder.

Returns:
the notes builder of this document.
Since:
0.3.5

getSlideByIndex

public Slide 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 Slide 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<Slide> 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 delete

Throw 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 Slide 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 copied
dest - the destination position of the slide need to be copied
newName - 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 moved
dest - The index of the destination position before the move action

Throw IndexOutOfBoundsException if the slide index is out of the presentation document slide count.


appendPresentation

public void appendPresentation(PresentationDocument srcDoc)
Append all the slides of the specified presentation document to the current document.

Parameters:
srcDoc - the specified PresentationDocument that need to be appended

copyForeignSlide

public Slide copyForeignSlide(int destIndex,
                              PresentationDocument 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 document
srcDoc - the source document of the copied slide
srcIndex - 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.


newSlide

public Slide newSlide(int index,
                      String name,
                      Slide.SlideLayout slideLayout)
New a slide at the specified position with the specified name, and use the specified slide template. See OdfDrawPage.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 position
name - the new slide name
slideLayout - 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.


createChart

public Chart createChart(String title,
                         DataSet dataset,
                         Rectangle rect)
Description copied from interface: ChartContainer
Creates a new Chart for this container.

Specified by:
createChart in interface ChartContainer
Parameters:
title - chart title.
dataset - chart data set.
rect - chart rectangle.
Returns:
the created chart.

createChart

public Chart createChart(String title,
                         SpreadsheetDocument document,
                         CellRangeAddressList cellRangeAddr,
                         boolean firstRowAsLabel,
                         boolean firstColumnAsLabel,
                         boolean rowAsDataSeries,
                         Rectangle rect)
Description copied from interface: ChartContainer
Creates a new Chart for this container.

Specified by:
createChart in interface ChartContainer
Parameters:
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.
Returns:
the created chart.

createChart

public Chart createChart(String title,
                         String[] labels,
                         String[] legends,
                         double[][] data,
                         Rectangle rect)
Description copied from interface: ChartContainer
Creates a new Chart for this container.

Specified by:
createChart in interface ChartContainer
Parameters:
title - chart rectangle.
labels - label strings
legends - legend strings
data - chart data set.
rect - chart rectangle.
Returns:
the created chart.

deleteChartById

public void deleteChartById(String chartId)
Description copied from interface: ChartContainer
Deletes chart by chart id.

Specified by:
deleteChartById in interface ChartContainer
Parameters:
chartId - the id of specified chart.

deleteChartByTitle

public void deleteChartByTitle(String title)
Description copied from interface: ChartContainer
Deletes chart(s) by chart title.

Specified by:
deleteChartByTitle in interface ChartContainer
Parameters:
title - the title of specified chart(s).

getChartById

public Chart getChartById(String chartId)
Description copied from interface: ChartContainer
Gets chart with specified id.

Specified by:
getChartById in interface ChartContainer
Parameters:
chartId - the id of this chart.
Returns:
the chart with specified id.

getChartByTitle

public List<Chart> getChartByTitle(String title)
Description copied from interface: ChartContainer
Gets chart list with specified title.

Specified by:
getChartByTitle in interface ChartContainer
Parameters:
title - the title of specified chart(s).
Returns:
the chart(s) with specified title.

getChartCount

public int getChartCount()
Description copied from interface: ChartContainer
Returns the chart count of this container

Specified by:
getChartCount in interface ChartContainer
Returns:
the chart count of this container

getTableContainerElement

public OdfElement getTableContainerElement()
Description copied from interface: TableContainer
Get the ODF element which can have as child element directly according to ODF specification. This Element will help to find the position to insert a new Table. For example, element is usable with element, so TextDocument will return OfficeTextElement. While Presentation Notes is an indirectly TableContainer, which holds Table with the help of its grand-child element , so for Notes, DrawTextBoxElement should be return.

Specified by:
getTableContainerElement in interface TableContainer
Returns:
container element which can hold .


Copyright © 2010-2011 The Apache Software Foundation. All Rights Reserved.