public class Result
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APPLICATION_OCTET_STREAM |
static java.lang.String |
APPLICATION_XML |
static java.lang.String |
APPLICATON_JSON |
static java.lang.String |
APPLICATON_JSONP |
static java.lang.String |
CACHE_CONTROL |
static java.lang.String |
CACHE_CONTROL_DEFAULT_NOCACHE_VALUE |
static java.lang.String |
DATE |
static java.lang.String |
EXPIRES |
static java.lang.String |
LOCATION |
static NoHttpBody |
NO_HTTP_BODY |
static int |
SC_200_OK |
static int |
SC_204_NO_CONTENT |
static int |
SC_300_MULTIPLE_CHOICES |
static int |
SC_301_MOVED_PERMANENTLY |
static int |
SC_302_FOUND |
static int |
SC_303_SEE_OTHER |
static int |
SC_304_NOT_MODIFIED |
static int |
SC_307_TEMPORARY_REDIRECT |
static int |
SC_400_BAD_REQUEST |
static int |
SC_403_FORBIDDEN |
static int |
SC_404_NOT_FOUND |
static int |
SC_500_INTERNAL_SERVER_ERROR |
static int |
SC_501_NOT_IMPLEMENTED |
static java.lang.String |
TEXT_HTML |
static java.lang.String |
TEXT_PLAIN |
Constructor and Description |
---|
Result(int statusCode)
A result.
|
Modifier and Type | Method and Description |
---|---|
Result |
addCookie(Cookie cookie) |
Result |
addHeader(java.lang.String headerName,
java.lang.String headerContent) |
void |
charset(java.lang.String charset) |
Result |
contentType(java.lang.String contentType)
Sets the content type.
|
Result |
doNotCacheContent()
This function sets
Cache-Control: no-cache, no-store
Date: (current date)
Expires: 1970
=> it therefore effectively forces the browser and every proxy in between
not to cache content.
|
java.lang.String |
getCharset() |
java.lang.String |
getContentType() |
Cookie |
getCookie(java.lang.String cookieName)
Returns cookie with that name or null.
|
java.util.List<Cookie> |
getCookies() |
java.util.Map<java.lang.String,java.lang.String> |
getHeaders() |
java.lang.Object |
getRenderable() |
int |
getStatusCode() |
java.lang.String |
getTemplate() |
Result |
html()
Set the content type of this result to
TEXT_HTML . |
Result |
json()
Set the content type of this result to
APPLICATON_JSON . |
Result |
jsonp()
Set the content type of this result to
APPLICATON_JSONP . |
Result |
redirect(java.lang.String url)
A redirect that uses 303 see other.
|
Result |
redirectTemporary(java.lang.String url)
A redirect that uses 307 see other.
|
Result |
render(java.util.Map.Entry<java.lang.String,java.lang.Object> entry)
Handles two cases:
1) If this.renderable is null a new HashMap is generated and this entry being added
to the map.
|
Result |
render(java.util.Map<java.lang.String,java.lang.Object> mapToRender)
Replaces the object being passed by this result to the rendering engine
with this map.
|
Result |
render(java.lang.Object object)
This method handles two principal cases:
1) If the this.renderable of this result is null, the object passed is simply set as renderable
for this Result
2) If the this.renderable of this result is not null an new map is generated as
object to render and both the former renderable and the new object added to the map.
|
Result |
render(Renderable renderable)
Sets this renderable as object to render.
|
Result |
render(java.lang.String key,
java.lang.Object value)
Implicitly generates a hashmap as object being rendered and adds
this key, value pair.
|
Result |
renderRaw(java.lang.String string)
This method directly renders the String to the output.
|
Result |
setContentType(java.lang.String contentType)
Deprecated.
|
Result |
status(int statusCode)
Set the status of this result.
|
Result |
template(java.lang.String template)
Set the template to render.
|
Result |
unsetCookie(java.lang.String name) |
Result |
xml()
Set the content type of this result to
Result#APPLICATON_XML . |
public static int SC_200_OK
public static int SC_204_NO_CONTENT
public static int SC_300_MULTIPLE_CHOICES
public static int SC_301_MOVED_PERMANENTLY
public static int SC_302_FOUND
public static int SC_303_SEE_OTHER
public static int SC_304_NOT_MODIFIED
public static int SC_307_TEMPORARY_REDIRECT
public static int SC_400_BAD_REQUEST
public static int SC_403_FORBIDDEN
public static int SC_404_NOT_FOUND
public static int SC_500_INTERNAL_SERVER_ERROR
public static int SC_501_NOT_IMPLEMENTED
public static final java.lang.String TEXT_HTML
public static final java.lang.String TEXT_PLAIN
public static final java.lang.String APPLICATON_JSON
public static final java.lang.String APPLICATON_JSONP
public static final java.lang.String APPLICATION_XML
public static final java.lang.String APPLICATION_OCTET_STREAM
public static final NoHttpBody NO_HTTP_BODY
public static final java.lang.String LOCATION
public static final java.lang.String CACHE_CONTROL
public static final java.lang.String CACHE_CONTROL_DEFAULT_NOCACHE_VALUE
public static final java.lang.String DATE
public static final java.lang.String EXPIRES
public Result(int statusCode)
SC_200_OK
, SC_204_NO_CONTENT
and so on
for some short cuts to predefined results.statusCode
- The status code to set for the result. Shortcuts to the code at: SC_200_OK
public java.lang.Object getRenderable()
public Result render(java.lang.Object object)
IllegalArgumentException
is being thrown.Object
- The object to add (either an arbitrary class or Renderable).public Result render(java.util.Map<java.lang.String,java.lang.Object> mapToRender)
mapToRender
- The map being passed to the templating engine.public Result render(java.util.Map.Entry<java.lang.String,java.lang.Object> entry)
IllegalArgumentException
is thrown.
If the entry key already exists in the map of this.renderable an IllegalArgumentException
is thrown.entry
- The entry to add.public Result render(Renderable renderable)
renderable
- The renderable that will handle everything after returing the result.public Result render(java.lang.String key, java.lang.Object value)
key
- The key to use.value
- The value to use.public Result renderRaw(java.lang.String string)
public Result controllerMethod() {
String customJson = "{\"user\" : \"[email protected]\"}";
return Results.json().renderRaw(customJson);
}
string
- The string to render.public java.lang.String getContentType()
public java.lang.String getCharset()
public void charset(java.lang.String charset)
@Deprecated public Result setContentType(java.lang.String contentType)
contentType
- public Result contentType(java.lang.String contentType)
charset(String)
;contentType
- (without encoding) something like "text/html" or
"application/json"public java.util.Map<java.lang.String,java.lang.String> getHeaders()
public Result addHeader(java.lang.String headerName, java.lang.String headerContent)
public Cookie getCookie(java.lang.String cookieName)
cookieName
- Name of the cookiepublic java.util.List<Cookie> getCookies()
public Result unsetCookie(java.lang.String name)
public int getStatusCode()
public Result status(int statusCode)
SC_200_OK
, SC_204_NO_CONTENT
and so on
for some short cuts to predefined results.statusCode
- The status code. Result (SC_200_OK
) provides some helpers.public java.lang.String getTemplate()
public Result template(java.lang.String template)
template
- The view to render. Eg. views/AnotherController/anotherview.ftl.htmlpublic Result redirect(java.lang.String url)
url
- The url used as redirect target.public Result redirectTemporary(java.lang.String url)
url
- The url used as redirect target.public Result html()
TEXT_HTML
.TEXT_HTML
.public Result json()
APPLICATON_JSON
.APPLICATON_JSON
.public Result jsonp()
APPLICATON_JSONP
.APPLICATON_JSONP
.public Result xml()
Result#APPLICATON_XML
.Result#APPLICATON_XML
.public Result doNotCacheContent()
Copyright © 2014. All Rights Reserved.