Class MobileUtil


  • public class MobileUtil
    extends java.lang.Object
    The MobileUtil provides various utility methods revolving around WCM Mobile.
    • Constructor Detail

      • MobileUtil

        public MobileUtil()
    • Method Detail

      • isDeviceGroup

        public static boolean isDeviceGroup​(Resource resource)
        Checks whether the given Resource represents a WCM Mobile Device Group. Resource that match the resource type DeviceGroup.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
      • 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 - The SlingHttpServletRequest to retrieve selectors from.
        Returns:
        A String representing the selector or null if not found.
      • hasCapability

        public static boolean hasCapability​(SlingHttpServletRequest request,
                                            DeviceCapability capability)
        This method retrieves the DeviceGroup from the current request and checks the group whether it offers the given capability.
        Parameters:
        request - The current request.
        capability - The DeviceCapability 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 type MobileConstants.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 type MobileConstants.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)