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
,JSONResponse
The
AbstractPostResponse
class provides a basic implementation
of the PostResponse
interface maintaining properties to be
prepared for sending the response in an internal map.-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Name of the error property set bysetError(Throwable)
static final String
Name of the create status property set bysetCreateRequest(boolean)
static final String
Name of the location property set bysetLocation(String)
static final String
Name of the parent location property set bysetParentLocation(String)
static final String
Name of the path property set bysetPath(String)
static final String
Name of the referer property set bysetReferer(String)
static final String
Name of the status code property set bysetStatus(int, String)
static final String
Name of the status message property set bysetStatus(int, String)
static final String
Name of the title property set bysetTitle(String)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
doSend
(javax.servlet.http.HttpServletResponse response) getError()
Returns any recorded error ornull
Returns the location of the modification.Returns the parent location of the modification. this is the externalized form of the parent node of the current path.getPath()
Returns the absolute path of the item upon which the request operated.protected Object
getProperty
(String name) Returns the generic response property with the given name and type ornull
if no such property exists.protected <Type> Type
getProperty
(String name, Class<Type> type) Returns the generic response property with the given name and type ornull
if no such property exists or the property is not of the requested type.Returns the referer previously set byPostResponse.setReferer(String)
int
Returns the status code of this instance.Returns the status message ornull
if no has been set with thePostResponse.setStatus(int, String)
method.boolean
Returnstrue
if this was a create request.protected boolean
determines if the referer has a proper referer including protocolboolean
void
Records a 'copied' change.void
Records a 'created' changevoid
Records a 'deleted' changevoid
onModified
(String path) Records a 'modified' changevoid
Records a 'moved' change.final void
send
(javax.servlet.http.HttpServletResponse response, boolean setStatus) 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.void
setCreateRequest
(boolean isCreateRequest) Sets whether the request was a create request or not.void
Sets the recorded error causing the operation to fail.void
setLocation
(String location) Sets the location of this modification.void
setParentLocation
(String parentLocation) Sets the parent location of the modification.void
Sets the absolute path of the item upon which the request operated.protected void
setProperty
(String name, Object value) Sets a generic response property with the givenvoid
setReferer
(String referer) Sets the referer propertyvoid
sets the response status code propertiesvoid
Sets the title of the response messageMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.sling.servlets.post.PostResponse
onChange
-
Field Details
-
PN_TITLE
Name of the title property set bysetTitle(String)
- See Also:
-
PN_STATUS_CODE
Name of the status code property set bysetStatus(int, String)
- See Also:
-
PN_STATUS_MESSAGE
Name of the status message property set bysetStatus(int, String)
- See Also:
-
PN_LOCATION
Name of the location property set bysetLocation(String)
- See Also:
-
PN_PARENT_LOCATION
Name of the parent location property set bysetParentLocation(String)
- See Also:
-
PN_PATH
Name of the path property set bysetPath(String)
- See Also:
-
PN_REFERER
Name of the referer property set bysetReferer(String)
- See Also:
-
PN_IS_CREATED
Name of the create status property set bysetCreateRequest(boolean)
- See Also:
-
PN_ERROR
Name of the error property set bysetError(Throwable)
- See Also:
-
-
Constructor Details
-
AbstractPostResponse
public AbstractPostResponse()
-
-
Method Details
-
getReferer
Returns the referer previously set byPostResponse.setReferer(String)
- Specified by:
getReferer
in interfacePostResponse
- Returns:
- the referer
-
setReferer
Sets the referer property- Specified by:
setReferer
in interfacePostResponse
- Parameters:
referer
- the referer
-
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
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
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
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
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
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
Sets the title of the response message- Specified by:
setTitle
in interfacePostResponse
- Parameters:
title
- the title
-
setStatus
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
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
Returns any recorded error ornull
- Specified by:
getError
in interfacePostResponse
- Returns:
- an error or
null
-
setError
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
Records a 'modified' change- Specified by:
onModified
in interfacePostResponse
- Parameters:
path
- path of the item that was modified
-
onCreated
Records a 'created' change- Specified by:
onCreated
in interfacePostResponse
- Parameters:
path
- path of the item that was created
-
onDeleted
Records a 'deleted' change- Specified by:
onDeleted
in interfacePostResponse
- Parameters:
path
- path of the item that was deleted
-
onMoved
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
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.
-
setProperty
Sets a generic response property with the given- Parameters:
name
- name of the propertyvalue
- value of the property
-
getProperty
Returns the generic response property with the given name and type ornull
if no such property exists or the property is not of the requested type.- Type Parameters:
Type
- the return type- Parameters:
name
- the name of the requetested propertytype
- the type of the parameter which should be returned- Returns:
- the property as the requested type or null if not available at all or not in the requested type
-
getProperty
Returns the generic response property with the given name and type ornull
if no such property exists.- Parameters:
name
- the name of the response property- Returns:
- the requested property (might be null)
-
isSafeReferer
protected boolean isSafeReferer()determines if the referer has a proper referer including protocol- Returns:
- true if HTTP or HTTPS protocol information is available in the referer
-
doSend
- Throws:
IOException
-
send
public final void send(javax.servlet.http.HttpServletResponse response, boolean setStatus) throws 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:
IOException
- if an i/o exception occurs
-