Class OdfPresentationDocument

    • 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.
      • 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 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 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 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​(OdfPresentationDocument srcDoc)
        Append all the slides of the specified presentation document to the current document.
        Parameters:
        srcDoc - the specified OdfPresentationDocument 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 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.

      • 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 copied
        dom - The specified DOM tree that the returned element belong to
        deep - 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. 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.