Package com.day.cq.wcm.mobile.core
Class MobileUtil
- java.lang.Object
-
- com.day.cq.wcm.mobile.core.MobileUtil
-
public class MobileUtil extends java.lang.ObjectTheMobileUtilprovides various utility methods revolving around WCM Mobile.
-
-
Constructor Summary
Constructors Constructor Description MobileUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DeviceGroupgetDefaultDeviceGroup(Page page)This method finds the device groups currently assigned to the given page or its closest ancestor.static java.lang.StringgetDeviceGroupSelector(SlingHttpServletRequest request)Returns the last selector found in the request URL.static booleanhasCapability(SlingHttpServletRequest request, DeviceCapability capability)This method retrieves theDeviceGroupfrom the current request and checks the group whether it offers the givencapability.static booleanisDeviceGroup(Page page)Checks whether the givenPagerepresents a WCM Mobile Device Group.static booleanisDeviceGroup(Resource resource)Checks whether the givenResourcerepresents a WCM Mobile Device Group.static booleanisMobileRequest(SlingHttpServletRequest r)True if the request's user agent is a mobile device.static booleanisMobileResource(Resource r)True if given resource's parent page (or page itself) or any of its parent pages is based on the mobile resource typeMobileConstants.MOBILE_BASE_RESOURCE_TYPE.static booleanisMobileResource(Resource r, java.lang.String[] types)True if given resource's parent page (or page itself) or any of its parent pages is based on the mobile resource typeMobileConstants.MOBILE_BASE_RESOURCE_TYPEor any other type provided in the types array.static booleanisNoMatch(java.lang.String[] selectors)static booleanisPreventRedirect(Resource r)Checks if the given resource prevents redirection
-
-
-
Method Detail
-
isDeviceGroup
public static boolean isDeviceGroup(Resource resource)
Checks whether the givenResourcerepresents a WCM Mobile Device Group. Resource that match the resource typeDeviceGroup.RESOURCE_TYPEare considered device groups.- Parameters:
resource- The resource to check.- Returns:
trueif the resource is in fact a device group.- See Also:
DeviceGroup
-
isDeviceGroup
public static boolean isDeviceGroup(Page page)
Checks whether the givenPagerepresents a WCM Mobile Device Group. The check is performed on the page's content resource.- Parameters:
page- The page to check.- Returns:
trueif the page is in fact a device group.- See Also:
isDeviceGroup(org.apache.sling.api.resource.Resource),DeviceGroup
-
getDefaultDeviceGroup
public static DeviceGroup getDefaultDeviceGroup(Page page)
This method finds the device groups currently assigned to the given page or its closest ancestor. From the assigned device groups, the first group is returned.- Parameters:
page- The page to check for device group mappings.- Returns:
- The first
DeviceGroup.
-
getDeviceGroupSelector
public static java.lang.String getDeviceGroupSelector(SlingHttpServletRequest request)
Returns the last selector found in the request URL. Within a mobile site context, this selector usually defines the device group name for the active device group.- Parameters:
request- TheSlingHttpServletRequestto retrieve selectors from.- Returns:
- A
Stringrepresenting the selector ornullif not found.
-
hasCapability
public static boolean hasCapability(SlingHttpServletRequest request, DeviceCapability capability)
This method retrieves theDeviceGroupfrom the current request and checks the group whether it offers the givencapability.- Parameters:
request- The current request.capability- TheDeviceCapabilityto check for.- Returns:
trueif the current device group offers the capability.
-
isMobileRequest
public static boolean isMobileRequest(SlingHttpServletRequest r)
True if the request's user agent is a mobile device. The user agent header is matched for "Mobile" and "Blackberry".- Parameters:
r- The request to check.- Returns:
trueif this is a mobile request.
-
isMobileResource
public static boolean isMobileResource(Resource r)
True if given resource's parent page (or page itself) or any of its parent pages is based on the mobile resource typeMobileConstants.MOBILE_BASE_RESOURCE_TYPE.- Parameters:
r- The resource to check, may be null.- Returns:
trueif this resource is a mobile resource.
-
isMobileResource
public static boolean isMobileResource(Resource r, java.lang.String[] types)
True if given resource's parent page (or page itself) or any of its parent pages is based on the mobile resource typeMobileConstants.MOBILE_BASE_RESOURCE_TYPEor any other type provided in the types array.- Parameters:
r- The resource to check, may be null.types- The additional resource types to check. May be null.- Returns:
trueif this resource is a mobile resource.
-
isPreventRedirect
public static boolean isPreventRedirect(Resource r)
Checks if the given resource prevents redirection- Parameters:
r- resource- Returns:
trueif redirection is prevented
-
isNoMatch
public static boolean isNoMatch(java.lang.String[] selectors)
-
-