org.apache.sling.servlets.post.impl.helper
Class JSONResponse

java.lang.Object
  extended by org.apache.sling.api.servlets.HtmlResponse
      extended by org.apache.sling.servlets.post.impl.helper.JSONResponse

public class JSONResponse
extends HtmlResponse

Represents a JSON response to be sent to the client. For backward compatibility, this extends HtmlResponse.


Nested Class Summary
 class JSONResponse.JSONResponseException
           
 
Field Summary
static String RESPONSE_CONTENT_TYPE
           
 
Fields inherited from class org.apache.sling.api.servlets.HtmlResponse
PN_CHANGE_LOG, PN_ERROR, PN_IS_CREATED, PN_LOCATION, PN_PARENT_LOCATION, PN_PATH, PN_REFERER, PN_STATUS_CODE, PN_STATUS_MESSAGE, PN_TITLE
 
Constructor Summary
JSONResponse()
           
 
Method Summary
 Throwable getError()
          Returns any recorded error or null
 Object getProperty(String name)
          Returns the generic response property with the given name and type or null if no such property exists.
 void onChange(String type, String... arguments)
          Records a generic change of the given type.
 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.
 void setCreateRequest(boolean isCreateRequest)
          Sets whether the request was a create request or not.
 void setError(Throwable error)
           
 void setProperty(String name, Object value)
          Sets a generic response property with the given
 
Methods inherited from class org.apache.sling.api.servlets.HtmlResponse
getLocation, getParentLocation, getPath, getProperty, getReferer, getStatusCode, getStatusMessage, isCreateRequest, isSuccessful, onCopied, onCreated, onDeleted, onModified, onMoved, setLocation, setParentLocation, setPath, setReferer, setStatus, setTitle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESPONSE_CONTENT_TYPE

public static final String RESPONSE_CONTENT_TYPE
See Also:
Constant Field Values
Constructor Detail

JSONResponse

public JSONResponse()
             throws JSONResponse.JSONResponseException
Throws:
JSONResponse.JSONResponseException
Method Detail

onChange

public void onChange(String type,
                     String... arguments)
              throws JSONResponse.JSONResponseException
Description copied from class: HtmlResponse
Records a generic change of the given type.

The change is added to the internal list of changes with the syntax of a method call, where the type is the method name and the arguments are the string arguments to the method enclosed in double quotes. For example, the the call

 onChange("sameple", "arg1", "arg2");
 
is aded as
 sample("arg1", "arg2")
 
to the internal list of changes.

Overrides:
onChange in class HtmlResponse
Parameters:
type - The type of the modification
arguments - The arguments to the modifications
Throws:
JSONResponse.JSONResponseException

setError

public void setError(Throwable error)
Overrides:
setError in class HtmlResponse

getError

public Throwable getError()
Description copied from class: HtmlResponse
Returns any recorded error or null

Overrides:
getError in class HtmlResponse
Returns:
an error or null

setCreateRequest

public void setCreateRequest(boolean isCreateRequest)
Description copied from class: HtmlResponse
Sets whether the request was a create request or not.

Overrides:
setCreateRequest in class HtmlResponse

setProperty

public void setProperty(String name,
                        Object value)
Description copied from class: HtmlResponse
Sets a generic response property with the given

Overrides:
setProperty in class HtmlResponse
Parameters:
name - name of the property
value - value of the property

getProperty

public Object getProperty(String name)
                   throws JSONResponse.JSONResponseException
Description copied from class: HtmlResponse
Returns the generic response property with the given name and type or null if no such property exists.

Overrides:
getProperty in class HtmlResponse
Throws:
JSONResponse.JSONResponseException

send

public void send(javax.servlet.http.HttpServletResponse response,
                 boolean setStatus)
          throws IOException
Description copied from class: HtmlResponse
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.

Overrides:
send in class HtmlResponse
Parameters:
response - to send to
setStatus - whether to set the status code on the response
Throws:
IOException - if an i/o exception occurs


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