com.jalios.jcms.taglib
Class ThumbnailTag

java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by javax.servlet.jsp.tagext.BodyTagSupport
          extended by com.jalios.jcms.taglib.ThumbnailTag
All Implemented Interfaces:
JcmsConstants, JaliosConstants, Serializable, javax.servlet.jsp.tagext.BodyTag, javax.servlet.jsp.tagext.IterationTag, javax.servlet.jsp.tagext.JspTag, javax.servlet.jsp.tagext.Tag

public class ThumbnailTag
extends javax.servlet.jsp.tagext.BodyTagSupport
implements JcmsConstants

This tags add possibily to create and display a thumbnail of an image. If you need to create and display a thumbnail from java code. Use method createThumbnail(FileDocument, File, URL, ImageFormat, int, int) which use same internal cache.

Since:
jcms-5.5.0
Version:
$Revision: 35897 $
Author:
Olivier Jaquemet
See Also:
Serialized Form

Field Summary
static int MAX_THUMB_SIZE
           
static int MIN_THUMB_SIZE
           
static String REVISION
           
 
Fields inherited from class javax.servlet.jsp.tagext.BodyTagSupport
bodyContent
 
Fields inherited from class javax.servlet.jsp.tagext.TagSupport
id, pageContext
 
Fields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, ADMIN_NOTES_PROP, ADVANCED_TAB, ARCHIVES_DIR, ASCII_WIDTH, CATEGORY_TAB, CDATE_SEARCH, COMMON_ALARM, CONTENT_TAB, COOKIE_MAX_AGE, CTRL_TOPIC_INTERNAL, CTRL_TOPIC_REF, CTRL_TOPIC_VALUE, CTRL_TOPIC_WRITE, CUSTOM_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, ICON_ARCHIVE, ICON_LOCK, ICON_LOCK_STRONG, ICON_WARN, ICON_WH_BOOK_CLOSED, ICON_WH_BOOK_OPEN, INFORMATION_MSG, JALIOS_JUNIT_PROP, JCMS_CADDY, JCMS_MSG_LIST, JSYNC_DOWNLOAD_DIR, JSYNC_SYNC_ALARM, LOG_FILE, LOG_TOPIC_SECURITY, LOGGER_PROP, LOGGER_XMLPROP, MBR_PHOTO_DIR, MDATE_SEARCH, MONITOR_XML, OP_CREATE, OP_DEEP_COPY, OP_DEEP_DELETE, OP_DELETE, OP_MERGE, OP_UPDATE, PDATE_SEARCH, PHOTO_DIR, PHOTO_ICON, PHOTO_ICON_HEIGHT, PHOTO_ICON_WIDTH, PHOTO_LARGE, PHOTO_LARGE_HEIGHT, PHOTO_LARGE_WIDTH, PHOTO_NORMAL, PHOTO_NORMAL_HEIGHT, PHOTO_NORMAL_WIDTH, PHOTO_SMALL, PHOTO_SMALL_HEIGHT, PHOTO_SMALL_WIDTH, PHOTO_TINY, PHOTO_TINY_HEIGHT, PHOTO_TINY_WIDTH, PREVIOUS_TAB, PRINT_VIEW, PRIVATE_FILE_ACCESS, PUBLIC_FILE_ACCESS, READ_RIGHT_TAB, SDATE_SEARCH, SEARCHENGINE_ALARM, SESSION_AUTHORIZED_FILENAMES_SET, STATS_REPORT_DIR, STATUS_PROP, STORE_XML, TEMPLATE_TAB, THUMBNAIL_LARGE_HEIGHT, THUMBNAIL_LARGE_WIDTH, THUMBNAIL_SMALL_HEIGHT, THUMBNAIL_SMALL_WIDTH, UDATE_SEARCH, UPDATE_RIGHT_TAB, UPLOAD_DIR, URL_REGEXP, WARNING_MSG, WEBAPP_PROP, WFEXPRESS_ALARM, WFREMINDER_ALARM, WORKFLOW_TAB, WORKFLOW_XML
 
Fields inherited from interface com.jalios.util.JaliosConstants
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR
 
Fields inherited from interface javax.servlet.jsp.tagext.BodyTag
EVAL_BODY_BUFFERED, EVAL_BODY_TAG
 
Fields inherited from interface javax.servlet.jsp.tagext.IterationTag
EVAL_BODY_AGAIN
 
Fields inherited from interface javax.servlet.jsp.tagext.Tag
EVAL_BODY_INCLUDE, EVAL_PAGE, SKIP_BODY, SKIP_PAGE
 
Constructor Summary
ThumbnailTag()
           
 
Method Summary
static File buildThumbnail(File srcFile, int width, int height, File defaultFile, String background)
          Returns a Thumbnail for the given path.
