Copyright© 2008-2022 Sitevision AB, all rights reserved.
@Requireable(value="ImageLinkRenderer") public interface ImageLinkRenderer
Using the ImageLinkRenderer is pretty straightforward. All setup and state are maintained in an ImageRenderer instance and an LinkRenderer instance that both can be retrieved via their corresponding getters. Conceptually you would typically use ImageLinkRenderer like this:
LinkRenderer
)ImageRenderer
)When you have rendered once, you can re-use the renderers until you are done. Something like:
Example of how this strategy could be implemented in Velocity:
(You want to do a simple thumbnail listing of some image nodes in a collection/iterator "$images", and each thumbnail should be linked to
the original image (and opened in a new window)
## Get the ImageLinkRenderer
#set ($imageLinkRenderer = $sitevisionUtils.imageLinkRenderer)
## Fetch the ImageRenderer and apply an image scaler (200x100 px)
#set ($imageScaler = $sitevisionUtils.getImageScaler(200, 100))
#set ($imageRenderer = $imageLinkRenderer.imageRenderer)
$imageRenderer.setImageScaler($imageScaler)
## Fetch the LinkRenderer and ensure links will be opened in a new window
#set ($linkRenderer = $imageLinkRenderer.linkRenderer)
$linkRenderer.forceOpenNewWindow()
## Iterate through images and render them
<ul style="list-style:none">
#foreach ($image in $images)
## Load an image (that will be rendered as a 200x100 thumbnail)
$imageRenderer.update($image)
## Link the image
$linkRenderer.update($image)
<li>
## Render the image link (i.e. a thumbnail image linked to the original image)
$imageLinkRenderer.render()
</li>
#end
</ul>
Validation Note! Some validation tools consider image links to be invalid if the linked content
(i.e. in this case an <img>
element) does not have a textual representation (i.e. the alt
attribute of the <img>
element is empty). In order to minimize work to encompass this, the
ImageRenderer.forceUseAutoDescription()
is initially invoked for the ImageRenderer
used by the ImageLinkRenderer.
Thread Note! The render method is NOT thread safe! During execution of the render method the
ImageLinkRenderer might temporarily modify the state of the LinkRenderer and/or the ImageRenderer. In other words:
if two threads simultaneously executes the render method on the SAME ImageLinkRenderer instance, the rendered
result might differ. This is in almost all cases nothing you need to worry about, unless your portlet or servlet actually
creates a separate Thread
and starts it. If so - ensure all your created
threads creates and uses their own ImageLinkRenderer instance!
An instance of the Sitevision class implementing this interface can be obtained via
Utils.getImageLinkRenderer()
.
See Utils
for how to obtain an instance of the Utils
interface.
LinkRenderer
,
ImageRenderer
Modifier and Type | Method and Description |
---|---|
ImageRenderer |
getImageRenderer()
Returns the ImageRenderer instance used by this image link renderer to control (linked) image behaviour.
|
LinkRenderer |
getLinkRenderer()
Returns the LinkRenderer instance used by this image link renderer to control linking behaviour.
|
String |
render()
Builds a html link based on current state of the link renderer and the image render.
|
LinkRenderer getLinkRenderer()
LinkRenderer
ImageRenderer getImageRenderer()
Note! The useAutoDescription
is initially set to true
when the ImageRenderer instance is
created by this image link renderer, see validation note above.
ImageRenderer
String render()
Note! The render method is not thread safe, see thread note above.
Sitevision - Portal and Content Management Made Easy
Sitevision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2022 Sitevision AB, all rights reserved.