Class UIHelper


  • public class UIHelper
    extends java.lang.Object
    This class provides various utility methods pertaining to DAM required in presentation/user interface.
    • Constructor Detail

      • UIHelper

        public UIHelper()
    • Method Detail

      • getTitle

        public static java.lang.String getTitle​(Resource res)
        Returns the title of a resource. returns dc:title metadata property is return if resource represents a DAM asset returns Page title if the resource represents a cq:Page returns title if it is a LabeledResource in other cases, it returns name of the resource or jcr:title property if exists
        Parameters:
        res - a resource
        Returns:
        title of the resource
      • getBestfitRendition

        public static Rendition getBestfitRendition​(Asset asset,
                                                    int width)
        Returns best fit rendition, whose width is nearer to given width. First it tries to look for thumbnail name starting with "cq5dam.thumbnail.width". If such a perfect match is not found, then it tries to look for nearest match by looking at rendition width. If a null asset is provided, an IllegalArgumentException will be thrown.
        Parameters:
        asset - dam asset
        width - width of thumbnail in pixels
        Returns:
        Rendition best fit rendition
      • getAltText

        public static java.lang.String getAltText​(Resource resource)
        Returns alternate text that is to be used in place of the image when displaying the resource's thumbnail
        Parameters:
        resource - The resource whose alt text need to be found.
        Returns:
        The alternate text that is to be used in place of the image/thumbnail.
      • getCacheKiller

        public static long getCacheKiller​(Node node)
        Returns the cache killer number that can be appended the resource request.
        Parameters:
        node - a node
        Returns:
        a number which represent last modified timestamp of node/resource
      • getCurrentSuffixResource

        public static Resource getCurrentSuffixResource​(SlingHttpServletRequest request)
        returns the resource represented by the suffix. if the request path is assets.html/content/dam, it will return suffix represnted by /content/dam in case of invalid paths, it defaults to /content/dam
        Parameters:
        request - sling request
        Returns:
        suffix resource
      • getSizeLabel

        public static java.lang.String getSizeLabel​(double size)
        Adds units to given size in bytes and create label to be displayed in UI
        Parameters:
        size - size in bytes
        Returns:
        string label for file/asset size.
      • getSizeLabel

        public static java.lang.String getSizeLabel​(double size,
                                                    SlingHttpServletRequest slingRequest)
        Adds units to given size in bytes and create label to be displayed in UI and Internationalize the result.
        Parameters:
        size - size in bytes
        Returns:
        string label for file/asset size.
      • getResolutionLabel

        public static java.lang.String getResolutionLabel​(long width,
                                                          long height,
                                                          SlingHttpServletRequest slingRequest)
        Display resolution with correct i18n number formatting
        Parameters:
        width - width
        height - height
        slingRequest - request
        Returns:
        string label for resolution in i18n'ed format of: width x height
      • hasPermission

        public static boolean hasPermission​(AccessControlManager acm,
                                            Resource res,
                                            java.lang.String privilege)
                                     throws RepositoryException
        returns whether the given resource has the permission to perform the privileged action
        Parameters:
        acm - AccessControlManager to determine the permissions
        res - resource
        privilege - action, wanted to perform on the res
        Returns:
        true if user has the permission, otherwise false
        Throws:
        RepositoryException
      • isEditSupportedFormat

        public static boolean isEditSupportedFormat​(java.lang.String mimetype)
        returns whether Interactive Edit(crop/rotate) operations are supported on the given mimetype
        Parameters:
        mimetype -
        Returns:
      • getBestFitRendtionBasedOnSize

        public static Rendition getBestFitRendtionBasedOnSize​(Asset asset,
                                                              long size)
        Returns best fit rendition, whose size is nearer to given size.
        Parameters:
        asset - dam asset
        size - size in KB
        Returns:
        Rendition best fit rendition
      • getBestFitRendtionBasedOnSize

        public static Rendition getBestFitRendtionBasedOnSize​(Asset asset,
                                                              long size,
                                                              boolean preferOriginal)
        Returns best fit rendition, whose size is nearer to given size.
        Parameters:
        asset - dam asset
        size - size in KB
        preferOriginal - return original if size of best fit rendition is greater
        Returns:
        Rendition best fit rendition
      • canRenderOnWeb

        public static boolean canRenderOnWeb​(java.lang.String mimeType)
        Returns true if the given mime type can be rendered in HTML by browser.
        Parameters:
        mimeType -
        Returns:
      • getWidth

        public static int getWidth​(Rendition r)
        Returns the width of rendition if it is the original rendition, and has dimension metadata, or if it follows the naming convention cq5dam.[thumbnail|web].width.height.ext,else 0
        Parameters:
        r - Rendition whose width is required
        Returns:
        width if it follows the naming convention, else 0
      • getHeight

        public static int getHeight​(Rendition r)
        Returns the height of rendition if it is the original rendition, and has dimension metadata, or if it follows the naming convention cq5dam.[thumbnail|web].width.height.ext,else 0
        Parameters:
        r - Rendition whose width is required
        Returns:
        width if it follows the naming convention, else 0
      • lookupMimeType

        @Deprecated
        public static java.lang.String lookupMimeType​(java.lang.String mimeType,
                                                      Node node,
                                                      boolean uppercase)
        Deprecated.
        Please use lookupMimeType(String, Resource, boolean)
      • lookupMimeType

        public static java.lang.String lookupMimeType​(java.lang.String mimeType,
                                                      Resource resource,
                                                      boolean uppercase)
        does a lookup for the given mimetype in the given resource.
        Parameters:
        mimeType -
        resource -
        uppercase -
        Returns:
        title/description of the matched resource
      • isCheckedOutByDrive

        public static boolean isCheckedOutByDrive​(Asset asset)
        Returns true, if an asset is checked out by drive. False otherwise.
        Parameters:
        asset - Asset whose status needs to be determined
        Returns:
        True if asset is checked out by drive, false otherwise
      • getCheckedOutby

        public static java.lang.String getCheckedOutby​(Asset asset)
      • getAssetActionRels

        public static java.util.List<java.lang.String> getAssetActionRels​(boolean hasJcrRead,
                                                                          boolean hasJcrWrite,
                                                                          boolean hasAddChild,
                                                                          boolean canEdit,
                                                                          boolean canAnnotate,
                                                                          boolean isAdmin,
                                                                          boolean isAssetExpired,
                                                                          boolean isSubAssetExpired,
                                                                          boolean isContentFragment,
                                                                          boolean isArchive,
                                                                          boolean isSnippetTemplate,
                                                                          boolean isDownloadable,
                                                                          boolean isOmniSearchRequest,
                                                                          boolean isStockAsset,
                                                                          boolean isStockAssetLicensed,
                                                                          boolean isStockAccessible,
                                                                          boolean isLiveCopy)
        Returns list of actions rels string for assets
        Parameters:
        hasJcrRead - hasJcrRead flag
        hasJcrWrite - hasJcrWrite flag
        hasAddChild - hasAddChild flag
        canEdit - canEdit flag
        canAnnotate - canAnnotate flag
        isAdmin - isAdmin flag
        isAssetExpired - isAssetExpired flag
        isSubAssetExpired - isSubAssetExpired flag
        isContentFragment - isContentFragment flag
        isArchive - isArchive flag
        isSnippetTemplate - isSnippetTemplate flag
        isDownloadable - isDownloadable flag
        isOmniSearchRequest - isOmniSearchRequest flag
        isStockAsset - isStockAsset flag
        isStockAssetLicensed - isStockAssetLicensed flag
        isStockAccessible - isStockAccessible flag
        isLiveCopy - isLiveCopy flag
        Returns:
        List of actions rels strings
      • getDirectoryActionRels

        @Deprecated
        public static java.util.List<java.lang.String> getDirectoryActionRels​(boolean hasJcrRead,
                                                                              boolean hasModifyAccessControl,
                                                                              boolean hasJcrWrite,
                                                                              boolean hasReplicate,
                                                                              boolean isMACShared,
                                                                              boolean isCCShared,
                                                                              boolean isRootMACShared,
                                                                              boolean isMPShared,
                                                                              boolean isRootMPShared,
                                                                              boolean isLiveCopy)
        Returns list of actions rels string for directories
        Parameters:
        hasJcrRead - hasJcrRead flag
        hasModifyAccessControl - hasModifyAccessControl flag
        hasJcrWrite - hasJcrWrite flag
        hasReplicate - hasReplicate flag
        isMACShared - isMACShared flag
        isCCShared - isCCShared flag
        isRootMACShared - isRootMACShared flag
        isMPShared - isMPShared flag
        isRootMPShared - isRootMPShared flag
        isLiveCopy - isLiveCopy flag
        Returns:
        List of actions rels strings
      • getDirectoryActionRels

        public static java.util.List<java.lang.String> getDirectoryActionRels​(boolean hasJcrRead,
                                                                              boolean hasModifyAccessControl,
                                                                              boolean hasJcrWrite,
                                                                              boolean hasReplicate,
                                                                              boolean isMACShared,
                                                                              boolean isCCShared,
                                                                              boolean isRootMACShared,
                                                                              boolean isMPShared,
                                                                              boolean isRootMPShared,
                                                                              boolean isLiveCopy,
                                                                              boolean hasAddChild,
                                                                              boolean hasRemoveNode,
                                                                              boolean hasModifyProperties)
        Returns list of actions rels string for directories
        Parameters:
        hasJcrRead - hasJcrRead flag
        hasModifyAccessControl - hasModifyAccessControl flag
        hasJcrWrite - hasJcrWrite flag
        hasReplicate - hasReplicate flag
        isMACShared - isMACShared flag
        isCCShared - isCCShared flag
        isRootMACShared - isRootMACShared flag
        isMPShared - isMPShared flag
        isRootMPShared - isRootMPShared flag
        isLiveCopy - isLiveCopy flag
        hasAddChild - Indicates if jcr:addChildNodes permission is granted
        hasRemoveNode - Indicates if jcr:removeNode permission is granted
        hasModifyProperties - Indicates if jcr:modifyProperties permission is granted
        Returns:
        List of actions rels strings