org.loom.resolution
Class JacksonResolution

java.lang.Object
  extended by org.loom.resolution.AbstractHttpResolution
      extended by org.loom.resolution.JacksonResolution
All Implemented Interfaces:
CacheableResolution, HttpResolution, Resolution

public class JacksonResolution
extends AbstractHttpResolution

A resolution that uses Jackson to serialize a JSON response.


Constructor Summary
JacksonResolution(org.codehaus.jackson.map.ObjectMapper mapper, java.lang.Object contents)
           
 
Method Summary
 JacksonResolution addCookie(javax.servlet.http.Cookie cookie)
          Adds a cookie
 JacksonResolution addCookie(java.lang.String name, java.lang.String value)
          Adds a cookie that will not be stored on disk (will be deleted when the browser is closed).
 JacksonResolution addCookie(java.lang.String name, java.lang.String value, int maxAge)
          Adds a cookie
 JacksonResolution addHeader(java.lang.String name, java.lang.Object value)
          Add a http header.
 java.lang.Object getContents()
           
 org.codehaus.jackson.map.ObjectMapper getMapper()
           
 void resolve(LoomServletRequest request, LoomServletResponse response)
          Write the response contents
 JacksonResolution setCacheControl(CacheControl cacheControl)
          Sets the cache data to be sent to the browser
 JacksonResolution setCharset(java.lang.String charset)
          Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.
 JacksonResolution setContentType(java.lang.String contentType)
          Sets the content type of the response being sent to the client, if the response has not been committed yet.
 JacksonResolution setHeader(java.lang.String name, java.lang.Object value)
          Set a String http header.
 JacksonResolution setHeaderIfNotPresent(java.lang.String name, java.lang.Object value)
          Set a String http header if it has not been set.
 java.lang.String toString()
           
 JacksonResolution withView(java.lang.Class<?> viewClass)
          Specify the jackson view to use for serializing
 
Methods inherited from class org.loom.resolution.AbstractHttpResolution
addDateHeader, addIntHeader, containsHeader, getCacheControl, getCharset, getContentType, setDateHeader, setDateHeaderIfNotPresent, setIntHeader, setIntHeaderIfNotPresent, setJsonHeader, writeHeaders
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JacksonResolution

public JacksonResolution(org.codehaus.jackson.map.ObjectMapper mapper,
                         java.lang.Object contents)
Method Detail

resolve

public void resolve(LoomServletRequest request,
                    LoomServletResponse response)
             throws java.io.IOException,
                    javax.servlet.ServletException
Description copied from interface: Resolution
Write the response contents

Specified by:
resolve in interface Resolution
Specified by:
resolve in class AbstractHttpResolution
Parameters:
request - the current request object
response - the current response object
Throws:
java.io.IOException
javax.servlet.ServletException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

withView

public JacksonResolution withView(java.lang.Class<?> viewClass)
Specify the jackson view to use for serializing


getMapper

public org.codehaus.jackson.map.ObjectMapper getMapper()

getContents

public java.lang.Object getContents()

addCookie

public JacksonResolution addCookie(java.lang.String name,
                                   java.lang.String value)
Description copied from interface: HttpResolution
Adds a cookie that will not be stored on disk (will be deleted when the browser is closed).

Specified by:
addCookie in interface HttpResolution
Overrides:
addCookie in class AbstractHttpResolution
Parameters:
name - the name of the cookie
value - the value of the Cookie

addCookie

public JacksonResolution addCookie(java.lang.String name,
                                   java.lang.String value,
                                   int maxAge)
Description copied from interface: HttpResolution
Adds a cookie

Specified by:
addCookie in interface HttpResolution
Overrides:
addCookie in class AbstractHttpResolution
Parameters:
name - the name of the cookie
value - the value of the Cookie
maxAge - can be positive (number of seconds that it will be stored in the browser), zero (to delete the cookie from the browser) or a negative value (to indicate that the cookie should not be stored in disk and will be forgotten when the browser exists).

addCookie

public JacksonResolution addCookie(javax.servlet.http.Cookie cookie)
Description copied from interface: HttpResolution
Adds a cookie

Specified by:
addCookie in interface HttpResolution
Overrides:
addCookie in class AbstractHttpResolution
Parameters:
cookie - the cookie to be added to the response

addHeader

public JacksonResolution addHeader(java.lang.String name,
                                   java.lang.Object value)
Description copied from interface: HttpResolution
Add a http header. If the header already exists a new value will be added.

Specified by:
addHeader in interface HttpResolution
Overrides:
addHeader in class AbstractHttpResolution
Parameters:
name - the name of the http header
value - the value of the http header. Date, int and String are supported. Anything else will be cast to toString(). Null will be ignored.

setHeader

public JacksonResolution setHeader(java.lang.String name,
                                   java.lang.Object value)
Description copied from interface: HttpResolution
Set a String http header. If the header already exists it will be replaced.

Specified by:
setHeader in interface HttpResolution
Overrides:
setHeader in class AbstractHttpResolution
Parameters:
name - the name of the http header
value - the value of the http header

setHeaderIfNotPresent

public JacksonResolution setHeaderIfNotPresent(java.lang.String name,
                                               java.lang.Object value)
Description copied from interface: HttpResolution
Set a String http header if it has not been set.

Specified by:
setHeaderIfNotPresent in interface HttpResolution
Overrides:
setHeaderIfNotPresent in class AbstractHttpResolution
Parameters:
name - the name of the http header
value - the value of the http header

setCharset

public JacksonResolution setCharset(java.lang.String charset)
Description copied from interface: HttpResolution
Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.

Specified by:
setCharset in interface HttpResolution
Overrides:
setCharset in class AbstractHttpResolution

setContentType

public JacksonResolution setContentType(java.lang.String contentType)
Description copied from interface: HttpResolution
Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example, text/html;charset=UTF-8. Notice that #setCharset(String) can also be used for this.

Specified by:
setContentType in interface HttpResolution
Overrides:
setContentType in class AbstractHttpResolution

setCacheControl

public JacksonResolution setCacheControl(CacheControl cacheControl)
Description copied from interface: CacheableResolution
Sets the cache data to be sent to the browser

Specified by:
setCacheControl in interface CacheableResolution
Specified by:
setCacheControl in interface HttpResolution
Overrides:
setCacheControl in class AbstractHttpResolution
Parameters:
cacheControl - the cache data.
Returns:
this same instance, to allow easy chaining of invocations