Package com.day.cq.wcm.foundation.forms
Class FormResourceEdit
- java.lang.Object
-
- com.day.cq.wcm.foundation.forms.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FormResourceEdit.CommonAndPartial
Helper struct for the result ofgetCommonAndPartialMultiValues(List, String)
.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
REOPEN_PARAM
static java.lang.String
RESOURCES_ATTRIBUTE
static java.lang.String
RESOURCES_PARAM
static java.lang.String
WRITE_SUFFIX
-
Constructor Summary
Constructors Constructor Description FormResourceEdit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FormResourceEdit.CommonAndPartial
getCommonAndPartialMultiValues(java.util.List<Resource> resources, java.lang.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.static Resource
getMergedResource(java.util.List<Resource> resources)
Retrieves a resource that presents a synthetic resource with merged values for all the given resources.static java.lang.String
getPostResourcePath(SlingHttpServletRequest request)
Returns the (unvalidated) path of the single resource that is target of the form POST request.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.static java.util.List<Resource>
getResources(ServletRequest req)
Get the list of resources to be handled by the "edit" resources form action.static boolean
isMultiResource(ServletRequest req)
Returns if multiple resources are handled by the "edit" resource form action.static boolean
isMultiResourcePost(SlingHttpServletRequest request)
Returns whether the given form POST based on the "edit" resource action targets multiple resources.static boolean
isSingleResource(ServletRequest req)
Returns if exactly a single resource is handled by the "edit" resource form action.static boolean
isSingleResourcePost(SlingHttpServletRequest request)
Returns whether the given form POST based on the "edit" resource action targets a single resource.static void
multiPost(java.util.List<Resource> resources, SlingHttpServletRequest request, SlingHttpServletResponse response)
Performs a Sling POST servlet modify operation, but on multiple resources.static void
setResources(ServletRequest req, java.util.List<Resource> resources)
Sets the list of resources to be handled by the "edit" resources form action.
-
-
-
Field Detail
-
RESOURCES_ATTRIBUTE
public static final java.lang.String RESOURCES_ATTRIBUTE
- See Also:
- Constant Field Values
-
RESOURCES_PARAM
public static final java.lang.String RESOURCES_PARAM
- See Also:
- Constant Field Values
-
REOPEN_PARAM
public static final java.lang.String REOPEN_PARAM
- See Also:
- Constant Field Values
-
WRITE_SUFFIX
public static final java.lang.String WRITE_SUFFIX
- See Also:
- Constant Field Values
-
-
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 requestresources
- 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. UsesMergedValueMap
.- Parameters:
resources
- list of resources to merge- Returns:
- a synthetic resource with merged values
-
getCommonAndPartialMultiValues
public static FormResourceEdit.CommonAndPartial getCommonAndPartialMultiValues(java.util.List<Resource> resources, java.lang.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. TheFormResourceEdit.CommonAndPartial.common
values will be the ones that are present in the property in all resources, whereas theFormResourceEdit.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 resourcesname
- the name of the multi-value property to inspect- Returns:
- a struct object with the
FormResourceEdit.CommonAndPartial.common
andFormResourceEdit.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 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 returnnull
.- 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-editrequest
- current POST request, including the parameters for the Sling POST servletresponse
- current response- Throws:
ServletException
- if post failsjava.io.IOException
- if post fails
-
-