Class OdfDrawImage

All Implemented Interfaces:
Serializable, Cloneable, Element, ElementTraversal, EventTarget, Node, NodeList, TypeInfo

public class OdfDrawImage extends DrawImageElement
Convenient functionality for the parent ODF OpenDocument element
See Also:
  • Constructor Details

    • OdfDrawImage

      public OdfDrawImage(OdfFileDom ownerDoc)
      Creates a new instance of this class
      Parameters:
      ownerDoc - The XML DOM containing the draw:image element
  • Method Details

    • getImageUri

      public URI getImageUri()
      Return the URI for this image
      Returns:
      the URI of image
    • setImagePath

      public void setImagePath(String packagePath)
      The image path will be stored as URI of the href attribute
      Parameters:
      packagePath - The relative path from the package root to the image
    • newImage

      public String newImage(URI imageUri) throws Exception
      Inserts the image file from the URI to the ODF package named similar as in the URI. The manifest is adapted using the media type according to the suffix. Existing images are replaced. Note: Default image seize will only be set, if the draw:image had been added to its draw:frame prior.
      Parameters:
      imageUri - The URI of the image that will be added as 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.
      Returns:
      Returns the package path of the image, which was created based on the given URI.
      Throws:
      Exception - If the image provided by the URI, could not be added as stream to the ODF package.
    • newImage

      public void newImage(InputStream is, String packagePath, String mediaType) throws Exception
      Inserts the image file from the stream to the ODF package named similar as in the provided path.. The manifest is adapted using given media type. Existing images are replaced.
      Parameters:
      is - InputStream to be added to the ODF package
      packagePath - Internal path of the image in the package
      mediaType - The mediaType of the image. Can be obtained by the OdfFileEntry class findMediaType(String fileRef).
      Throws:
      Exception - If the given stream could not be added to the ODF package at the packagePatch
    • newImage

      public void newImage(byte[] fileBytes, String packagePath, String mediaType) throws Exception
      Inserts the image file from the stream to the ODF package named similar as in the provided path.. The manifest is adapted using given media type. Existing images are replaced.
      Parameters:
      fileBytes - - data of the file stream to be stored in package. If NULL a directory with the given media type will be created.
      packagePath - Internal path of the image in the package
      mediaType - The mediaType of the image. Can be obtained by the OdfFileEntry class findMediaType(String fileRef).
      Throws:
      Exception - If the given stream could not be added to the ODF package at the packagePatch
    • getImageByPath

      public static List<OdfDrawImage> getImageByPath(OdfSchemaDocument doc, String imagePath)
      The method returns the specific one or more images by image path since the image may be inserted to the document several times.
      Parameters:
      doc - the document the image belongs to
      imagePath - the internal package path of the image.
      Returns:
      an Image list that match the given image path if no images is found under the given path, return an empty list.
    • deleteImageByPath

      public static void deleteImageByPath(OdfSchemaDocument doc, String imagePath)
      The method deletes one or more images from image container by image path.
      Parameters:
      doc - the document the image should be deleted from
      imagePath - the internal package path of the image.
    • deleteImage

      public static void deleteImage(OdfSchemaDocument doc, OdfDrawImage image)
      The method deletes the specified image from image container.
      Parameters:
      doc - the document the image should be deleted from
      image - the image which need to be deleted
    • getImageCount

      public static int getImageCount(OdfSchemaDocument doc)
      Get the count of image objects in the image container.
      Parameters:
      doc - the document the image should be counted from
      Returns:
      the number of image in this document if no image is found, return zero
    • getImages

      public static List<OdfDrawImage> getImages(OdfSchemaDocument doc)
      The method return the image list in the image container.
      Parameters:
      doc - the document the list of images should be returned from
      Returns:
      an image list in this document if no images is found, return an empty list.
    • getImagePathSet

      public static Set<String> getImagePathSet(OdfSchemaDocument doc)
      The method return the set of all the image paths.
      Parameters:
      doc - the document the image path set should be obtained from
      Returns:
      an image path set in this document