play.mvc
Class Controller

java.lang.Object
  extended by play.mvc.Controller
All Implemented Interfaces:
ControllersEnhancer.ControllerSupport, LocalvariablesNamesEnhancer.LocalVariablesSupport

public abstract class Controller
extends java.lang.Object
implements ControllersEnhancer.ControllerSupport, LocalvariablesNamesEnhancer.LocalVariablesSupport

Application controller support


Field Summary
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 (used in templates)
protected static Http.Request request
          The current HTTP request
protected static Http.Response response
          The current HTTP response
protected static Scope.Session session
          The current HTTP session
protected static Validation validation
          The current Validation
 
Constructor Summary
Controller()
           
 
Method Summary
protected static void error()
          Send a 500 Error response
protected static void error(int status, java.lang.String reason)
          Send a 5xx Error response
protected static void error(java.lang.String reason)
          Send a 500 Error response
protected static void flash(java.lang.String key, java.lang.Object value)
          Add a value to the flash scope
protected static void forbidden()
          Send a 403 Forbidden response
protected static void forbidden(java.lang.String reason)
          Send a 403 Forbidden response
protected static
<T extends java.lang.annotation.Annotation>
T
getActionAnnotation(java.lang.Class<T> clazz)
          Retrieve annotation for the action method
protected static
<T extends java.lang.annotation.Annotation>
T
getControllerAnnotation(java.lang.Class<T> clazz)
          Retrieve annotation for the controller class
protected static java.lang.Class getControllerClass()
          Retrieve annotation for the action method
protected static
<T extends java.lang.annotation.Annotation>
T
getControllerInheritedAnnotation(java.lang.Class<T> clazz)
          Retrieve annotation for the controller class
protected static void notFound()
          Send a 404 Not Found reponse
protected static void notFound(java.lang.String what)
          Send a 404 Not Found reponse
protected static void notFoundIfNull(java.lang.Object o)
          Send a 404 Not Found reponse if object is null
protected static void ok()
          Send a 200 OK reponse
protected static void parent()
          Call the parent method
protected static void parent(java.util.Map<java.lang.String,java.lang.Object> map)
          Call the parent action adding this objects to the params scope
protected static void parent(java.lang.Object... args)
          Call the parent action adding this objects to the params scope
protected static void redirect(java.lang.String url)
          Send a 302 redirect response.
protected static void redirect(java.lang.String url, boolean permanent)
          Send a Redirect response.
protected static void redirect(java.lang.String action, boolean permanent, java.lang.Object... args)
          Redirect to another action
protected static void redirect(java.lang.String action, java.lang.Object... args)
          302 Redirect to another action
protected static void redirectToStatic(java.lang.String file)
          Send a 302 redirect response.
protected static void render(java.lang.Object... args)
          Render the corresponding template
protected static void renderBinary(java.io.File file)
          Return a 200 OK application/binary response
protected static void renderBinary(java.io.File file, java.lang.String name)
          Return a 200 OK application/binary response with content-disposition attachment
protected static void renderBinary(java.io.InputStream is)
          Return a 200 OK application/binary response
protected static void renderBinary(java.io.InputStream is, java.lang.String name)
          Return a 200 OK application/binary response with content-disposition attachment
protected static void renderJSON(java.lang.Object o)
          Render a 200 OK application/json response
protected static void renderJSON(java.lang.Object o, com.google.gson.JsonSerializer... adapters)
          Render a 200 OK application/json response
protected static void renderJSON(java.lang.String jsonString)
          Render a 200 OK application/json response
protected static void renderTemplate(java.lang.String templateName, java.lang.Object... args)
          Render a specific template
protected static void renderText(java.lang.CharSequence pattern, java.lang.Object... args)
          Return a 200 OK text/plain response
protected static void renderText(java.lang.Object text)
          Return a 200 OK text/plain response
protected static void renderXml(org.w3c.dom.Document xml)
          Return a 200 OK text/xml response
protected static void renderXml(java.lang.String xml)
          Return a 200 OK text/xml response
protected static void suspend(java.lang.String timeout)
          Suspend the current request for a specified amount of time
protected static void unauthorized(java.lang.String realm)
          Send a 401 Unauthorized response
protected static void waitFor(java.util.concurrent.Future task)
          Suspend this request and wait for the task completion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

request

protected static Http.Request request
The current HTTP request


response

protected static Http.Response response
The current HTTP response


session

protected static Scope.Session session
The current HTTP session


flash

protected static Scope.Flash flash
The current flash scope


params

protected static Scope.Params params
The current HTTP params


renderArgs

protected static Scope.RenderArgs renderArgs
The current renderArgs (used in templates)


validation

protected static Validation validation
The current Validation

Constructor Detail

Controller

public Controller()
Method Detail

renderText

protected static void renderText(java.lang.Object text)
Return a 200 OK text/plain response

Parameters:
text - The response content

renderText

protected static void renderText(java.lang.CharSequence pattern,
                                 java.lang.Object... args)
Return a 200 OK text/plain response

Parameters:
text - The response content to be formatted (with String.format)
args - Args for String.format

renderXml

protected static void renderXml(java.lang.String xml)
Return a 200 OK text/xml response

Parameters:
xml - The XML string

renderXml

