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
TheAbstractPostResponse
class provides a basic implementation of thePostResponse
interface maintaining properties to be prepared for sending the response in an internal map.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PN_ERROR
Name of the error property set bysetError(Throwable)
static java.lang.String
PN_IS_CREATED
Name of the create status property set bysetCreateRequest(boolean)
static java.lang.String
PN_LOCATION
Name of the location property set bysetLocation(String)
static java.lang.String
PN_PARENT_LOCATION
Name of the parent location property set bysetParentLocation(String)
static java.lang.String
PN_PATH
Name of the path property set bysetPath(String)
static java.lang.String
PN_REFERER
Name of the referer property set bysetReferer(String)
static java.lang.String
PN_STATUS_CODE
Name of the status code property set bysetStatus(int, String)
static java.lang.String
PN_STATUS_MESSAGE
Name of the status message property set bysetStatus(int, String)
static java.lang.String
PN_TITLE
Name 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.Throwable
getError()
Returns any recorded error ornull
java.lang.String
getLocation()
Returns the location of the modification.java.lang.String
getParentLocation()
Returns the parent location of the modification.java.lang.String
getPath()
Returns the absolute path of the item upon which the request operated.java.lang.String
getReferer()
Returns the referer previously set byPostResponse.setReferer(String)
int
getStatusCode()
Returns the status code of this instance.java.lang.String
getStatusMessage()
Returns the status message ornull
if no has been set with thePostResponse.setStatus(int, String)
method.boolean
isCreateRequest()
Returnstrue
if this was a create request.boolean
isSuccessful()
void
onCopied(java.lang.String srcPath, java.lang.String dstPath)
Records a 'copied' change.void
onCreated(java.lang.String path)
Records a 'created' changevoid
onDeleted(java.lang.String path)
Records a 'deleted' changevoid
onModified(java.lang.String path)
Records a 'modified' changevoid
onMoved(java.lang.String srcPath, java.lang.String dstPath)
Records a 'moved' change.void
send(HttpServletResponse response, boolean setStatus)
Writes the response to the given writer and replaces all ${var} patterns by the value of the respective property.void
setCreateRequest(boolean isCreateRequest)
Sets whether the request was a create request or not.void
setError(java.lang.Throwable error)
Sets the recorded error causing the operation to fail.void
setLocation(java.lang.String location)
Sets the location of this modification.void
setParentLocation(java.lang.String parentLocation)
Sets the parent location of the modification.void
setPath(java.lang.String path)
Sets the absolute path of the item upon which the request operated.void
setReferer(java.lang.String referer)
Sets the referer propertyvoid
setStatus(int code, java.lang.String message)
sets the response status code propertiesvoid
setTitle(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:
getReferer
in interfacePostResponse
- Returns:
- the referer
-
setReferer
public void setReferer(java.lang.String referer)
Sets the referer property- Specified by:
setReferer
in 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:
getPath
in 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:
setPath
in interfacePostResponse
- Parameters:
path
- the path
-
isCreateRequest
public boolean isCreateRequest()
Returnstrue
if this was a create request.Before calling the
PostResponse.setCreateRequest(boolean)
method, this method always returnsfalse
.- Specified by:
isCreateRequest
in 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:
setCreateRequest
in 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:
getLocation
in interfacePostResponse
- Returns:
- the location
-
setLocation
public void setLocation(java.lang.String location)
Description copied from interface:PostResponse
Sets the location of this modification. This is the externalized form of thecurrent path
.- Specified by:
setLocation
in 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:
getParentLocation
in interfacePostResponse
- Returns:
- the location of the modification.
-
setParentLocation
public void setParentLocation(java.lang.String parentLocation)
Description copied from interface:PostResponse
Sets the parent location of the modification. This is the externalized form of the parent node of thecurrent path
.- Specified by:
setParentLocation
in 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:
setTitle
in interfacePostResponse
- Parameters:
title
- the title
-
setStatus
public void setStatus(int code, java.lang.String message)
sets the response status code properties- Specified by:
setStatus
in 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:
getStatusCode
in interfacePostResponse
- Returns:
- the status code
-
getStatusMessage
public java.lang.String getStatusMessage()
Description copied from interface:PostResponse
Returns the status message ornull
if no has been set with thePostResponse.setStatus(int, String)
method.- Specified by:
getStatusMessage
in interfacePostResponse
- Returns:
- the status message (might be null)
-
getError
public java.lang.Throwable getError()
Returns any recorded error ornull
- Specified by:
getError
in interfacePostResponse
- Returns:
- an error or
null
-
setError
public void setError(java.lang.Throwable error)
Description copied from interface:PostResponse
Sets the recorded error causing the operation to fail.- Specified by:
setError
in interfacePostResponse
- Parameters:
error
- the throwable
-
isSuccessful
public boolean isSuccessful()
- Specified by:
isSuccessful
in interfacePostResponse
- Returns:
- true if the status code is 2xx
-
onModified
public void onModified(java.lang.String path)
Records a 'modified' change- Specified by:
onModified
in interfacePostResponse
- Parameters:
path
- path of the item that was modified
-
onCreated
public void onCreated(java.lang.String path)
Records a 'created' change- Specified by:
onCreated
in interfacePostResponse
- Parameters:
path
- path of the item that was created
-
onDeleted
public void onDeleted(java.lang.String path)
Records a 'deleted' change- Specified by:
onDeleted
in 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:
onMoved
in 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:
onCopied
in 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:
send
in 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
-
-