Class ThumbnailTag

java.lang.Object
javax.servlet.jsp.tagext.TagSupport
javax.servlet.jsp.tagext.BodyTagSupport
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 possibility 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
Author:
Olivier Jaquemet
See Also:
  • Field Details

  • Constructor Details

    • ThumbnailTag

      public ThumbnailTag()
  • Method Details

    • 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)
    • setSquare

      public void setSquare(boolean square)
    • 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)
    • setAddChannelBaseUrl

      public void setAddChannelBaseUrl(boolean addChannelBaseUrl)
    • setDataAttribute

      public void setDataAttribute(DataAttribute dataAttribute)
    • 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
    • isSmallImage

      public static boolean isSmallImage(FileDocument fileDoc)
    • isSmallImage

      public static boolean isSmallImage(long width, long height)
    • 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
    • setLazy

      public void setLazy(boolean lazy)
    • 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)
      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
      Returns:
      String relative path to the thumbnail
      See Also:
    • 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)
      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
      Returns:
      the thumbnail file on success, or null if the thumbnail could not be created.
      See Also:
    • 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
    • createThumbnail

      public static File createThumbnail(FileDocument fileDoc, File srcFile, URL url, ImageFormat format, int maxWidth, int maxHeight, String background, boolean square)
      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 the format specified in property "tag.thumbnail.format" 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
      square - set to true to crop image into a square using the specified width during thumbnail creation.
      Returns:
      the thumbnail file on success, or null if the thumbnail could not be created.
      Since:
      jcms-9.0
    • getDefaultImageFormat

      public static ImageFormat getDefaultImageFormat(FileDocument fileDoc, File srcFile, URL url)
      Retrieve the default format to use for the specified source if none was specified
      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
      Returns:
      an ImageFormat, never return null
    • 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
    • getThumbnailFile

      public static File getThumbnailFile(FileDocument fileDoc, File srcFile, URL url, int maxWidth, int maxHeight, boolean square)
      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.
      square - set to true to indicate image is cropped into a square
      Returns:
      a File representing the thumbnail filename or null if none could be computed.
      Since:
      jcms-9.0
    • getThumbnailFile

      public static File getThumbnailFile(FileDocument fileDoc, File srcFile, URL url, int maxWidth, int maxHeight, boolean square, String extension)
      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.
      square - set to true to indicate image is cropped into a square
      extension - the extension of the thumbnail format being create/generated/manipulated. eg "jpg"
      This value is not used when generating URL. See property tag.thumbnail.thumbshot.file-ext.
      Returns:
      a File representing the thumbnail filename or null if none could be computed.
      Since:
      jcms-10.0.1 JCMS-4762
    • createThumbnailNow

      public static boolean createThumbnailNow(FileDocument fileDoc, File srcFile, URL url, ImageFormat format, int maxWidth, int maxHeight, File destFile)
      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)
      Returns:
      true on success, or false if the thumbnail could not be created
      See Also:
    • 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:
    • createThumbnailNow

      public static boolean createThumbnailNow(FileDocument fileDoc, File srcFile, URL url, ImageFormat format, int maxWidth, int maxHeight, File destFile, String background, boolean square)
      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
      square - set to true to crop image into a square using the specified width during thumbnail creation.
      Returns:
      true on success, or false if the thumbnail could not be created
      Since:
      jcms-9.0
      See Also:
    • createImageThumbnail

      public static boolean createImageThumbnail(File imageFile, File dest, ImageFormat format, int maxWidth, int maxHeight)
      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
      Returns:
      true on success, or false if the thumbnail could not be created
      See Also:
    • 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:
    • createImageThumbnail

      public static boolean createImageThumbnail(File imageFile, File dest, ImageFormat format, int maxWidth, int maxHeight, String background, boolean square)
      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
      square - set to true to crop image into a square using the specified width during thumbnail creation.
      Returns:
      true on success, or false if the thumbnail could not be created
      Since:
      jcms-9.0
      See Also:
    • createOpenOfficeThumbnail

      public static boolean createOpenOfficeThumbnail(File docFile, File dest, ImageFormat format, int maxWidth, int maxHeight, String background, boolean square)
      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
      square - set to true to crop image into a square using the specified width during thumbnail creation.
      Returns:
      true on success, or false if the thumbnail could not be created
      See Also:
    • createOpenXmlThumbnail

      public static boolean createOpenXmlThumbnail(File docFile, File dest, ImageFormat format, int maxWidth, int maxHeight, String background, boolean square)
      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
      square - set to true to crop image into a square using the specified width during thumbnail creation.
      Returns:
      true on success, or false if the thumbnail could not be created
      See Also: