Package com.day.cq.wcm.foundation.forms
Class FormResourceEdit
java.lang.Object
com.day.cq.wcm.foundation.forms.FormResourceEdit
Helper class for bulk editing of multiple resources via CQ forms and the
Sling POST servlet.
- Since:
- 5.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHelper struct for the result ofgetCommonAndPartialMultiValues(List, String). -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetCommonAndPartialMultiValues(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.static ResourcegetMergedResource(List<Resource> resources) Retrieves a resource that presents a synthetic resource with merged values for all the given resources.static StringReturns the (unvalidated) path of the single resource that is target of the form POST request.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.Get the list of resources to be handled by the "edit" resources form action.static booleanReturns if multiple resources are handled by the "edit" resource form action.static booleanReturns whether the given form POST based on the "edit" resource action targets multiple resources.static booleanReturns if exactly a single resource is handled by the "edit" resource form action.static booleanReturns whether the given form POST based on the "edit" resource action targets a single resource.static voidmultiPost(List<Resource> resources, SlingHttpServletRequest request, SlingHttpServletResponse response) Performs a Sling POST servlet modify operation, but on multiple resources.static voidsetResources(ServletRequest req, List<Resource> resources) Sets the list of resources to be handled by the "edit" resources form action.
-
Field Details
-
RESOURCES_ATTRIBUTE
- See Also:
-
RESOURCES_PARAM
- See Also:
-
REOPEN_PARAM
- See Also:
-
WRITE_SUFFIX
- See Also:
-
-
Constructor Details
-
FormResourceEdit
public FormResourceEdit()
-
-
Method Details
-
setResources
Sets the list of resources to be handled by the "edit" resources form action.- Parameters:
req- current requestresources- the list of resources
-
getResources
Get the list of resources to be handled by the "edit" resources form action.- Parameters:
req- current request- Returns:
- the list of resources (or
nullif not set)
-
getMergedResource
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(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. TheFormResourceEdit.CommonAndPartial.commonvalues will be the ones that are present in the property in all resources, whereas theFormResourceEdit.CommonAndPartial.partialvalues 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.commonandFormResourceEdit.CommonAndPartial.partialsets of values
-
isSingleResource
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
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
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
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
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
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-editrequest- current POST request, including the parameters for the Sling POST servletresponse- current response- Throws:
ServletException- if post failsIOException- if post fails
-