Class AbstractPostOperation
java.lang.Object
org.apache.sling.servlets.post.impl.operations.AbstractPostOperation
- All Implemented Interfaces:
JakartaPostOperation
- Direct Known Subclasses:
CheckinOperation,CheckoutOperation,CopyOperation,DeleteOperation,ImportOperation,ModifyOperation,MoveOperation,RestoreOperation,StreamedUploadOperation
The
AbstractPostOperation class is a base implementation of the
JakartaPostOperation service interface providing actual implementations with
useful tooling and common functionality like preparing the change logs or
saving or refreshing.
As this package is not exported, if you want to use this as a base class for
custom operations you'll need to embed it in your bundles using the appropriate
bnd directive.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final JCRSupportThe JCR support provides additional functionality if the resources are backed by JCR.protected final org.slf4j.LoggerDefault loggerFields inherited from interface org.apache.sling.servlets.post.JakartaPostOperation
PROP_OPERATION_NAME, SERVICE_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voiddoRun(org.apache.sling.api.SlingJakartaHttpServletRequest request, JakartaPostResponse response, List<Modification> changes) Actually performs the desired operation filling progress into thechangeslist and preparing and further information in theresponse.protected final StringexternalizePath(org.apache.sling.api.SlingJakartaHttpServletRequest request, String path) Returns an external form of the given path prepending the context path and appending a display extension.protected Iterator<org.apache.sling.api.resource.Resource>getApplyToResources(org.apache.sling.api.SlingJakartaHttpServletRequest request) Returns an iterator onResourceinstances addressed in theSlingPostConstants.RP_APPLY_TOrequest parameter.protected StringgetResourcePath(org.apache.sling.api.SlingJakartaHttpServletRequest request) Returns the path of the resource of the request as the resource path.protected VersioningConfigurationgetVersioningConfiguration(org.apache.sling.api.SlingJakartaHttpServletRequest request) Get the versioning configuration.protected booleanisSkipCheckin(org.apache.sling.api.SlingJakartaHttpServletRequest request) Check if checkin should be skippedprotected voidorderResource(org.apache.sling.api.SlingJakartaHttpServletRequest request, org.apache.sling.api.resource.Resource resource, List<Modification> changes) Orders the given resource according to the specified command.voidrun(org.apache.sling.api.SlingJakartaHttpServletRequest request, JakartaPostResponse response, SlingJakartaPostProcessor[] processors) Prepares and finalizes the actual operation.
-
Field Details
-
log
protected final org.slf4j.Logger logDefault logger -
jcrSupport
The JCR support provides additional functionality if the resources are backed by JCR.
-
-
Constructor Details
-
AbstractPostOperation
public AbstractPostOperation()
-
-
Method Details
-
run
public void run(org.apache.sling.api.SlingJakartaHttpServletRequest request, JakartaPostResponse response, SlingJakartaPostProcessor[] processors) throws PreconditionViolatedPersistenceException, TemporaryPersistenceException, org.apache.sling.api.resource.PersistenceException Prepares and finalizes the actual operation. Preparation encompasses getting the absolute path of the item to operate on by calling thegetResourcePath(SlingJakartaHttpServletRequest)method and setting the location and parent location on the response. After the operation has been done in thedoRun(SlingJakartaHttpServletRequest, PostResponse, List)method the session is saved if there are unsaved modifications. In case of errors, the unsaved changes in the session are rolled back.- Specified by:
runin interfaceJakartaPostOperation- Parameters:
request- the request to operate onresponse- ThePostResponseto record execution progress.processors- The array of processors- Throws:
PreconditionViolatedPersistenceException- when a necessary precondition failed, and a retry without further changes doesn't make sense.TemporaryPersistenceException- when a commit failed, but a retry could make the operation work successfully.org.apache.sling.api.resource.PersistenceException- when the commit fails
-
doRun
protected abstract void doRun(org.apache.sling.api.SlingJakartaHttpServletRequest request, JakartaPostResponse response, List<Modification> changes) throws org.apache.sling.api.resource.PersistenceException Actually performs the desired operation filling progress into thechangeslist and preparing and further information in theresponse.The
responsecomes prepared with the path, location and parent location set. Other properties are expected to be set by this implementation.- Parameters:
request- TheSlingJakartaHttpServletRequestproviding the input, mostly in terms of request parameters, to the operation.response- ThePostResponseto fill with response informationchanges- A container to addModificationinstances representing the operations done.- Throws:
org.apache.sling.api.resource.PersistenceException- Maybe thrown if any error occurs while accessing the repository.
-
getVersioningConfiguration
protected VersioningConfiguration getVersioningConfiguration(org.apache.sling.api.SlingJakartaHttpServletRequest request) Get the versioning configuration.- Parameters:
request- The http request- Returns:
- The versioning configuration
-
isSkipCheckin
protected boolean isSkipCheckin(org.apache.sling.api.SlingJakartaHttpServletRequest request) Check if checkin should be skipped- Parameters:
request- The http request- Returns:
trueif checkin should be skipped
-
getApplyToResources
protected Iterator<org.apache.sling.api.resource.Resource> getApplyToResources(org.apache.sling.api.SlingJakartaHttpServletRequest request) Returns an iterator onResourceinstances addressed in theSlingPostConstants.RP_APPLY_TOrequest parameter. If the request parameter is not set,nullis returned. If the parameter is set with valid resources an empty iterator is returned. Any resources addressed in theSlingPostConstants.RP_APPLY_TOparameter is ignored.- Parameters:
request- TheSlingJakartaHttpServletRequestobject used to get theSlingPostConstants.RP_APPLY_TOparameter.- Returns:
- The iterator of resources listed in the parameter or
nullif the parameter is not set in the request.
-
externalizePath
protected final String externalizePath(org.apache.sling.api.SlingJakartaHttpServletRequest request, String path) Returns an external form of the given path prepending the context path and appending a display extension.- Parameters:
request- The http requestpath- the path to externalize- Returns:
- the url
-
getResourcePath
Returns the path of the resource of the request as the resource path.This method may be overwritten by extension if the operation has different requirements on path processing.
- Parameters:
request- The http request- Returns:
- The resource path
-
orderResource
protected void orderResource(org.apache.sling.api.SlingJakartaHttpServletRequest request, org.apache.sling.api.resource.Resource resource, List<Modification> changes) throws org.apache.sling.api.resource.PersistenceException Orders the given resource according to the specified command. The following syntax is supported: <xmp> | first | before all child nodes | before A | before child node A | after A | after child node A | last | after all nodes | N | at a specific position, N being an integer </xmp>- Parameters:
request- The http requestresource- the resource to orderchanges- the list of modifications- Throws:
org.apache.sling.api.resource.PersistenceException- in case the operation is not successful
-