public class Controller extends Object implements ControllersEnhancer.ControllerSupport, LocalvariablesNamesEnhancer.LocalVariablesSupport
Modifier and Type | Class and Description |
---|---|
static interface |
Controller.ITemplateNameResolver
This allow people that implements their own template engine to override
the way template are resolved.
|
Modifier and Type | Field and Description |
---|---|
static ThreadLocal<Router.ActionDefinition> |
_currentReverse
Don't use this directly if you don't know why
|
protected static Scope.Flash |
flash
The current flash scope.
|
protected static Scope.Params |
params
The current HTTP params.
|
protected static Scope.RenderArgs |
renderArgs
The current renderArgs scope: This is a hash map that is accessible
during the rendering phase.
|
protected static Http.Request |
request
The current HTTP request: the message sent by the client to the server.
|
protected static Http.Response |
response
The current HTTP response: The message sent back from the server after a
request.
|
protected static Scope.RouteArgs |
routeArgs
The current routeArgs scope: This is a hash map that is accessible during
the reverse routing phase.
|
protected static Scope.Session |
session
The current HTTP session.
|
protected static Validation |
validation
The current Validation object.
|
Constructor and Description |
---|
Controller() |
Modifier and Type | Method and Description |
---|---|
protected static <T> T |
await(Future<T> future) |
protected static <T> void |
await(Future<T> future,
F.Action<T> callback) |
protected static void |
await(int millis) |
protected static void |
await(int millis,
F.Action0 callback) |
protected static void |
await(String timeout) |
protected static void |
await(String timeout,
F.Action0 callback) |
protected static void |
badRequest()
Send a 400 Bad request
|
protected static void |
badRequest(String msg)
Send a 400 Bad request
|
protected static void |
checkAuthenticity()
Check that the token submitted from a form is valid.
|
protected static void |
error()
Send a 500 Error response
|
protected static void |
error(Exception reason)
Send a 500 Error response
|
protected static void |
error(int status,
String reason)
Send a 5xx Error response
|
protected static void |
error(String reason)
Send a 500 Error response
|
protected static void |
flash(String key,
Object value)
Add a value to the flash scope
|
protected static void |
forbidden()
Send a 403 Forbidden response
|
protected static void |
forbidden(String reason)
Send a 403 Forbidden response
|
protected static <T extends Annotation> |
getActionAnnotation(Class<T> clazz)
Retrieve annotation for the action method
|
protected static <T extends Annotation> |
getControllerAnnotation(Class<T> clazz)
Retrieve annotation for the controller class
|
protected static Class<? extends Controller> |
getControllerClass()
Retrieve the controller class
|
protected static <T extends Annotation> |
getControllerInheritedAnnotation(Class<T> clazz)
Retrieve annotation for the controller class
|
protected static void |
notFound()
Send a 404 Not Found response
|
protected static void |
notFound(String what)
Send a 404 Not Found response
|
protected static void |
notFoundIfNull(Object o)
Send a 404 Not Found response if object is null
|
protected static void |
notFoundIfNull(Object o,
String what)
Send a 404 Not Found response if object is null
|
protected static void |
notModified()
Send a 304 Not Modified response
|
protected static void |
ok()
Send a 200 OK response
|
protected static void |
parent()
Deprecated.
|
protected static void |
parent(Map<String,Object> map)
Deprecated.
|
protected static void |
parent(Object... args)
Deprecated.
|
protected static void |
redirect(String url)
Send a 302 redirect response.
|
protected static void |
redirect(String url,
boolean permanent)
Send a Redirect response.
|
protected static void |
redirect(String action,
boolean permanent,
Object... args)
Redirect to another action
|
static void |
redirect(String action,
Object... args)
302 Redirect to another action
|
protected static void |
redirectToStatic(String file)
Send a 302 redirect response.
|
static void |
registerTemplateNameResolver(Controller.ITemplateNameResolver templateNameResolver)
Register a customer template name resolver.
|
protected static void |
render(Object... args)
Render the corresponding template (@see
template() ). |
protected static void |
renderBinary(File file)
Return a 200 OK application/binary response
|
protected static void |
renderBinary(File file,
String name)
Return a 200 OK application/binary response with content-disposition
attachment
|
protected static void |
renderBinary(InputStream is)
Return a 200 OK application/binary response.
|
protected static void |
renderBinary(InputStream is,
long length)
Return a 200 OK application/binary response.
|
protected static void |
renderBinary(InputStream is,
String name)
Return a 200 OK application/binary response with content-disposition
attachment.
|
protected static void |
renderBinary(InputStream is,
String name,
boolean inline)
Return a 200 OK application/binary response with content-disposition
attachment.
|
protected static void |
renderBinary(InputStream is,
String name,
long length)
Return a 200 OK application/binary response with content-disposition
attachment.
|
protected static void |
renderBinary(InputStream is,
String name,
long length,
boolean inline)
Return a 200 OK application/binary response with content-disposition
attachment.
|
protected static void |
renderBinary(InputStream is,
String name,
long length,
String contentType,
boolean inline)
Return a 200 OK application/binary response with content-disposition
attachment.
|
protected static void |
renderBinary(InputStream is,
String name,
String contentType,
boolean inline)
Return a 200 OK application/binary response with content-disposition
attachment.
|
protected static void |
renderHtml(Object html)
Return a 200 OK text/html response
|
protected static void |
renderJSON(Object o)
Render a 200 OK application/json response
|
protected static void |
renderJSON(Object o,
com.google.gson.Gson gson)
Render a 200 OK application/json response.
|
protected static void |
renderJSON(Object o,
com.google.gson.JsonSerializer<?>... adapters)
Render a 200 OK application/json response.
|
protected static void |
renderJSON(Object o,
Type type)
Render a 200 OK application/json response
|
protected static void |
renderJSON(String jsonString)
Render a 200 OK application/json response
|
protected static void |
renderTemplate(Map<String,Object> args)
Render the template corresponding to the action's package-class-method
name (@see
template() ). |
protected static void |
renderTemplate(String templateName,
Map<String,Object> args)
Render a specific template.
|
protected static void |
renderTemplate(String templateName,
Object... args)
Render a specific template
|
protected static void |
renderText(CharSequence pattern,
Object... args)
Return a 200 OK text/plain response
|
protected static void |
renderText(Object text)
Return a 200 OK text/plain response
|
protected static void |
renderXml(Document xml)
Return a 200 OK text/xml response
|
protected static void |
renderXml(Object o)
Return a 200 OK text/xml response.
|
protected static void |
renderXml(Object o,
com.thoughtworks.xstream.XStream xstream)
Return a 200 OK text/xml response
|
protected static void |
renderXml(String xml)
Return a 200 OK text/xml response
|
protected static Router.ActionDefinition |
reverse() |
protected static void |
suspend(int millis)
Deprecated.
|
protected static void |
suspend(String timeout)
Deprecated.
|
protected static String |
template()
Work out the default template to load for the invoked action.
|
protected static String |
template(String templateName)
Work out the default template to load for the action.
|
protected static boolean |
templateExists(String templateName) |
protected static void |
todo()
Send a todo response
|
protected static void |
unauthorized()
Send a 401 Unauthorized response
|
protected static void |
unauthorized(String realm)
Send a 401 Unauthorized response
|
protected static void |
waitFor(Future<?> task)
Deprecated.
|
protected static Http.Request request
protected static Http.Response response
protected static Scope.Session session
protected static Scope.Flash flash
protected static Scope.Params params
protected static Scope.RenderArgs renderArgs
protected static Scope.RouteArgs routeArgs
protected static Validation validation
public static final ThreadLocal<Router.ActionDefinition> _currentReverse
protected static void renderText(Object text)
text
- The response contentprotected static void renderHtml(Object html)
html
- The response contentprotected static void renderText(CharSequence pattern, Object... args)
pattern
- The response content to be formatted (with String.format)args
- Args for String.formatprotected static void renderXml(String xml)
xml
- The XML stringprotected static void renderXml(Document xml)
xml
- The DOM document objectprotected static void renderXml(Object o)
o
- the object to serializeprotected static void renderXml(Object o, com.thoughtworks.xstream.XStream xstream)
o
- the object to serializexstream
- the XStream object to use for serialization. See XStream's
documentation for details about customizing the output.protected static void renderBinary(InputStream is)
is
- The stream to copyprotected static void renderBinary(InputStream is, long length)
is
- The stream to copylength
- Stream's size in bytes.protected static void renderBinary(InputStream is, String name)
is
- The stream to copyname
- Name of file user is downloading.protected static void renderBinary(InputStream is, String name, long length)
is
- The stream to copy. Content is streamed.name
- Name of file user is downloading.length
- Stream's size in bytes.protected static void renderBinary(InputStream is, String name, boolean inline)
is
- The stream to copyname
- Name of file user is downloading.inline
- true to set the response Content-Disposition to inlineprotected static void renderBinary(InputStream is, String name, long length, boolean inline)
is
- The stream to copyname
- The attachment namelength
- Stream's size in bytes.inline
- true to set the response Content-Disposition to inlineprotected static void renderBinary(InputStream is, String name, String contentType, boolean inline)
is
- The stream to copyname
- The attachment namecontentType
- The content type of the attachmentinline
- true to set the response Content-Disposition to inlineprotected static void renderBinary(InputStream is, String name, long length, String contentType, boolean inline)
is
- The stream to copyname
- The attachment namelength
- Content's byte size.contentType
- The content type of the attachmentinline
- true to set the response Content-Disposition to inlineprotected static void renderBinary(File file)
file
- The file to copyprotected static void renderBinary(File file, String name)
file
- The file to copyname
- The attachment nameprotected static void renderJSON(String jsonString)
jsonString
- The JSON stringprotected static void renderJSON(Object o)
o
- The Java object to serializeprotected static void renderJSON(Object o, Type type)
o
- The Java object to serializetype
- The Type information for complex generic typesprotected static void renderJSON(Object o, com.google.gson.JsonSerializer<?>... adapters)
o
- The Java object to serializeadapters
- A set of GSON serializers/deserializers/instance creator to
useprotected static void renderJSON(Object o, com.google.gson.Gson gson)
o
- The Java object to serializegson
- The GSON serializer object useprotected static void notModified()
protected static void badRequest(String msg)
protected static void badRequest()
protected static void unauthorized(String realm)
realm
- The realm nameprotected static void unauthorized()
protected static void notFound(String what)
what
- The Not Found resource nameprotected static void ok()
protected static void todo()
protected static void notFoundIfNull(Object o)
o
- The object to checkprotected static void notFoundIfNull(Object o, String what)
o
- The object to checkwhat
- The Not Found resource nameprotected static void notFound()
protected static void checkAuthenticity()
protected static void forbidden(String reason)
reason
- The reasonprotected static void forbidden()
protected static void error(int status, String reason)
status
- The exact status codereason
- The reasonprotected static void error(String reason)
reason
- The reasonprotected static void error(Exception reason)
reason
- The reasonprotected static void error()
protected static void flash(String key, Object value)
key
- The keyvalue
- The valueprotected static void redirect(String url)
url
- The Location to redirectprotected static void redirectToStatic(String file)
file
- The Location to redirectprotected static void redirect(String url, boolean permanent)
url
- The Location to redirectpermanent
- true -> 301, false -> 302public static void redirect(String action, Object... args)
action
- The fully qualified action name (ex: Application.index)args
- Method argumentsprotected static void redirect(String action, boolean permanent, Object... args)
action
- The fully qualified action name (ex: Application.index)permanent
- true -> 301, false -> 302args
- Method argumentsprotected static boolean templateExists(String templateName)
protected static void renderTemplate(String templateName, Object... args)
templateName
- The template nameargs
- The template dataprotected static void renderTemplate(String templateName, Map<String,Object> args)
templateName
- The template name.args
- The template data.protected static void renderTemplate(Map<String,Object> args)
template()
).args
- The template data.protected static void render(Object... args)
template()
).args
- The template dataprotected static String template()
protected static String template(String templateName)
protected static <T extends Annotation> T getActionAnnotation(Class<T> clazz)
clazz
- The annotation classprotected static <T extends Annotation> T getControllerAnnotation(Class<T> clazz)
clazz
- The annotation classprotected static <T extends Annotation> T getControllerInheritedAnnotation(Class<T> clazz)
clazz
- The annotation classprotected static Class<? extends Controller> getControllerClass()
@Deprecated protected static void parent(Object... args)
@Deprecated protected static void parent()
@Deprecated protected static void parent(Map<String,Object> map)
@Deprecated protected static void suspend(String timeout)
Important: The method will not resume on the line after you call this. The method will be called again as if there was a new HTTP request.
timeout
- Period of time to wait, e.g. "1h" means 1 hour.@Deprecated protected static void suspend(int millis)
Important: The method will not resume on the line after you call this. The method will be called again as if there was a new HTTP request.
millis
- Number of milliseconds to wait until trying again.@Deprecated protected static void waitFor(Future<?> task)
Important: The method will not resume on the line after you call this. The method will be called again as if there was a new HTTP request.
task
- protected static void await(String timeout)
protected static void await(int millis)
protected static void await(int millis, F.Action0 callback)
protected static <T> T await(Future<T> future)
protected static Router.ActionDefinition reverse()
ActionDefinition action = reverse(); {
Application.anyAction(anyParam, "toto");
}
String url = action.url;
public static void registerTemplateNameResolver(Controller.ITemplateNameResolver templateNameResolver)
Guillaume Bort & zenexity - Distributed under Apache 2 licence, without any warrantly