com.day.cq.wcm.foundation
Class Image

java.lang.Object
  extended by org.apache.sling.api.resource.ResourceWrapper
      extended by com.day.cq.commons.DownloadResource
          extended by com.day.cq.commons.ImageResource
              extended by com.day.cq.wcm.foundation.Image
All Implemented Interfaces:
Adaptable, Resource

public class Image
extends ImageResource

Provides convenience methods for displaying images.


Field Summary
static String PN_IMAGE_MAP
          name of the image map property
 
Fields inherited from class com.day.cq.commons.ImageResource
PN_ALT, PN_HEIGHT, PN_HTML_HEIGHT, PN_HTML_WIDTH, PN_IMAGE_CROP, PN_IMAGE_ROTATE, PN_LINK_URL, PN_MAX_HEIGHT, PN_MAX_WIDTH, PN_MIN_HEIGHT, PN_MIN_WIDTH, PN_WIDTH
 
Fields inherited from class com.day.cq.commons.DownloadResource
attrs, NN_FILE, node, PN_DESCRIPTION, PN_FILE_NAME, PN_REFERENCE, PN_TITLE, properties
 
Fields inherited from interface org.apache.sling.api.resource.Resource
RESOURCE_TYPE_NON_EXISTING
 
Constructor Summary
Image(Resource resource)
          Creates a new image based on the given resource. the image properties are considered to 'on' the given resource.
Image(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.
 
Method Summary
protected  boolean canDraw()
          checks if this image can be drawn.
protected  void doDraw(PrintWriter w)
          Writes this image as tag to the given writer by invoking the following - calls ImageResource.getImageTagAttributes() - prints the link tag if needed - prints the image tag - prints the attributes - closes the image tag - closes the link tag
 String getIconPath()
          Returns a path to an icon representing the file.
protected  Map<String,String> getImageTagAttributes()
          Collects the image tag attributes.
protected  Resource getReferencedResource(String path)
          Returns the resource that is referenced by path.
 boolean hasNoPlaceholder()
          Returns the placeholder flag.
 void loadStyleData(Style style)
          Loads several definitions from style.
 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. the id is added as css class to the image attribute. and has the format: "{id}-{classifier}"
 void setNoPlaceholder(boolean noPlaceholder)
          Sets the placeholder flag.
 
Methods inherited from class com.day.cq.commons.ImageResource
crop, draw, getAlt, getCropRect, getDoctype, getExtension, getLayer, getRelativeResource, getRotation, getSrc, getTitle, resize, rotate, setAlt, setDoctype, setExtension, setSrc
 
Methods inherited from class com.day.cq.commons.DownloadResource
addAttribute, addCssClass, addQueryParam, get, get, getAttributes, getData, getDescription, getDescription, getFileName, getFileNodePath, getFileReference, getHref, getIconType, getInnerHtml, getItemName, getLastModified, getMimeType, getQuery, getSelector, getString, getSuffix, getTitle, hasContent, init, isTouchAuthoringUIMode, set, setDescription, setFileName, setFileNodePath, setFileReference, setHref, setInnerHtml, setIsInUITouchMode, setItemName, setQuery, setSelector, setSuffix, setTitle
 
Methods inherited from class org.apache.sling.api.resource.ResourceWrapper
adaptTo, getChild, getChildren, getName, getParent, getPath, getResource, getResourceMetadata, getResourceResolver, getResourceSuperType, getResourceType, isResourceType, listChildren, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PN_IMAGE_MAP

public static final String PN_IMAGE_MAP
name of the image map property

See Also:
Constant Field Values
Constructor Detail

Image

public Image(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.

Image

public Image(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

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.

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

canDraw

protected boolean canDraw()
checks if this image can be drawn.

Overrides:
canDraw in class ImageResource
Returns:
true if hasNoPlaceholder() is false or the image has content.

getImageTagAttributes

protected Map<String,String> getImageTagAttributes()
Description copied from class: ImageResource
Collects the image tag attributes.

Overrides:
getImageTagAttributes in class ImageResource
Returns:
the attributes

doDraw

protected void doDraw(PrintWriter w)
Writes this image as tag to the given writer by invoking the following - calls ImageResource.getImageTagAttributes() - prints the link tag if needed - prints the image tag - prints the attributes - closes the image tag - closes the link tag

Overrides:
doDraw in class ImageResource
Parameters:
w - the writer

getIconPath

public String getIconPath()
Returns a path to an icon representing the file. Checks if the component of the resource provides an icon for the respective type.

Overrides:
getIconPath in class DownloadResource
Returns:
a path to an icon or null.

getReferencedResource

protected Resource getReferencedResource(String path)
Returns the resource that is referenced by path. Subclasses can provide further semantics. Checks if the resource is an asset and returns the correct rendition.

Overrides:
getReferencedResource in class DownloadResource
Parameters:
path - path to the resource
Returns:
the resource or null.


Copyright © 2011-2013 Adobe Systems Incorporated. All Rights Reserved.