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.Object
TheMobileUtil
provides 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 DeviceGroup
getDefaultDeviceGroup(Page page)
This method finds the device groups currently assigned to the given page or its closest ancestor.static java.lang.String
getDeviceGroupSelector(SlingHttpServletRequest request)
Returns the last selector found in the request URL.static boolean
hasCapability(SlingHttpServletRequest request, DeviceCapability capability)
This method retrieves theDeviceGroup
from the current request and checks the group whether it offers the givencapability
.static boolean
isDeviceGroup(Page page)
Checks whether the givenPage
represents a WCM Mobile Device Group.static boolean
isDeviceGroup(Resource resource)
Checks whether the givenResource
represents a WCM Mobile Device Group.static boolean
isMobileRequest(SlingHttpServletRequest r)
True if the request's user agent is a mobile device.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
.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_TYPE
or any other type provided in the types array.static boolean
isNoMatch(java.lang.String[] selectors)
static boolean
isPreventRedirect(Resource r)
Checks if the given resource prevents redirection
-
-
-
Method Detail
-
isDeviceGroup
public static boolean isDeviceGroup(Resource resource)
Checks whether the givenResource
represents a WCM Mobile Device Group. Resource that match the resource typeDeviceGroup.RESOURCE_TYPE
are considered device groups.- Parameters:
resource
- The resource to check.- Returns:
true
if the resource is in fact a device group.- See Also:
DeviceGroup
-
isDeviceGroup
public static boolean isDeviceGroup(Page page)
Checks whether the givenPage
represents a WCM Mobile Device Group. The check is performed on the page's content resource.- Parameters:
page
- The page to check.- Returns:
true
if 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
- TheSlingHttpServletRequest
to retrieve selectors from.- Returns:
- A
String
representing the selector ornull
if not found.
-
hasCapability
public static boolean hasCapability(SlingHttpServletRequest request, DeviceCapability capability)
This method retrieves theDeviceGroup
from the current request and checks the group whether it offers the givencapability
.- Parameters:
request
- The current request.capability
- TheDeviceCapability
to check for.- Returns:
true
if 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:
true
if 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:
true
if 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_TYPE
or 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:
true
if this resource is a mobile resource.
-
isPreventRedirect
public static boolean isPreventRedirect(Resource r)
Checks if the given resource prevents redirection- Parameters:
r
- resource- Returns:
true
if redirection is prevented
-
isNoMatch
public static boolean isNoMatch(java.lang.String[] selectors)
-
-