Class WCMUtils


  • public class WCMUtils
    extends java.lang.Object
    The CMUtils class provides utility methods for various aspects of the Core WCM system.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEBUG_PARAM
      debug parameter name
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Component getComponent​(Resource resource)
      Returns the component according to the type of the resource or null if no such component exists.
      static ComponentContext getComponentContext​(ServletRequest request)
      Returns the component context for the given request or null if not defined.
      static java.lang.String getInheritedProperty​(Page page, ResourceResolver resolver, java.lang.String name)
      Returns the content property of the given page.
      static java.lang.String getKeywords​(Page page)
      Returns a comma-separated list of keywords for the given page, based on the titles of the tags set on the page.
      static java.lang.String getKeywords​(Page page, boolean onlyLocalized)
      Returns a comma-separated list of keywords for the given page, based on the titles of the tags set on the page.
      static Node getNode​(Resource resource)
      Returns a node for the given resource.
      static Style getStyle​(SlingHttpServletRequest request)
      Returns the style for the given request.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEBUG_PARAM

        public static final java.lang.String DEBUG_PARAM
        debug parameter name
        See Also:
        Constant Field Values
    • Method Detail

      • getComponent

        public static Component getComponent​(Resource resource)
        Returns the component according to the type of the resource or null if no such component exists. This is a pure convenience method retrieving the component manager and invoking ComponentManager.getComponentOfResource(Resource).
        Parameters:
        resource - to resolve
        Returns:
        the respective component or null
      • getInheritedProperty

        public static java.lang.String getInheritedProperty​(Page page,
                                                            ResourceResolver resolver,
                                                            java.lang.String name)
        Returns the content property of the given page. If the page does not contain this property, the page's parent's property is returned or null if the page has no parent.

        Note that the standard "pageProperties" variable defined by the <cq:defineObjects/> tag is now (since CQ 5.4) an InheritanceValueMap that provides getInherited(String, Class) and getInherited(String, Object) to search for those properties in parent pages if not found locally.

        Parameters:
        page - the page to retrieve the property from
        resolver - for resolving parent pages
        name - the property name
        Returns:
        the property value or null
      • getStyle

        public static Style getStyle​(SlingHttpServletRequest request)
        Returns the style for the given request. It's a convenience method that retrieves the respective page of the request resource, resolves its design, extracts the cell path and retrieves the style. A design and cell path can be specified '/-/' delimited as suffix. the design path only needs to include the part after the /etc/designs. eg: ...img.png/geometrixx/-/par/image
        Parameters:
        request - the request
        Returns:
        the style or null
      • getComponentContext

        public static ComponentContext getComponentContext​(ServletRequest request)
        Returns the component context for the given request or null if not defined.
        Parameters:
        request - servlet request
        Returns:
        component context or null
      • getNode

        public static Node getNode​(Resource resource)
        Returns a node for the given resource. If the node does not exist, returns null
        Parameters:
        resource - resource to adapt to node
        Returns:
        the node or null
      • getKeywords

        public static java.lang.String getKeywords​(Page page)
        Returns a comma-separated list of keywords for the given page, based on the titles of the tags set on the page. Useful for the <meta keywords> element in HTML.

        Since CQ 5.4, this returns localized tag titles based on the page language or the default title if no localized title exists for that language. This is essentially the same as getKeywords(page, false).

        Parameters:
        page - wcm page
        Returns:
        comma-separated list of keywords
      • getKeywords

        public static java.lang.String getKeywords​(Page page,
                                                   boolean onlyLocalized)
        Returns a comma-separated list of keywords for the given page, based on the titles of the tags set on the page. Useful for the <meta keywords> element in HTML.

        Returns localized tag titles based on the page language. A boolean flag allows to choose if only localized titles shall be returned or if it is ok to fallback to the default title in case no localized title exists for a given tag.

        Parameters:
        page - wcm page
        onlyLocalized - if only keywords should be returned that have a localized variant for the given page locale
        Returns:
        comma-separated list of keywords
        Since:
        5.4