static String buildThumbnail(String path, int width, int height, String defaultPath)
           
static String buildThumbnail(String path, int width, int height, String defaultPath, String background)
          Returns a Thumbnail for the given path.
protected  void clean()
           
static boolean createImageThumbnail(File imageFile, File dest, ImageFormat format, int maxWidth, int maxHeight)
           
static boolean createImageThumbnail(File imageFile, File dest, ImageFormat format, int maxWidth, int maxHeight, String background)
          This method creates a thumbnail of the given image source file.
static boolean createOpenOfficeThumbnail(File docFile, File dest, ImageFormat format, int maxWidth, int maxHeight, String background)
          This method creates a thumbnail of the given Open Office file.
static boolean createOpenXmlThumbnail(File docFile, File dest, ImageFormat format, int maxWidth, int maxHeight, String background)
          This method creates a thumbnail of the given OpenXml file.
static File createThumbnail(FileDocument fileDoc, File srcFile, URL url, ImageFormat format, int maxWidth, int maxHeight)
           
static File createThumbnail(FileDocument fileDoc, File srcFile, URL url, ImageFormat format, int maxWidth, int maxHeight, String background)
          Create a thumbnail using the first valid source from FileDocument, File or URL using given dimensions.
static String createThumbnailFromSessionAttribute(String sessionAttrName)
           
static boolean createThumbnailNow(FileDocument fileDoc, File srcFile, URL url, ImageFormat format, int maxWidth, int maxHeight, File destFile)
           
static boolean createThumbnailNow(FileDocument fileDoc, File srcFile, URL url, ImageFormat format, int maxWidth, int maxHeight, File destFile, String background)
          This method create a thumbnail of one of the three source given using the options passed as parameters ("now" as opposed to generation when going through ajax}.
 int doAfterBody()
           
 int doEndTag()
           
 int doStartTag()
           
static File getThumbnailFile(FileDocument fileDoc, File srcFile, URL url, int maxWidth, int maxHeight)
          Gets the File to use for a thumbnail of the given FileDocument, File or URL using given dimensions.
static void invalidateCacheAttemptThumbnail(FileDocument fileDoc, File srcFile, URL url)
          Invalidates the cache of failure while attempt to create a thumbnail for the given parameter.
 void setAjaxLoadingImage(String ajaxLoadingImage)
           
 void setAlt(String alt)
           
 void setBackground(String background)
           
 void setCss(String css)
           
 void setData(Data data)
           
 void setDestination(String path)
           
 void setFile(File file)
           
 void setFileDoc(FileDocument fd)
           
 void setForceUpdate(boolean forceUpdate)
           
 void setFormat(String format)
           
 void setHeight(int height)
           
 void setHtmlAttributes(String htmlAttributes)
           
 void setPath(String path)
           
 void setUrl(String purl)
           
 void setUseAjaxLoading(boolean useAjaxLoading)
           
 void setWidth(int width)
           
 
Methods inherited from class javax.servlet.jsp.tagext.BodyTagSupport
doInitBody, getBodyContent, getPreviousOut, release, setBodyContent
 
Methods inherited from class javax.servlet.jsp.tagext.TagSupport
findAncestorWithClass, getId, getParent, getValue, getValues, removeValue, setId, setPageContext, setParent, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.jsp.tagext.Tag
getParent, setPageContext, setParent
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values

MAX_THUMB_SIZE

public static final int MAX_THUMB_SIZE
See Also:
Constant Field Values

MIN_THUMB_SIZE

public static final int MIN_THUMB_SIZE
See Also:
Constant Field Values
Constructor Detail

ThumbnailTag

public ThumbnailTag()
Method Detail

clean

protected void clean()

setData

public void setData(Data data)

setFileDoc

public void setFileDoc(FileDocument fd)

setFile

public void setFile(File file)

setPath

public void setPath(String path)

setUrl

public void setUrl(String purl)

setFormat

public void setFormat(String format)

setWidth

public void setWidth(int width)

setHeight

public void setHeight(int height)

setDestination

public void setDestination(String path)

setBackground

public void setBackground(String background)

setForceUpdate

public void setForceUpdate(boolean forceUpdate)

setAlt

public void setAlt(String alt)

setCss

public void setCss(String css)

setHtmlAttributes

public void setHtmlAttributes(String htmlAttributes)

setUseAjaxLoading

public void setUseAjaxLoading(boolean useAjaxLoading)

setAjaxLoadingImage

public void setAjaxLoadingImage(String ajaxLoadingImage)

doStartTag

public int doStartTag()
               throws javax.servlet.jsp.JspException
Specified by:
doStartTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doStartTag in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException

doEndTag

