Package com.day.cq.dam.commons.util
Class UIHelper
- java.lang.Object
-
- com.day.cq.dam.commons.util.UIHelper
-
public class UIHelper extends java.lang.Object
This class provides various utility methods pertaining to DAM required in presentation/user interface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UIHelper.ActionRelsRequestProperties
static class
UIHelper.ActionRelsResourceProperties
Structs for specifying action rel filters Want to create bitmaps for fast comparison.static class
UIHelper.ActionRelsUserProperties
-
Constructor Summary
Constructors Constructor Description UIHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static boolean
canRenderOnWeb(java.lang.String mimeType)
Returns true if the given mime type can be rendered in HTML by browser.static Privilege[]
getAllPermission(AccessControlManager acm, Resource res)
returns the privileges the session has for the given resourcestatic java.lang.String
getAltText(Resource resource)
Returns alternate text that is to be used in place of the image when displaying the resource's thumbnailstatic 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 assetsstatic java.util.List<java.lang.String>
getAssetActionRels(UIHelper.ActionRelsResourceProperties resource, UIHelper.ActionRelsUserProperties user, UIHelper.ActionRelsRequestProperties request)
Returns list of actions rels string for assetsstatic Rendition
getBestfitRendition(Asset asset, int width)
Returns best fit rendition, whose width is nearer to given width.static Rendition
getBestFitRendtionBasedOnSize(Asset asset, long size)
Returns best fit rendition, whose size is nearer to given size.static Rendition
getBestFitRendtionBasedOnSize(Asset asset, long size, boolean preferOriginal)
Returns best fit rendition, whose size is nearer to given size.static long
getCacheKiller(Node node)
Returns the cache killer number that can be appended the resource request.static java.lang.String
getCheckedOutby(Asset asset)
static Resource
getCurrentSuffixResource(SlingHttpServletRequest request)
returns the resource represented by the suffix.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)
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 directoriesstatic 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 0static java.lang.String
getResolutionLabel(long width, long height, SlingHttpServletRequest slingRequest)
Display resolution with correct i18n number formattingstatic java.lang.String
getSizeLabel(double size)
Adds units to given size in bytes and create label to be displayed in UIstatic 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.static java.lang.String
getTitle(Resource res)
Returns the title of a resource.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 0static boolean
hasPermission(AccessControlManager acm, Resource res, java.lang.String privilege)
returns whether the given resource has the permission to perform the privileged actionstatic boolean
isCheckedOutByDrive(Asset asset)
Returns true, if an asset is checked out by drive.static boolean
isEditSupportedFormat(java.lang.String mimetype)
returns whether Interactive Edit(crop/rotate) operations are supported on the given mimetypestatic java.lang.String
lookupMimeType(java.lang.String mimeType, Node node, boolean uppercase)
Deprecated.static java.lang.String
lookupMimeType(java.lang.String mimeType, Resource resource, boolean uppercase)
does a lookup for the given mimetype in the given resource.
-
-
-
Method Detail
-
getTitle
public static java.lang.String getTitle(Resource res)
Returns the title of a resource. returnsdc:title
metadata property is return if resource represents a DAM asset returns Page title if the resource represents acq:Page
returns title if it is aLabeledResource
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 assetwidth
- 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
- widthheight
- heightslingRequest
- 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 permissionsres
- resourceprivilege
- action, wanted to perform on the res- Returns:
- true if user has the permission, otherwise false
- Throws:
RepositoryException
-
getAllPermission
public static Privilege[] getAllPermission(AccessControlManager acm, Resource res) throws PathNotFoundException, RepositoryException
returns the privileges the session has for the given resource- Parameters:
acm
- AccessControlManager to determine the permissionsres
- resource- Returns:
- returns the privileges for the resource
- Throws:
RepositoryException
PathNotFoundException
-
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 assetsize
- 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 assetsize
- size in KBpreferOriginal
- 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(UIHelper.ActionRelsResourceProperties resource, UIHelper.ActionRelsUserProperties user, UIHelper.ActionRelsRequestProperties request)
Returns list of actions rels string for assets- Parameters:
resource
- - properties of the resource in questionuser
- - properties of the current principalrequest
- - properties of the request itself
-
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 flaghasJcrWrite
- hasJcrWrite flaghasAddChild
- hasAddChild flagcanEdit
- canEdit flagcanAnnotate
- canAnnotate flagisAdmin
- isAdmin flagisAssetExpired
- isAssetExpired flagisSubAssetExpired
- isSubAssetExpired flagisContentFragment
- isContentFragment flagisArchive
- isArchive flagisSnippetTemplate
- isSnippetTemplate flagisDownloadable
- isDownloadable flagisOmniSearchRequest
- isOmniSearchRequest flagisStockAsset
- isStockAsset flagisStockAssetLicensed
- isStockAssetLicensed flagisStockAccessible
- isStockAccessible flagisLiveCopy
- 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)
Deprecated.Returns list of actions rels string for directories- Parameters:
hasJcrRead
- hasJcrRead flaghasModifyAccessControl
- hasModifyAccessControl flaghasJcrWrite
- hasJcrWrite flaghasReplicate
- hasReplicate flagisMACShared
- isMACShared flagisCCShared
- isCCShared flagisRootMACShared
- isRootMACShared flagisMPShared
- isMPShared flagisRootMPShared
- isRootMPShared flagisLiveCopy
- 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 flaghasModifyAccessControl
- hasModifyAccessControl flaghasJcrWrite
- hasJcrWrite flaghasReplicate
- hasReplicate flagisMACShared
- isMACShared flagisCCShared
- isCCShared flagisRootMACShared
- isRootMACShared flagisMPShared
- isMPShared flagisRootMPShared
- isRootMPShared flagisLiveCopy
- isLiveCopy flaghasAddChild
- Indicates if jcr:addChildNodes permission is grantedhasRemoveNode
- Indicates if jcr:removeNode permission is grantedhasModifyProperties
- Indicates if jcr:modifyProperties permission is granted- Returns:
- List of actions rels strings
-
-