net.sue445.kulib.controller
Class JsonController

java.lang.Object
  extended by org.slim3.controller.Controller
      extended by org.slim3.controller.SimpleController
          extended by net.sue445.kulib.controller.JsonController

public abstract class JsonController
extends SimpleController

A Controller which is print response as JSON or JSONP

 example
 
 public Navigation run() throws Exception {
     String json = ... ;
     String jsonp = toJsonp(json);
     return responseJson(jsonp);
 }
 
 

Since:
0.0.4
Author:
sue445

Field Summary
protected  String callback
          JSONP callback
protected static String CONTENT_TYPE_PREFIX
           
protected static Charset DEFAULT_CHARSET
           
 
Fields inherited from class org.slim3.controller.Controller
basePath, BUFFER_SIZE, errors, request, response, servletContext
 
Constructor Summary
JsonController()
           
 
Method Summary
protected  Navigation response(String content, Charset charset, String contentType)
          print string to response
protected  Navigation responseJson(String jsonContent)
          print json response(UTF-8) and finish contoller
protected  Navigation responseJson(String jsonContent, Charset charset)
          print json response and finish contoller
protected  Navigation setUp()
           
protected  String toJsonp(String jsonContent)
          if exists callback, add this to json content
 
Methods inherited from class org.slim3.controller.SimpleController
createRequestHandler
 
Methods inherited from class org.slim3.controller.Controller
applicationScope, applicationScope, asBoolean, asDate, asDouble, asDouble, asFloat, asFloat, asInteger, asInteger, asKey, asLong, asLong, asMap, asShort, asShort, asString, download, download, encodeFileName, forward, getForwardServletPath, handleError, isDelete, isDevelopment, isGet, isPost, isPut, param, paramValues, redirect, removeApplicationScope, removeRequestScope, removeSessionScope, requestScope, requestScope, run, runBare, sessionScope, sessionScope, show, show, tearDown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHARSET

protected static final Charset DEFAULT_CHARSET

CONTENT_TYPE_PREFIX

protected static final String CONTENT_TYPE_PREFIX
See Also:
Constant Field Values

callback

protected String callback
JSONP callback

Constructor Detail

JsonController

public JsonController()
Method Detail

setUp

protected Navigation setUp()
Overrides:
setUp in class Controller

toJsonp

protected String toJsonp(String jsonContent)
if exists callback, add this to json content

Parameters:
jsonContent -
Returns:

responseJson

protected Navigation responseJson(String jsonContent)
                           throws IOException
print json response(UTF-8) and finish contoller

Parameters:
jsonContent -
Returns:
Throws:
IOException

responseJson

protected Navigation responseJson(String jsonContent,
                                  Charset charset)
                           throws IOException
print json response and finish contoller

Parameters:
jsonContent -
charset -
Returns:
Throws:
IOException

response

protected Navigation response(String content,
                              Charset charset,
                              String contentType)
                       throws IOException
print string to response

Parameters:
content -
charset -
contentType -
Returns:
Throws:
IOException


Copyright © 2013. All Rights Reserved.