Class FormResourceEdit


  • public abstract class FormResourceEdit
    extends java.lang.Object
    Helper class for bulk editing of multiple resources via CQ forms and the Sling POST servlet.
    Since:
    5.5
    • Constructor Detail

      • FormResourceEdit

        public FormResourceEdit()
    • Method Detail

      • setResources

        public static void setResources​(ServletRequest req,
                                        java.util.List<Resource> resources)
        Sets the list of resources to be handled by the "edit" resources form action.
        Parameters:
        req - current request
        resources - the list of resources
      • getResources

        public static java.util.List<Resource> getResources​(ServletRequest req)
        Get the list of resources to be handled by the "edit" resources form action.
        Parameters:
        req - current request
        Returns:
        the list of resources (or null if not set)
      • getMergedResource

        public static Resource getMergedResource​(java.util.List<Resource> resources)
        Retrieves a resource that presents a synthetic resource with merged values for all the given resources. Uses MergedValueMap.
        Parameters:
        resources - list of resources to merge
        Returns:
        a synthetic resource with merged values
      • isSingleResource

        public static boolean isSingleResource​(ServletRequest req)
        Returns if exactly a single resource is handled by the "edit" resource form action.
        Parameters:
        req - current request
        Returns:
        true if a single resource is handled, false if multiple resources or no resource at all is handled
      • isMultiResource

        public static boolean isMultiResource​(ServletRequest req)
        Returns if multiple resources are handled by the "edit" resource form action.
        Parameters:
        req - current request
        Returns:
        true if multiple resources are handled, false if a single or no resource at all is handled
      • isSingleResourcePost

        public static boolean isSingleResourcePost​(SlingHttpServletRequest request)
        Returns whether the given form POST based on the "edit" resource action targets a single resource.
        Parameters:
        request - current request
        Returns:
        if a single resource is target of the POST
      • isMultiResourcePost

        public static boolean isMultiResourcePost​(SlingHttpServletRequest request)
        Returns whether the given form POST based on the "edit" resource action targets multiple resources.
        Parameters:
        request - current request
        Returns:
        if multiple resources are target of the POST
      • getPostResourcePath

        public static java.lang.String getPostResourcePath​(SlingHttpServletRequest request)
        Returns the (unvalidated) path of the single resource that is target of the form POST request. If this is not a form POST based on the "edit" resource action or if multiple resources are the target, this will return null.
        Parameters:
        request - current request
        Returns:
        path of the resource or null
      • getPostResources

        public static java.util.List<Resource> getPostResources​(SlingHttpServletRequest request)
        Returns a list of all resources that are the target of the form POST request based on the "edit" resource action, and which can actually be written to using the request session.
        Parameters:
        request - current request
        Returns:
        list with all resolved target resources
      • multiPost

        public static void multiPost​(java.util.List<Resource> resources,
                                     SlingHttpServletRequest request,
                                     SlingHttpServletResponse response)
                              throws ServletException,
                                     java.io.IOException
        Performs a Sling POST servlet modify operation, but on multiple resources.

        The Sling POST servlet (more specifically, its modify operation) itself can only handle a single resource (using the request resource) or by using absolute paths to properties. This method will automatically rewrite the parameters for the multiple resources and then call the Sling POST servlet. All resources will be changed in a single transaction. The response will look like the standard Sling POST response.

        Parameters:
        resources - list of resources to bulk-edit
        request - current POST request, including the parameters for the Sling POST servlet
        response - current response
        Throws:
        ServletException - if post fails
        java.io.IOException - if post fails