Package com.day.cq.commons
Class ImageResource
java.lang.Object
org.apache.sling.api.resource.ResourceWrapper
com.day.cq.commons.DownloadResource
com.day.cq.commons.ImageResource
- Direct Known Subclasses:
Image
Provides convenience methods for displaying images.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringthe default image pathstatic final Stringname of the alt name propertystatic final Stringname of the default image path propertystatic final Stringname of the height propertystatic final Stringname of the html height propertystatic final Stringname of the html width propertystatic final Stringname of the image crop propertystatic final Stringname of the image rotation propertystatic final Stringname of the link URL propertystatic final Stringname of the maximal height property.static final Stringname of the maximal width property.static final Stringname of the minimal height property.static final Stringname of the minimal width property.static final Stringname of the width propertyFields inherited from class com.day.cq.commons.DownloadResource
NN_FILE, PN_DESCRIPTION, PN_FILE_NAME, PN_REFERENCE, PN_TITLEFields inherited from interface org.apache.sling.api.resource.Resource
RESOURCE_TYPE_NON_EXISTING -
Constructor Summary
ConstructorsConstructorDescriptionImageResource(Resource resource) Creates a new image based on the given resource.ImageResource(Resource resource, String imageName) Creates a new image based on the given resource. -
Method Summary
Modifier and TypeMethodDescriptionCrops the layer using the internal crop rectangle.voidWrites this image as tag to the given writer by invokingdoDraw(PrintWriter)ifcanDraw()returnstrue.getAlt()Returns the image alt name as defined by the "alt" or overridden bysetAlt(String).Returns the cropping rectangle as defined by the "imageCrop".getData()Returns the property that contains the binary data of this download.Deprecated.Tries to calculate the extension from the mime-type of the underlying image.Returns the doctype that is used when generating the HTML.getLayer(boolean cropped, boolean resized, boolean rotated) Returns the layer addressed by this image.intReturns the rotation angle as defined by the "imageRotate".getSrc()Returns the source attribute of this image.getTitle(boolean escape) Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden byDownloadResource.setTitle(String).Resizes the given layer according to the dimensions defined in this image.Rotates the layer using the internal rotation angle.voidSets the alt name.voidsetDoctype(Doctype doctype) Deprecated.voidsetExtension(String extension) Sets the extension.voidsetImageDoctype(Doctype doctype) Sets the doctype that is used when generating the HTML.voidSets the source attributeMethods inherited from class com.day.cq.commons.DownloadResource
addAttribute, addCssClass, addQueryParam, get, get, getAttributes, getDescription, getDescription, getFileName, getFileNodePath, getFileReference, getHref, getIconPath, 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, setTitleMethods inherited from class org.apache.sling.api.resource.ResourceWrapper
adaptTo, getChild, getChildren, getName, getParent, getPath, getResource, getResourceMetadata, getResourceResolver, getResourceSuperType, getResourceType, getValueMap, hasChildren, isResourceType, listChildren, toString
-
Field Details
-
PN_HTML_WIDTH
name of the html width property- See Also:
-
PN_HTML_HEIGHT
name of the html height property- See Also:
-
PN_WIDTH
name of the width property- See Also:
-
PN_HEIGHT
name of the height property- See Also:
-
PN_MIN_WIDTH
name of the minimal width property. used for resizing.- See Also:
-
PN_MIN_HEIGHT
name of the minimal height property. used for resizing.- See Also:
-
PN_MAX_WIDTH
name of the maximal width property. used for resizing.- See Also:
-
PN_MAX_HEIGHT
name of the maximal height property. used for resizing.- See Also:
-
PN_ALT
name of the alt name property- See Also:
-
PN_IMAGE_CROP
name of the image crop property- See Also:
-
PN_IMAGE_ROTATE
name of the image rotation property- See Also:
-
PN_LINK_URL
name of the link URL property- See Also:
-
PN_DEFAULT_IMAGE_PATH
name of the default image path property- See Also:
-
DEFAULT_IMAGE_PATH
the default image path- See Also:
-
-
Constructor Details
-
ImageResource
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
Creates a new image based on the given resource. the image properties are considered to 'on' the given resource unlessimageNameis specified. then the respective child resource holds the image properties.- Parameters:
resource- current resourceimageName- name of the image resource- Throws:
IllegalArgumentException- if the given resource is not adaptable to node.
-
-
Method Details
-
getTitle
Returns the image title as defined by 'getItemName(PN_TITLE)' or overridden byDownloadResource.setTitle(String).- Overrides:
getTitlein classDownloadResource- Parameters:
escape- iftruethe string is HTML escaped- Returns:
- the title
-
getAlt
Returns the image alt name as defined by the "alt" or overridden bysetAlt(String).- Returns:
- the alt name
- See Also:
-
setAlt
Sets the alt name.- Parameters:
alt- the alt name.
-
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
Tries to calculate the extension from the mime-type of the underlying image.- Overrides:
getExtensionin classDownloadResource- Returns:
- the mime-type dependant extension or ".png" if not determinable
-
setExtension
Description copied from class:DownloadResourceSets the extension.- Overrides:
setExtensionin classDownloadResource- Parameters:
extension- the extension.
-
setSrc
Sets the source attribute- Parameters:
src- the source attribute
-
getDoctype
Deprecated.Returns the doctype that is used when generating the HTML. Defaults toDoctype.HTML_401_STRICT.- Returns:
- the doctype
- Since:
- 5.3
-
getImageDoctype
Returns the doctype that is used when generating the HTML. Defaults toDoctype.HTML_401_STRICT.- Returns:
- the doctype
-
setDoctype
Deprecated.Sets the doctype that is used when generating the HTML. If the given argument isnullthe current doctype is not overridden.- Parameters:
doctype- the doctype- Since:
- 5.3
-
setImageDoctype
Sets the doctype that is used when generating the HTML. If the given argument isnullthe current doctype is not overridden.- Parameters:
doctype- the doctype
-
draw
Writes this image as tag to the given writer by invokingdoDraw(PrintWriter)ifcanDraw()returnstrue.- Overrides:
drawin classDownloadResource- Parameters:
w- the writer- Throws:
IOException- if an I/O error occurs
-
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
Resizes the given layer according to the dimensions defined in this image. SeeImageHelper.resize(Layer, Dimension, Dimension, Dimension)for more details about the resizing algorithm.- Parameters:
layer- the layer to resize- Returns:
- the layer or
nullif the layer is untouched
-
crop
Crops the layer using the internal crop rectangle. if the crop rectangle is empty no cropping is performed andnullis returned.- Parameters:
layer- the layer- Returns:
- cropped layer or
null
-
rotate
Rotates the layer using the internal rotation angle. If no rotation other than 0 is defined, no rotation is performed andnullis 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 iftrueresized- apply resizing iftruerotated- apply rotation iftrue- Returns:
- the layer
- Throws:
IOException- if an I/O error occurs.RepositoryException- if a repository error occurs.
-
getData
Description copied from class:DownloadResourceReturns 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:
getDatain classDownloadResource- Returns:
- binary property or
null - Throws:
RepositoryException- if an error accessing the repository occurs.
-
getImageDoctype()