Class FormResourceEdit

java.lang.Object
com.day.cq.wcm.foundation.forms.FormResourceEdit

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

  • Constructor Details

    • FormResourceEdit

      public FormResourceEdit()
  • Method Details

    • setResources

      public static void setResources(ServletRequest req, 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 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(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
    • getCommonAndPartialMultiValues

      public static FormResourceEdit.CommonAndPartial getCommonAndPartialMultiValues(List<Resource> resources, String name)
      Calculates the set of common values and the set of partially present values for a multi-value property on a list of resources. The FormResourceEdit.CommonAndPartial.common values will be the ones that are present in the property in all resources, whereas the FormResourceEdit.CommonAndPartial.partial values will be the set of all values that are present at least in one resource, but not all of them. The multi-value property is seen as set, so the order and multiple occurrences of the same value in a single property do not make any difference.
      Parameters:
      resources - a list of resources
      name - the name of the multi-value property to inspect
      Returns:
      a struct object with the FormResourceEdit.CommonAndPartial.common and FormResourceEdit.CommonAndPartial.partial sets of 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 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 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(List<Resource> resources, SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, 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
      IOException - if post fails