Class ImageResource

    • Field Detail

      • PN_HTML_WIDTH

        public static final java.lang.String PN_HTML_WIDTH
        name of the html width property
        See Also:
        Constant Field Values
      • PN_HTML_HEIGHT

        public static final java.lang.String PN_HTML_HEIGHT
        name of the html height property
        See Also:
        Constant Field Values
      • PN_WIDTH

        public static final java.lang.String PN_WIDTH
        name of the width property
        See Also:
        Constant Field Values
      • PN_HEIGHT

        public static final java.lang.String PN_HEIGHT
        name of the height property
        See Also:
        Constant Field Values
      • PN_MIN_WIDTH

        public static final java.lang.String PN_MIN_WIDTH
        name of the minimal width property. used for resizing.
        See Also:
        Constant Field Values
      • PN_MIN_HEIGHT

        public static final java.lang.String PN_MIN_HEIGHT
        name of the minimal height property. used for resizing.
        See Also:
        Constant Field Values
      • PN_MAX_WIDTH

        public static final java.lang.String PN_MAX_WIDTH
        name of the maximal width property. used for resizing.
        See Also:
        Constant Field Values
      • PN_MAX_HEIGHT

        public static final java.lang.String PN_MAX_HEIGHT
        name of the maximal height property. used for resizing.
        See Also:
        Constant Field Values
      • PN_ALT

        public static final java.lang.String PN_ALT
        name of the alt name property
        See Also:
        Constant Field Values
      • PN_IMAGE_CROP

        public static final java.lang.String PN_IMAGE_CROP
        name of the image crop property
        See Also:
        Constant Field Values
      • PN_IMAGE_ROTATE

        public static final java.lang.String PN_IMAGE_ROTATE
        name of the image rotation property
        See Also:
        Constant Field Values
      • PN_LINK_URL

        public static final java.lang.String PN_LINK_URL
        name of the link URL property
        See Also:
        Constant Field Values
      • PN_DEFAULT_IMAGE_PATH

        public static final java.lang.String PN_DEFAULT_IMAGE_PATH
        name of the default image path property
        See Also:
        Constant Field Values
      • DEFAULT_IMAGE_PATH

        public static final java.lang.String DEFAULT_IMAGE_PATH
        the default image path
        See Also:
        Constant Field Values
    • 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:
        java.lang.IllegalArgumentException - if the given resource is not adaptable to node.
      • ImageResource

        public ImageResource​(Resource resource,
                             java.lang.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:
        java.lang.IllegalArgumentException - if the given resource is not adaptable to node.
    • Method Detail

      • getTitle

        public java.lang.String getTitle​(boolean escape)
        Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden by DownloadResource.setTitle(String).
        Overrides:
        getTitle in class DownloadResource
        Parameters:
        escape - if true the string is HTML escaped
        Returns:
        the title
      • getAlt

        public java.lang.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​(java.lang.String alt)
        Sets the alt name.
        Parameters:
        alt - the alt name.
      • getSrc

        public java.lang.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 java.lang.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
      • setExtension

        public void setExtension​(java.lang.String extension)
        Description copied from class: DownloadResource
        Sets the extension.
        Overrides:
        setExtension in class DownloadResource
        Parameters:
        extension - the extension.
      • setSrc

        public void setSrc​(java.lang.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
      • draw

        public void draw​(java.io.Writer w)
                  throws java.io.IOException
        Writes this image as tag to the given writer by invoking doDraw(PrintWriter) if canDraw() returns true.
        Overrides:
        draw in class DownloadResource
        Parameters:
        w - the writer
        Throws:
        java.io.IOException - if an I/O error occurs
      • getCropRect

        public java.awt.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 java.io.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:
        java.io.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.