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 java.lang.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 abstract  void doRun(SlingHttpServletRequest request, HtmlResponse response, java.util.List<Modification> changes)
           
protected  java.lang.String externalizePath(SlingHttpServletRequest request, java.lang.String path)
          Returns an external form of the given path prepending the context path and appending a display extension.
protected  java.util.Iterator<Resource> getApplyToResources(SlingHttpServletRequest request)
          Returns an iterator on Resource instances addressed in the SlingPostConstants.RP_APPLY_TO request parameter.
protected  java.lang.String getItemPath(SlingHttpServletRequest request)
          Returns the path of the resource of the request as the item path.
protected  boolean hasItemPathPrefix(java.lang.String name)
          Returns true if the name starts with either of the prefixes {@link SlingPostConstants#ITEM_PREFIX_RELATIVE_CURRENT .
protected  void orderNode(SlingHttpServletRequest request, javax.jcr.Item item, java.util.List<Modification> changes)
          Orders the given node according to the specified command.
protected  boolean requireItemPathPrefix(SlingHttpServletRequest request)
          Returns true if any of the request parameters starts with {@link SlingPostConstants#ITEM_PREFIX_RELATIVE_CURRENT .
protected  java.lang.String resolvePath(java.lang.String absPath, java.lang.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.

getItemPath

protected java.lang.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,
                              java.util.List<Modification> changes)
                       throws javax.jcr.RepositoryException
Throws:
javax.jcr.RepositoryException

getApplyToResources

protected java.util.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 java.lang.String externalizePath(SlingHttpServletRequest request,
                                                 java.lang.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 java.lang.String resolvePath(java.lang.String absPath,
                                             java.lang.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(java.lang.String name)
Returns true if the name starts with either of the prefixes ./, ../ and /.


orderNode

protected void orderNode(SlingHttpServletRequest request,
                         javax.jcr.Item item,
                         java.util.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


Copyright © 2007-2009. All Rights Reserved.