public int doEndTag()
             throws javax.servlet.jsp.JspException
Specified by:
doEndTag in interface javax.servlet.jsp.tagext.Tag
Overrides:
doEndTag in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException

doAfterBody

public int doAfterBody()
                throws javax.servlet.jsp.JspException
Specified by:
doAfterBody in interface javax.servlet.jsp.tagext.IterationTag
Overrides:
doAfterBody in class javax.servlet.jsp.tagext.BodyTagSupport
Throws:
javax.servlet.jsp.JspException

createThumbnailFromSessionAttribute

public static String createThumbnailFromSessionAttribute(String sessionAttrName)
                                                  throws Exception
Parameters:
sessionAttrName - the name of session attribute Map object in which all options were stored
Returns:
relative thumbnail path if the thumbnail was created, null otherwise
Throws:
Exception - if option 'urlStr' (from option map) could not be converted to URL

invalidateCacheAttemptThumbnail

public static void invalidateCacheAttemptThumbnail(FileDocument fileDoc,
                                                   File srcFile,
                                                   URL url)
Invalidates the cache of failure while attempt to create a thumbnail for the given parameter. If not null, the key in the cache is for the FileDocument, otherwise, for the srcFile, otherwise for the file with given URL.

Parameters:
fileDoc - the FileDocument to invalidate cache thumbnail generation failure
srcFile - the file to invalidate the cache
url - the URL of the file to invalidate the cache
Since:
jcms-6.1.2

buildThumbnail

public static File buildThumbnail(File srcFile,
                                  int width,
                                  int height,
                                  File defaultFile,
                                  String background)
Returns a Thumbnail for the given path. If thumbnail do not exists then create it.

Warning : This method does not use any cache for failed attemps and may not meet performance requirements of frequent use. Use method createThumbnail(FileDocument, File, URL, ImageFormat, int, int) instead.

Parameters:
srcFile - the original file
width - target max width
height - target max width
defaultFile - the default file to use if thumbnail do not exists
background - the background color (eg "FFFFFF") if sets the image dimension will be set maxWidth and maxHeight
Returns:
File the thumbnail file

buildThumbnail

public static String buildThumbnail(String path,
                                    int width,
                                    int height,
                                    String defaultPath)
See Also:
buildThumbnail(String, int, int, String, String)

buildThumbnail

public static String buildThumbnail(String path,
                                    int width,
                                    int height,
                                    String defaultPath,
                                    String background)
Returns a Thumbnail for the given path. If thumbnail do not exists then create it.

Warning : This method does not use any cache for failed attemps and may not meet performance requirements of frequent use. Use method createThumbnail(FileDocument, File, URL, ImageFormat, int, int) instead.

Parameters:
path - Relative path to the original file
width - target max width
height - target max width
defaultPath - the default image to use if thumbnail do not exists
background - the background color (eg "FFFFFF") if sets the image dimension will be set maxWidth and maxHeight
Returns:
String relative path to the thumbnail

createThumbnail

public static File createThumbnail(FileDocument fileDoc,
                                   File srcFile,
                                   URL url,
                                   ImageFormat format,
                                   int maxWidth,
                                   int maxHeight)
See Also:
createThumbnail(FileDocument, File, URL, ImageFormat, int, int, String)

createThumbnail

public static File createThumbnail(FileDocument fileDoc,
                                   File srcFile,
                                   URL url,
                                   ImageFormat format,
                                   int maxWidth,
                                   int maxHeight,
                                   String background)
Create a thumbnail using the first valid source from FileDocument, File or URL using given dimensions.

For performance reason, if a previous thumbnail creation attempt failed for the specified source, this method will not perform any creation until the delay specified by property "tag.thumbnail.failed-attempt-check-delay" has been reached (or if site is restarted).
Be careful though that this method is not asynchronous and thus may take some time to process if thumbnail creation processing is long.

Parameters:
fileDoc - a FileDocument of which to create thumbnail
srcFile - a File of which to create thumbnail
url - an URL of which to create thumbnail
format - the ImageFormat of the file to generate (default to JPEG if null)
maxWidth - the maximum width of the thumbnail to generate
maxHeight - the maximum height of the thumbnail to generate
background - the background color (eg "FFFFFF") if sets the image dimension will be set maxWidth and maxHeight
Returns:
the thumbnail file on success, or null if the thumbnail could not be created.
Since:
jcms-6.1

getThumbnailFile

public static File getThumbnailFile(FileDocument fileDoc,
                                    File srcFile,
                                    URL url,
                                    int maxWidth,
                                    int maxHeight)
Gets the File to use for a thumbnail of the given FileDocument, File or URL using given dimensions.

