com.day.cq.wcm.foundation
Class Image

java.lang.Object
  extended by com.day.cq.wcm.foundation.Download
      extended by com.day.cq.wcm.foundation.Image

public class Image
extends Download

Provides convenience methods for displaying images.


Field Summary
static String PN_ALT
          name of the alt name property
static String PN_HEIGHT
          name of the height property
static String PN_HTML_HEIGHT
          name of the html height property
static String PN_HTML_WIDTH
          name of the html width property
static String PN_IMAGE_CROP
          name of the image crop property
static String PN_IMAGE_MAP
          name of the image map property
static String PN_IMAGE_ROTATE
          name of the image rotation property
static String PN_MAX_HEIGHT
          name of the maximal height property.
static String PN_MAX_WIDTH
          name of the maximal width property.
static String PN_MIN_HEIGHT
          name of the minimal height property.
static String PN_MIN_WIDTH
          name of the minimal width property.
static String PN_WIDTH
          name of the width property
 
Fields inherited from class com.day.cq.wcm.foundation.Download
attrs, NN_FILE, node, PN_DESCRIPTION, PN_FILE_NAME, PN_REFERENCE, PN_TITLE, properties, resource
 
Constructor Summary
Image(org.apache.sling.api.resource.Resource resource)
          Creates a new image based on the given resource.
Image(org.apache.sling.api.resource.Resource resource, String imageName)
          Creates a new image based on the given resource.
 
Method Summary
 com.day.image.Layer crop(com.day.image.Layer layer)
          Crops the layer using the internal crop rectangle.
 void draw(Writer w)
          Writes this image as tag to the given writer
 String getAlt()
          Returns the image alt name as defined by the "alt" or overridden by setAlt(String).
 Rectangle getCropRect()
          Returns the cropping rectangle as defined by the "imageCrop".
 com.day.image.Layer getLayer(boolean cropped, boolean resized, boolean rotated)
          Returns the layer addressed by this image.
 int getRotation()
          Returns the rotation angle as defined by the "imageRotate".
 String getSrc()
          Returns the source attribute of this image.
 boolean hasNoPlaceholder()
          Returns the placeholder flag.
 void loadStyleData(Style style)
          Loads several definitions from style.
 com.day.image.Layer resize(com.day.image.Layer layer)
          Resizes the given layer according to the dimensions defined in this image.
 com.day.image.Layer rotate(com.day.image.Layer layer)
          Rotates the layer using the internal rotation angle.
 void setAlt(String alt)
          Sets the alt name.
 void setDropTargetId(String id)
          Sets the drop target id for this image, using the name of the resources as path.
 void setDropTargetId(String id, String classifier)
          Sets the drop target id for this image.
 void setNoPlaceholder(boolean noPlaceholder)
          Sets the placeholder flag.
 void setSrc(String src)
          Sets the source attribute
 
Methods inherited from class com.day.cq.wcm.foundation.Download
addAttribute, addCssClass, get, get, getAttributes, getData, getDescription, getDescription, getExtension, getFileName, getFileNodePath, getFileReference, getHref, getIconPath, getIconType, getInnerHtml, getItemName, getMimeType, getResource, getSelector, getString, getSuffix, getTitle, getTitle, hasContent, init, set, setDescription, setExtension, setFileName, setFileNodePath, setFileReference, setHref, setInnerHtml, setItemName, setSelector, setSuffix, setTitle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PN_HTML_WIDTH

public static final String PN_HTML_WIDTH
name of the html width property

See Also:
Constant Field Values

PN_HTML_HEIGHT

public static final String PN_HTML_HEIGHT
name of the html height property

See Also:
Constant Field Values

PN_WIDTH

public static final String PN_WIDTH
name of the width property

See Also:
Constant Field Values

PN_HEIGHT

public static final String PN_HEIGHT
name of the height property

See Also:
Constant Field Values

PN_MIN_WIDTH

public static final String PN_MIN_WIDTH
name of the minimal width property. used for resizing.

See Also:
Constant Field Values

PN_MIN_HEIGHT

public static final String PN_MIN_HEIGHT
name of the minimal height property. used for resizing.

See Also:
Constant Field Values

PN_MAX_WIDTH

public static final String PN_MAX_WIDTH
name of the maximal width property. used for resizing.

See Also:
Constant Field Values

PN_MAX_HEIGHT

public static final String PN_MAX_HEIGHT
name of the maximal height property. used for resizing.

See Also:
Constant Field Values

PN_ALT

public static final String PN_ALT
name of the alt name property

See Also:
Constant Field Values

PN_IMAGE_MAP

public static final String PN_IMAGE_MAP
name of the image map property

See Also:
Constant Field Values

PN_IMAGE_CROP

public static final String PN_IMAGE_CROP
name of the image crop property

See Also:
Constant Field Values

PN_IMAGE_ROTATE

public static final String PN_IMAGE_ROTATE
name of the image rotation property

See Also:
Constant Field Values
Constructor Detail

Image

public Image(org.apache.sling.api.resource.Resource resource)
Creates a new image based on the given resource. the image properties are considered to by 'on' the given resource.

Parameters:
resource - resource of the image
Throws:
IllegalArgumentException - if the given resource is not adaptable to node.

Image

public Image(org.apache.sling.api.resource.Resource resource,
             String imageName)
Creates a new image based on the given resource. the image properties are considered to by 'on' the given resource unless image is specified. then the respective child resource hold 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

setDropTargetId

public void setDropTargetId(String id,
                            String classifier)
Sets the drop target id for this image. the id is added as css class to the image attribute. and has the format: "{id}-{classifier}"

Parameters:
id - the drop target id as configured in edit config.
classifier - optional classifier

setDropTargetId

public void setDropTargetId(String id)
Sets the drop target id for this image, using the name of the resources as path.

Parameters:
id - the drop target id as configured in edit config.

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:

Returns:
the source attribute

setSrc

public void setSrc(String src)
Sets the source attribute

Parameters:
src - the source attribute

hasNoPlaceholder

public boolean hasNoPlaceholder()
Returns the placeholder flag.

Returns:
true if no placeholder for empty content should be drawn.

setNoPlaceholder

public void setNoPlaceholder(boolean noPlaceholder)
Sets the placeholder flag.

Parameters:
noPlaceholder - if true no placeholder for empty content is used.

loadStyleData

public void loadStyleData(Style style)
Loads several definitions from style.

Currently, the minimum/maximum width and height are transferred from the given style.

Parameters:
style - style to load definitions from

draw

public void draw(Writer w)
          throws IOException
Writes this image as tag to the given writer

Overrides:
draw in class Download
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 com.day.image.Layer resize(com.day.image.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 com.day.image.Layer crop(com.day.image.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 com.day.image.Layer rotate(com.day.image.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 com.day.image.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.


Copyright © 2008 Day Management AG. All Rights Reserved.