com.ecyrd.jspwiki.rpc.json
Class JSONRPCManager

java.lang.Object
  extended by com.ecyrd.jspwiki.rpc.RPCManager
      extended by com.ecyrd.jspwiki.rpc.json.JSONRPCManager

public final class JSONRPCManager
extends RPCManager

Provides an easy-to-use interface for different modules to AJAX-enable themselves. This class is a static class, so it cannot be instantiated, but it easily available from anywhere (including JSP pages).

Any object which wants to expose its methods through JSON calls, needs to implement the RPCCallable interface. JSONRPCManager will expose all methods, so be careful which you want to expose.

Due to some limitations of the JSON-RPC library, we do not use the Global bridge object.

Since:
2.5.4
See Also:
RPCCallable

Method Summary
static String emitJSONCall(WikiContext context, RPCCallable c, String function, String params)
          Emits JavaScript to do a JSON RPC Call.
static void registerGlobalObject(String id, RPCCallable object)
          Registers a global object (i.e. something which can be called by any JSP page).
static void registerGlobalObject(String id, RPCCallable object, Permission perm)
          Registers a global object (i.e. something which can be called by any JSP page) with a specific permission.
static String registerJSONObject(WikiContext context, RPCCallable c)
          Registers a callable to JSON global bridge and requests JSON libraries to be added to the page.
static void requestJSON(WikiContext context)
          Requests the JSON Javascript and object to be generated in the HTML.
static void sessionCreated(HttpSession session)
          Is called whenever a session is created.
 
Methods inherited from class com.ecyrd.jspwiki.rpc.RPCManager
getId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

emitJSONCall

public static String emitJSONCall(WikiContext context,
                                  RPCCallable c,
                                  String function,
                                  String params)
Emits JavaScript to do a JSON RPC Call. You would use this method e.g. in your plugin generation code to embed an AJAX call to your object.

Parameters:
context - The Wiki Context
c - An RPCCallable object
function - Name of the method to call
params - Parameters to pass to the method
Returns:
generated JavasSript code snippet that calls the method

registerJSONObject

public static String registerJSONObject(WikiContext context,
                                        RPCCallable c)
Registers a callable to JSON global bridge and requests JSON libraries to be added to the page.

Parameters:
context - The WikiContext.
c - The RPCCallable to register
Returns:
the ID of the registered callable object

requestJSON

public static void requestJSON(WikiContext context)
Requests the JSON Javascript and object to be generated in the HTML.

Parameters:
context - The WikiContext.

registerGlobalObject

public static void registerGlobalObject(String id,
                                        RPCCallable object)
Registers a global object (i.e. something which can be called by any JSP page). Typical examples is e.g. "search". By default, the RPCCallable shall need a "view" permission to access.

Parameters:
id - The name under which this shall be registered (e.g. "search")
object - The RPCCallable which shall be associated to this id.

registerGlobalObject

public static void registerGlobalObject(String id,
                                        RPCCallable object,
                                        Permission perm)
Registers a global object (i.e. something which can be called by any JSP page) with a specific permission.

Parameters:
id - The name under which this shall be registered (e.g. "search")
object - The RPCCallable which shall be associated to this id.
perm - The permission which is required to access this object.

sessionCreated

public static void sessionCreated(HttpSession session)
Is called whenever a session is created. This method creates a new JSONRPCBridge and adds it to the user session. This is done because the global JSONRPCBridge InvocationCallbacks are not called; only session locals. This may be a bug in JSON-RPC, or it may be a design feature...

The JSONRPCBridge object will go away once the session expires.

Parameters:
session - The HttpSession which was created.