Class ImageResource

All Implemented Interfaces:
Adaptable, Resource
Direct Known Subclasses:
Image

public class ImageResource extends DownloadResource
Provides convenience methods for displaying images.
  • Field Details

  • Constructor Details

    • 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 Details

    • getTitle

      public 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 String getAlt()
      Returns the image alt name as defined by the "alt" or overridden by setAlt(String).
      Returns:
      the alt name
      See Also:
    • 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
    • setExtension

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

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

      @Deprecated public Doctype getDoctype()
      Deprecated.
      Returns the doctype that is used when generating the HTML. Defaults to Doctype.HTML_401_STRICT.
      Returns:
      the doctype
      Since:
      5.3
    • 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(Writer w) throws 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:
      IOException - if an I/O error occurs
    • 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)
    • resize

      public Layer resize(Layer layer)
      Resizes the given layer according to the dimensions defined in this image. See ImageHelper.resize(Layer, Dimension, Dimension, Dimension) for more details about the resizing algorithm.
      Parameters:
      layer - the layer to resize
      Returns:
      the layer or null if the layer is untouched
    • 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.