Class ThumbnailTag

  • All Implemented Interfaces:
    JcmsConstants, JaliosConstants, java.io.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
    Author:
    Olivier Jaquemet
    See Also:
    Serialized Form
    • Constructor Detail

      • ThumbnailTag

        public ThumbnailTag()
    • Method Detail

      • clean

        protected void clean()
      • setData

        public void setData​(Data data)
      • setFile

        public void setFile​(java.io.File file)
      • setPath

        public void setPath​(java.lang.String path)
      • setUrl

        public void setUrl​(java.lang.String purl)
      • setFormat

        public void setFormat​(java.lang.String format)
      • setWidth

        public void setWidth​(int width)
      • setHeight

        public void setHeight​(int height)
      • setDestination

        public void setDestination​(java.lang.String path)
      • setBackground

        public void setBackground​(java.lang.String background)
      • setSquare

        public void setSquare​(boolean square)
      • setForceUpdate

        public void setForceUpdate​(boolean forceUpdate)
      • setAlt

        public void setAlt​(java.lang.String alt)
      • setCss

        public void setCss​(java.lang.String css)
      • setHtmlAttributes

        public void setHtmlAttributes​(java.lang.String htmlAttributes)
      • setUseAjaxLoading

        public void setUseAjaxLoading​(boolean useAjaxLoading)
      • setAjaxLoadingImage

        public void setAjaxLoadingImage​(java.lang.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
      • 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 java.lang.String createThumbnailFromSessionAttribute​(java.lang.String sessionAttrName)
                                                                    throws java.lang.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:
        java.lang.Exception - if option 'urlStr' (from option map) could not be converted to URL
      • invalidateCacheAttemptThumbnail

        public static void invalidateCacheAttemptThumbnail​(FileDocument fileDoc,
                                                           java.io.File srcFile,
                                                           java.net.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 java.io.File buildThumbnail​(java.io.File srcFile,
                                                  int width,
                                                  int height,
                                                  java.io.File defaultFile,
                                                  java.lang.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 java.lang.String buildThumbnail​(java.lang.String path,
                                                      int width,
                                                      int height,
                                                      java.lang.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(String, int, int, String, String)
      • buildThumbnail

        public static java.lang.String buildThumbnail​(java.lang.String path,
                                                      int width,
                                                      int height,
                                                      java.lang.String defaultPath,
                                                      java.lang.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 java.io.File createThumbnail​(FileDocument fileDoc,
                                                   java.io.File srcFile,
                                                   java.net.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(FileDocument, File, URL, ImageFormat, int, int, String)
      • createThumbnail

        public static java.io.File createThumbnail​(FileDocument fileDoc,
                                                   java.io.File srcFile,
                                                   java.net.URL url,
                                                   ImageFormat format,
                                                   int maxWidth,
                                                   int maxHeight,
                                                   java.lang.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 java.io.File createThumbnail​(FileDocument fileDoc,
                                                   java.io.File srcFile,
                                                   java.net.URL url,
                                                   ImageFormat format,
                                                   int maxWidth,
                                                   int maxHeight,
                                                   java.lang.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
      • getThumbnailFile

        public static java.io.File getThumbnailFile​(FileDocument fileDoc,
                                                    java.io.File srcFile,
                                                    java.net.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 java.io.File getThumbnailFile​(FileDocument fileDoc,
                                                    java.io.File srcFile,
                                                    java.net.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 java.io.File getThumbnailFile​(FileDocument fileDoc,
                                                    java.io.File srcFile,
                                                    java.net.URL url,
                                                    int maxWidth,
                                                    int maxHeight,
                                                    boolean square,
                                                    java.lang.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
      • createImageThumbnail

        public static boolean createImageThumbnail​(java.io.File imageFile,
                                                   java.io.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(File, File, ImageFormat, int, int, String)
      • createImageThumbnail

        public static boolean createImageThumbnail​(java.io.File imageFile,
                                                   java.io.File dest,
                                                   ImageFormat format,
                                                   int maxWidth,
                                                   int maxHeight,
                                                   java.lang.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)
      • createImageThumbnail

        public static boolean createImageThumbnail​(java.io.File imageFile,
                                                   java.io.File dest,
                                                   ImageFormat format,
                                                   int maxWidth,
                                                   int maxHeight,
                                                   java.lang.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:
        ImageUtil.createThumbnail(File, ImageFormat, int, int)
      • createOpenOfficeThumbnail

        public static boolean createOpenOfficeThumbnail​(java.io.File docFile,
                                                        java.io.File dest,
                                                        ImageFormat format,
                                                        int maxWidth,
                                                        int maxHeight,
                                                        java.lang.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:
        ImageUtil.createThumbnail(File, ImageFormat, int, int)
      • createOpenXmlThumbnail

        public static boolean createOpenXmlThumbnail​(java.io.File docFile,
                                                     java.io.File dest,
                                                     ImageFormat format,
                                                     int maxWidth,
                                                     int maxHeight,
                                                     java.lang.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:
        ImageUtil.createThumbnail(File, ImageFormat, int, int)