Package org.apache.sling.servlets.post
Class AbstractPostResponse
- java.lang.Object
-
- org.apache.sling.servlets.post.AbstractPostResponse
-
- All Implemented Interfaces:
PostResponse
- Direct Known Subclasses:
HtmlResponse,HtmlResponse,JSONResponse
public abstract class AbstractPostResponse extends java.lang.Object implements PostResponse
TheAbstractPostResponseclass provides a basic implementation of thePostResponseinterface maintaining properties to be prepared for sending the response in an internal map.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPN_ERRORName of the error property set bysetError(Throwable)static java.lang.StringPN_IS_CREATEDName of the create status property set bysetCreateRequest(boolean)static java.lang.StringPN_LOCATIONName of the location property set bysetLocation(String)static java.lang.StringPN_PARENT_LOCATIONName of the parent location property set bysetParentLocation(String)static java.lang.StringPN_PATHName of the path property set bysetPath(String)static java.lang.StringPN_REFERERName of the referer property set bysetReferer(String)static java.lang.StringPN_STATUS_CODEName of the status code property set bysetStatus(int, String)static java.lang.StringPN_STATUS_MESSAGEName of the status message property set bysetStatus(int, String)static java.lang.StringPN_TITLEName of the title property set bysetTitle(String)
-
Constructor Summary
Constructors Constructor Description AbstractPostResponse()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ThrowablegetError()Returns any recorded error ornulljava.lang.StringgetLocation()Returns the location of the modification.java.lang.StringgetParentLocation()Returns the parent location of the modification.java.lang.StringgetPath()Returns the absolute path of the item upon which the request operated.java.lang.StringgetReferer()Returns the referer previously set byPostResponse.setReferer(String)intgetStatusCode()Returns the status code of this instance.java.lang.StringgetStatusMessage()Returns the status message ornullif no has been set with thePostResponse.setStatus(int, String)method.booleanisCreateRequest()Returnstrueif this was a create request.booleanisSuccessful()voidonCopied(java.lang.String srcPath, java.lang.String dstPath)Records a 'copied' change.voidonCreated(java.lang.String path)Records a 'created' changevoidonDeleted(java.lang.String path)Records a 'deleted' changevoidonModified(java.lang.String path)Records a 'modified' changevoidonMoved(java.lang.String srcPath, java.lang.String dstPath)Records a 'moved' change.voidsend(HttpServletResponse response, boolean setStatus)Writes the response to the given writer and replaces all ${var} patterns by the value of the respective property.voidsetCreateRequest(boolean isCreateRequest)Sets whether the request was a create request or not.voidsetError(java.lang.Throwable error)Sets the recorded error causing the operation to fail.voidsetLocation(java.lang.String location)Sets the location of this modification.voidsetParentLocation(java.lang.String parentLocation)Sets the parent location of the modification.voidsetPath(java.lang.String path)Sets the absolute path of the item upon which the request operated.voidsetReferer(java.lang.String referer)Sets the referer propertyvoidsetStatus(int code, java.lang.String message)sets the response status code propertiesvoidsetTitle(java.lang.String title)Sets the title of the response message-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.sling.servlets.post.PostResponse
onChange
-
-
-
-
Field Detail
-
PN_TITLE
public static final java.lang.String PN_TITLE
Name of the title property set bysetTitle(String)- See Also:
- Constant Field Values
-
PN_STATUS_CODE
public static final java.lang.String PN_STATUS_CODE
Name of the status code property set bysetStatus(int, String)- See Also:
- Constant Field Values
-
PN_STATUS_MESSAGE
public static final java.lang.String PN_STATUS_MESSAGE
Name of the status message property set bysetStatus(int, String)- See Also:
- Constant Field Values
-
PN_LOCATION
public static final java.lang.String PN_LOCATION
Name of the location property set bysetLocation(String)- See Also:
- Constant Field Values
-
PN_PARENT_LOCATION
public static final java.lang.String PN_PARENT_LOCATION
Name of the parent location property set bysetParentLocation(String)- See Also:
- Constant Field Values
-
PN_PATH
public static final java.lang.String PN_PATH
Name of the path property set bysetPath(String)- See Also:
- Constant Field Values
-
PN_REFERER
public static final java.lang.String PN_REFERER
Name of the referer property set bysetReferer(String)- See Also:
- Constant Field Values
-
PN_IS_CREATED
public static final java.lang.String PN_IS_CREATED
Name of the create status property set bysetCreateRequest(boolean)- See Also:
- Constant Field Values
-
PN_ERROR
public static final java.lang.String PN_ERROR
Name of the error property set bysetError(Throwable)- See Also:
- Constant Field Values
-
-
Method Detail
-
getReferer
public java.lang.String getReferer()
Returns the referer previously set byPostResponse.setReferer(String)- Specified by:
getRefererin interfacePostResponse- Returns:
- the referer
-
setReferer
public void setReferer(java.lang.String referer)
Sets the referer property- Specified by:
setRefererin interfacePostResponse- Parameters:
referer- the referer
-
getPath
public java.lang.String getPath()
Returns the absolute path of the item upon which the request operated.If the
PostResponse.setPath(String)method has not been called yet, this method returnsnull.- Specified by:
getPathin interfacePostResponse- Returns:
- the path (might be null)
-
setPath
public void setPath(java.lang.String path)
Sets the absolute path of the item upon which the request operated.- Specified by:
setPathin interfacePostResponse- Parameters:
path- the path
-
isCreateRequest
public boolean isCreateRequest()
Returnstrueif this was a create request.Before calling the
PostResponse.setCreateRequest(boolean)method, this method always returnsfalse.- Specified by:
isCreateRequestin interfacePostResponse- Returns:
- if this was a create request
-
setCreateRequest
public void setCreateRequest(boolean isCreateRequest)
Sets whether the request was a create request or not.- Specified by:
setCreateRequestin interfacePostResponse- Parameters:
isCreateRequest- true if the request was a create request
-
getLocation
public java.lang.String getLocation()
Returns the location of the modification.If the
PostResponse.setLocation(String)method has not been called yet, this method returnsnull.- Specified by:
getLocationin interfacePostResponse- Returns:
- the location
-
setLocation
public void setLocation(java.lang.String location)
Description copied from interface:PostResponseSets the location of this modification. This is the externalized form of thecurrent path.- Specified by:
setLocationin interfacePostResponse- Parameters:
location- the location
-
getParentLocation
public java.lang.String getParentLocation()
Returns the parent location of the modification. this is the externalized form of the parent node of the current path.- Specified by:
getParentLocationin interfacePostResponse- Returns:
- the location of the modification.
-
setParentLocation
public void setParentLocation(java.lang.String parentLocation)
Description copied from interface:PostResponseSets the parent location of the modification. This is the externalized form of the parent node of thecurrent path.- Specified by:
setParentLocationin interfacePostResponse- Parameters:
parentLocation- the parent location of the modification
-
setTitle
public void setTitle(java.lang.String title)
Sets the title of the response message- Specified by:
setTitlein interfacePostResponse- Parameters:
title- the title
-
setStatus
public void setStatus(int code, java.lang.String message)sets the response status code properties- Specified by:
setStatusin interfacePostResponse- Parameters:
code- the codemessage- the message
-
getStatusCode
public int getStatusCode()
Returns the status code of this instance. If the status code has never been set by calling thesetStatus(int, String)method, the status code is determined by checking if there was an error. If there was an error, the response is assumed to be unsuccessful and 500 is returned. If there is no error, the response is assumed to be successful and 200 is returned.- Specified by:
getStatusCodein interfacePostResponse- Returns:
- the status code
-
getStatusMessage
public java.lang.String getStatusMessage()
Description copied from interface:PostResponseReturns the status message ornullif no has been set with thePostResponse.setStatus(int, String)method.- Specified by:
getStatusMessagein interfacePostResponse- Returns:
- the status message (might be null)
-
getError
public java.lang.Throwable getError()
Returns any recorded error ornull- Specified by:
getErrorin interfacePostResponse- Returns:
- an error or
null
-
setError
public void setError(java.lang.Throwable error)
Description copied from interface:PostResponseSets the recorded error causing the operation to fail.- Specified by:
setErrorin interfacePostResponse- Parameters:
error- the throwable
-
isSuccessful
public boolean isSuccessful()
- Specified by:
isSuccessfulin interfacePostResponse- Returns:
- true if the status code is 2xx
-
onModified
public void onModified(java.lang.String path)
Records a 'modified' change- Specified by:
onModifiedin interfacePostResponse- Parameters:
path- path of the item that was modified
-
onCreated
public void onCreated(java.lang.String path)
Records a 'created' change- Specified by:
onCreatedin interfacePostResponse- Parameters:
path- path of the item that was created
-
onDeleted
public void onDeleted(java.lang.String path)
Records a 'deleted' change- Specified by:
onDeletedin interfacePostResponse- Parameters:
path- path of the item that was deleted
-
onMoved
public void onMoved(java.lang.String srcPath, java.lang.String dstPath)Records a 'moved' change.Note: the moved change only records the basic move command. the implied changes on the moved properties and sub nodes are not recorded.
- Specified by:
onMovedin interfacePostResponse- Parameters:
srcPath- source path of the node that was moveddstPath- destination path of the node that was moved.
-
onCopied
public void onCopied(java.lang.String srcPath, java.lang.String dstPath)Records a 'copied' change.Note: the copy change only records the basic copy command. the implied changes on the copied properties and sub nodes are not recorded.
- Specified by:
onCopiedin interfacePostResponse- Parameters:
srcPath- source path of the node that was copieddstPath- destination path of the node that was copied.
-
send
public final void send(HttpServletResponse response, boolean setStatus) throws java.io.IOException
Writes the response to the given writer and replaces all ${var} patterns by the value of the respective property. if the property is not defined the pattern is not modified.- Specified by:
sendin interfacePostResponse- Parameters:
response- to send tosetStatus- whether to set the status code on the response- Throws:
java.io.IOException- if an i/o exception occurs
-
-