org.apache.sling.servlets.post
Class AbstractSlingPostOperation

java.lang.Object
  extended by org.apache.sling.servlets.post.AbstractSlingPostOperation
All Implemented Interfaces:
SlingPostOperation

public abstract class AbstractSlingPostOperation
extends Object
implements SlingPostOperation

Holds various states and encapsulates methods that are needed to handle a post request.


Field Summary
protected  org.slf4j.Logger log
          default log
 
Fields inherited from interface org.apache.sling.servlets.post.SlingPostOperation
PROP_OPERATION_NAME, SERVICE_NAME
 
Constructor Summary
AbstractSlingPostOperation()
           
 
Method Summary
protected  void checkoutIfNecessary(javax.jcr.Node node, List<Modification> changes, VersioningConfiguration versioningConfiguration)
           
protected abstract  void doRun(SlingHttpServletRequest request, HtmlResponse response, List<Modification> changes)
           
protected  String externalizePath(SlingHttpServletRequest request, String path)
          Returns an external form of the given path prepending the context path and appending a display extension.
protected  javax.jcr.Node findVersionableAncestor(javax.jcr.Node node)
           
protected  Iterator<Resource> getApplyToResources(SlingHttpServletRequest request)
          Returns an iterator on Resource instances addressed in the SlingPostConstants.RP_APPLY_TO request parameter.
protected  String getItemPath(SlingHttpServletRequest request)
          Returns the path of the resource of the request as the item path.
protected  VersioningConfiguration getVersioningConfiguration(SlingHttpServletRequest request)
           
protected  boolean hasItemPathPrefix(String name)
          Returns true if the name starts with either of the prefixes {@link SlingPostConstants#ITEM_PREFIX_RELATIVE_CURRENT .
protected  boolean isSkipCheckin(SlingHttpServletRequest request)
           
protected  boolean isVersionable(javax.jcr.Node node)
           
protected  void orderNode(SlingHttpServletRequest request, javax.jcr.Item item, List<Modification> changes)
          Orders the given node according to the specified command.
protected  String removeAndValidateWorkspace(String path, javax.jcr.Session session)
          Remove the workspace name, if any, from the start of the path and validate that the session's workspace name matches the path workspace name.
protected  boolean requireItemPathPrefix(SlingHttpServletRequest request)
          Returns true if any of the request parameters starts with {@link SlingPostConstants#ITEM_PREFIX_RELATIVE_CURRENT .
protected  String resolvePath(String absPath, String relPath)
          Resolves the given path with respect to the current root path.
 void run(SlingHttpServletRequest request, HtmlResponse response, SlingPostProcessor[] processors)
          Prepares and finalizes the actual operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.slf4j.Logger log
default log

Constructor Detail

AbstractSlingPostOperation

public AbstractSlingPostOperation()
Method Detail

run

public void run(SlingHttpServletRequest request,
                HtmlResponse response,
                SlingPostProcessor[] processors)
Prepares and finalizes the actual operation. Preparation encompasses getting the absolute path of the item to operate on by calling the getItemPath(SlingHttpServletRequest) method and setting the location and parent location on the response. After the operation has been done in the doRun(SlingHttpServletRequest, HtmlResponse, List) method the session is saved if there are unsaved modifications. In case of errorrs, the unsaved changes in the session are rolled back.

Specified by:
run in interface SlingPostOperation
Parameters:
request - the request to operate on
response - The HtmlResponse to record execution progress.

getVersioningConfiguration

protected VersioningConfiguration getVersioningConfiguration(SlingHttpServletRequest request)

isSkipCheckin

protected boolean isSkipCheckin(SlingHttpServletRequest request)

removeAndValidateWorkspace

protected String removeAndValidateWorkspace(String path,
                                            javax.jcr.Session session)
                                     throws javax.jcr.RepositoryException
Remove the workspace name, if any, from the start of the path and validate that the session's workspace name matches the path workspace name.

Throws:
javax.jcr.RepositoryException

getItemPath

protected String getItemPath(SlingHttpServletRequest request)
Returns the path of the resource of the request as the item path.

This method may be overwritten by extension if the operation has different requirements on path processing.


doRun

protected abstract void doRun(SlingHttpServletRequest request,
                              HtmlResponse response,
                              List<Modification> changes)
                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getApplyToResources

protected Iterator<Resource> getApplyToResources(SlingHttpServletRequest request)
Returns an iterator on Resource instances addressed in the SlingPostConstants.RP_APPLY_TO request parameter. If the request parameter is not set, null is returned. If the parameter is set with valid resources an empty iterator is returned. Any resources addressed in the SlingPostConstants.RP_APPLY_TO parameter is ignored.

Parameters:
request - The SlingHttpServletRequest object used to get the SlingPostConstants.RP_APPLY_TO parameter.
Returns:
The iterator of resources listed in the parameter or null if the parameter is not set in the request.

externalizePath

protected final String externalizePath(SlingHttpServletRequest request,
                                       String path)
Returns an external form of the given path prepending the context path and appending a display extension.

Parameters:
path - the path to externalize
Returns:
the url

resolvePath

protected final String resolvePath(String absPath,
                                   String relPath)
Resolves the given path with respect to the current root path.

Parameters:
relPath - the path to resolve
Returns:
the given path if it starts with a '/'; a resolved path otherwise.

requireItemPathPrefix

protected final boolean requireItemPathPrefix(SlingHttpServletRequest request)
Returns true if any of the request parameters starts with ./. In this case only parameters starting with either of the prefixes ./, ../ and / are considered as providing content to be stored. Otherwise all parameters not starting with the command prefix : are considered as parameters to be stored.


hasItemPathPrefix

protected boolean hasItemPathPrefix(String name)
Returns true if the name starts with either of the prefixes ./, ../ and /.


orderNode

protected void orderNode(SlingHttpServletRequest request,
                         javax.jcr.Item item,
                         List<Modification> changes)
                  throws javax.jcr.RepositoryException
Orders the given node according to the specified command. The following syntax is supported: | 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

Parameters:
item - node to order
Throws:
javax.jcr.RepositoryException - if an error occurs

findVersionableAncestor

protected javax.jcr.Node findVersionableAncestor(javax.jcr.Node node)
                                          throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

isVersionable

protected boolean isVersionable(javax.jcr.Node node)
                         throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

checkoutIfNecessary

protected void checkoutIfNecessary(javax.jcr.Node node,
                                   List<Modification> changes,
                                   VersioningConfiguration versioningConfiguration)
                            throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException


Copyright © 2007-2011 The Apache Software Foundation. All Rights Reserved.