Parameters:
fileDoc - a FileDocument of which to create thumbnail
srcFile - a File of which to create thumbnail
url - an URL of which to create thumbnail
maxWidth - the maximum width of the thumbnail, a positive integer.
maxHeight - the maximum height of the thumbnail, a positive integer.
Returns:
a File representing the thumbnail filename or null if none could be computed.
Since:
jcms-6.1

createThumbnailNow

public static boolean createThumbnailNow(FileDocument fileDoc,
                                         File srcFile,
                                         URL url,
                                         ImageFormat format,
                                         int maxWidth,
                                         int maxHeight,
                                         File destFile)
See Also:
createThumbnailNow(FileDocument, File, URL, ImageFormat, int, int, File, String)

createThumbnailNow

public static boolean createThumbnailNow(FileDocument fileDoc,
                                         File srcFile,
                                         URL url,
                                         ImageFormat format,
                                         int maxWidth,
                                         int maxHeight,
                                         File destFile,
                                         String background)
This method create a thumbnail of one of the three source given using the options passed as parameters ("now" as opposed to generation when going through ajax}.

Warning : This method does not use any cache for failed attemps and may not meet performance requirements of frequent use. Use method createThumbnail(FileDocument, File, URL, ImageFormat, int, int) instead. Possible sources are (only of must be passed, other must be null) :

Parameters:
fileDoc - a FileDocument of which to create thumbnail
srcFile - a File of which to create thumbnail
url - an URL of which to create thumbnail
format - the ImageFormat of the file to generate (default to JPEG if null)
maxWidth - the maximum width of the thumbnail to generate
maxHeight - the maximum height of the thumbnail to generate
destFile - destination file (of the thumbnail to generate)
background - the background color (eg "FFFFFF") if sets the image dimension will be set maxWidth and maxHeight
Returns:
true on success, or false if the thumbnail could not be created
See Also:
PolicyManager.createThumbnail(FileDocument, File, ImageFormat, int, int, String), PolicyManager.createThumbnail(File, File, ImageFormat, int, int, String), PolicyManager.createThumbnail(URL, File, ImageFormat, int, int, String)

createImageThumbnail

public static boolean createImageThumbnail(File imageFile,
                                           File dest,
                                           ImageFormat format,
                                           int maxWidth,
                                           int maxHeight)
See Also:
createImageThumbnail(File, File, ImageFormat, int, int, String)

createImageThumbnail

public static boolean createImageThumbnail(File imageFile,
                                           File dest,
                                           ImageFormat format,
                                           int maxWidth,
                                           int maxHeight,
                                           String background)
This method creates a thumbnail of the given image source file.

Parameters:
imageFile - image file of which to create a thumbnail
dest - destination file (the thumbnail to generate)
format - the format of the file to generate as requested by the ThumbnailTag
maxWidth - the maximum width of the thumbnail to generate
maxHeight - the maximum height of the thumbnail to generate
background - the background color (eg "FFFFFF") if sets the image dimension will be set maxWidth and maxHeight
Returns:
true on success, or false if the thumbnail could not be created
See Also:
ImageUtil.createThumbnail(File, ImageFormat, int, int)

createOpenOfficeThumbnail

public static boolean createOpenOfficeThumbnail(File docFile,
                                                File dest,
                                                ImageFormat format,
                                                int maxWidth,
                                                int maxHeight,
                                                String background)
This method creates a thumbnail of the given Open Office file.

Parameters:
docFile - Open Office file of which to create a thumbnail
dest - destination file (the thumbnail to generate)
format - the format of the file to generate as requested by the ThumbnailTag
maxWidth - the maximum width of the thumbnail to generate
maxHeight - the maximum height of the thumbnail to generate
background - the background color (eg "FFFFFF") if sets the image dimension will be set maxWidth and maxHeight
Returns:
true on success, or false if the thumbnail could not be created
See Also:
ImageUtil.createThumbnail(File, ImageFormat, int, int)

createOpenXmlThumbnail

public static boolean createOpenXmlThumbnail(File docFile,
                                             File dest,
                                             ImageFormat format,
                                             int maxWidth,
                                             int maxHeight,
                                             String background)
This method creates a thumbnail of the given OpenXml file.

Parameters:
docFile - Open Office file of which to create a thumbnail
dest - destination file (the thumbnail to generate)
format - the format of the file to generate as requested by the ThumbnailTag
maxWidth - the maximum width of the thumbnail to generate
maxHeight - the maximum height of the thumbnail to generate
background - the background color (eg "FFFFFF") if sets the image dimension will be set maxWidth and maxHeight
Returns:
true on success, or false if the thumbnail could not be created
See Also:
ImageUtil.createThumbnail(File, ImageFormat, int, int)


Copyright © 2001-2010 Jalios SA. All Rights Reserved.