protected static void renderXml(org.w3c.dom.Document xml)
Return a 200 OK text/xml response

Parameters:
xml - The DOM document object

renderBinary

protected static void renderBinary(java.io.InputStream is)
Return a 200 OK application/binary response

Parameters:
is - The stream to copy

renderBinary

protected static void renderBinary(java.io.InputStream is,
                                   java.lang.String name)
Return a 200 OK application/binary response with content-disposition attachment

Parameters:
is - The stream to copy
name - The attachment name

renderBinary

protected static void renderBinary(java.io.File file)
Return a 200 OK application/binary response

Parameters:
file - The file to copy

renderBinary

protected static void renderBinary(java.io.File file,
                                   java.lang.String name)
Return a 200 OK application/binary response with content-disposition attachment

Parameters:
file - The file to copy
name - The attachment name

renderJSON

protected static void renderJSON(java.lang.String jsonString)
Render a 200 OK application/json response

Parameters:
jsonString - The JSON string

renderJSON

protected static void renderJSON(java.lang.Object o)
Render a 200 OK application/json response

Parameters:
o - The Java object to serialize

renderJSON

protected static void renderJSON(java.lang.Object o,
                                 com.google.gson.JsonSerializer... adapters)
Render a 200 OK application/json response

Parameters:
o - The Java object to serialize
adapters - A set of GSON serializers/deserializers/instance creator to use

unauthorized

protected static void unauthorized(java.lang.String realm)
Send a 401 Unauthorized response

Parameters:
realm - The realm name

notFound

protected static void notFound(java.lang.String what)
Send a 404 Not Found reponse

Parameters:
what - The Not Found resource name

ok

protected static void ok()
Send a 200 OK reponse


notFoundIfNull

protected static void notFoundIfNull(java.lang.Object o)
Send a 404 Not Found reponse if object is null

Parameters:
o - The object to check

notFound

protected static void notFound()
Send a 404 Not Found reponse


forbidden

protected static void forbidden(java.lang.String reason)
Send a 403 Forbidden response

Parameters:
reason - The reason

forbidden

protected static void forbidden()
Send a 403 Forbidden response


error

protected static void error(int status,
                            java.lang.String reason)
Send a 5xx Error response

Parameters:
status - The exact status code
reason - The reason

error

protected static void error(java.lang.String reason)
Send a 500 Error response

Parameters:
reason - The reason

error

protected static void error()
Send a 500 Error response


flash

protected static void flash(java.lang.String key,
                            java.lang.Object value)
Add a value to the flash scope

Parameters:
key - The key
value - The value

redirect

protected static void redirect(java.lang.String url)
Send a 302 redirect response.

Parameters:
url - The Location to redirect

redirectToStatic

protected static void redirectToStatic(java.lang.String file)
Send a 302 redirect response.

Parameters:
url - The Location to redirect

redirect

protected static void redirect(java.lang.String url,
                               boolean permanent)
Send a Redirect response.

Parameters:
url - The Location to redirect
permanent - true -> 301, false -> 302

redirect

protected static void redirect(java.lang.String action,
                               java.lang.Object... args)
302 Redirect to another action

Parameters:
action - The fully qualified action name (ex: Application.index)
args - Method arguments

redirect

protected static void redirect(java.lang.String action,
                               boolean permanent,
                               java.lang.Object... args)
Redirect to another action

Parameters:
action - The fully qualified action name (ex: Application.index)
permanent - true -> 301, false -> 302
args - Method arguments

renderTemplate

protected static void renderTemplate(java.lang.String templateName,
                                     java.lang.Object... args)
Render a specific template

Parameters:
templateName - The template name
args - The template data

render

protected static void render(java.lang.Object... args)
Render the corresponding template

Parameters:
templateName - The template name
args - The template data

getActionAnnotation

protected static <T extends java.lang.annotation.Annotation> T getActionAnnotation(java.lang.Class<T> clazz)
Retrieve annotation for the action method

Parameters:
clazz - The annotation class
Returns:
Annotation object or null if not found

getControllerAnnotation

protected static <T extends java.lang.annotation.Annotation> T getControllerAnnotation(java.lang.Class<T> clazz)
Retrieve annotation for the controller class

Parameters:
clazz - The annotation class
Returns:
Annotation object or null if not found

getControllerInheritedAnnotation

protected static <T extends java.lang.annotation.Annotation> T getControllerInheritedAnnotation(java.lang.Class<T> clazz)
Retrieve annotation for the controller class

Parameters:
clazz - The annotation class
Returns:
Annotation object or null if not found

getControllerClass

protected static java.lang.Class getControllerClass()
Retrieve annotation for the action method

Parameters:
clazz - The annotation class
Returns:
Annotation object or null if not found

parent

protected static void parent(java.lang.Object... args)
Call the parent action adding this objects to the params scope


parent

protected static void parent()
Call the parent method


parent

protected static void parent(java.util.Map<java.lang.String,java.lang.Object> map)
Call the parent action adding this objects to the params scope


suspend

protected static void suspend(java.lang.String timeout)
Suspend the current request for a specified amount of time


waitFor

protected static void waitFor(java.util.concurrent.Future task)
Suspend this request and wait for the task completion



Guillaume Bort & zenexity - Distributed under Apache 2 licence, without any warrantly