Class ImageResource

    • Constructor Detail

      • ImageResource

        public ImageResource​(Resource resource)
        Creates a new image based on the given resource. the image properties are considered to 'on' the given resource.
        Parameters:
        resource - resource of the image
        Throws:
        IllegalArgumentException - if the given resource is not adaptable to node.
      • ImageResource

        public ImageResource​(Resource resource,
                             String imageName)
        Creates a new image based on the given resource. the image properties are considered to 'on' the given resource unless imageName is specified. then the respective child resource holds the image properties.
        Parameters:
        resource - current resource
        imageName - name of the image resource
        Throws:
        IllegalArgumentException - if the given resource is not adaptable to node.
    • Method Detail

      • getAlt

        public String getAlt()
        Returns the image alt name as defined by the "alt" or overridden by setAlt(String).
        Returns:
        the alt name
        See Also:
        PN_ALT
      • setAlt

        public void setAlt​(String alt)
        Sets the alt name.
        Parameters:
        alt - the alt name.
      • getSrc

        public String getSrc()
        Returns the source attribute of this image. the source is computed as follows:
        • if a selector is defined the path of the current resource concatenated with the selector, extension, and suffix is used.
        • if a file node path is defined it is concatenated with the extension and suffix.
        • if a file reference is defined it is concatenated with the extension and suffix.
        Returns:
        the source attribute
      • getExtension

        public String getExtension()
        Tries to calculate the extension from the mime-type of the underlying image.
        Overrides:
        getExtension in class DownloadResource
        Returns:
        the mime-type dependant extension or ".png" if not determinable
      • setSrc

        public void setSrc​(String src)
        Sets the source attribute
        Parameters:
        src - the source attribute
      • getImageDoctype

        public Doctype getImageDoctype()
        Returns the doctype that is used when generating the HTML. Defaults to Doctype.HTML_401_STRICT.
        Returns:
        the doctype
      • setDoctype

        @Deprecated
        public void setDoctype​(Doctype doctype)
        Deprecated.
        Sets the doctype that is used when generating the HTML. If the given argument is null the current doctype is not overridden.
        Parameters:
        doctype - the doctype
        Since:
        5.3
      • setImageDoctype

        public void setImageDoctype​(Doctype doctype)
        Sets the doctype that is used when generating the HTML. If the given argument is null the current doctype is not overridden.
        Parameters:
        doctype - the doctype
      • getCropRect

        public Rectangle getCropRect()
        Returns the cropping rectangle as defined by the "imageCrop".
        Returns:
        the cropping rectangle or null
      • getRotation

        public int getRotation()
        Returns the rotation angle as defined by the "imageRotate".
        Returns:
        the rotation angle (in degrees)
      • crop

        public Layer crop​(Layer layer)
        Crops the layer using the internal crop rectangle. if the crop rectangle is empty no cropping is performed and null is returned.
        Parameters:
        layer - the layer
        Returns:
        cropped layer or null
      • rotate

        public Layer rotate​(Layer layer)
        Rotates the layer using the internal rotation angle. If no rotation other than 0 is defined, no rotation is performed and null is returned.
        Parameters:
        layer - the layer
        Returns:
        cropped layer or null
      • getLayer

        public Layer getLayer​(boolean cropped,
                              boolean resized,
                              boolean rotated)
                       throws IOException,
                              RepositoryException
        Returns the layer addressed by this image.
        Parameters:
        cropped - apply cropping if true
        resized - apply resizing if true
        rotated - apply rotation if true
        Returns:
        the layer
        Throws:
        IOException - if an I/O error occurs.
        RepositoryException - if a repository error occurs.
      • getData

        public Property getData()
                         throws RepositoryException
        Description copied from class: DownloadResource
        Returns the property that contains the binary data of this download. This can either by a property addressed by the internal file resource or a property addressed by an external file reference.
        Overrides:
        getData in class DownloadResource
        Returns:
        binary property or null
        Throws:
        RepositoryException - if an error accessing the repository occurs.