removed all references to Scotts' JSON Service and Screens
git-svn-id: https://svn.apache.org/repos/asf/turbine/core/branches/TURBINE_2_3_3@719957 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/turbine/modules/screens/JSONScreen.java b/src/java/org/apache/turbine/modules/screens/JSONScreen.java
deleted file mode 100644
index d1b5c6a..0000000
--- a/src/java/org/apache/turbine/modules/screens/JSONScreen.java
+++ /dev/null
@@ -1,140 +0,0 @@
-package org.apache.turbine.modules.screens;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.BufferedReader;
-import java.io.PrintWriter;
-import java.io.CharArrayWriter;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.turbine.modules.screens.RawScreen;
-import org.apache.turbine.services.jsonrpc.TurbineJsonRpc;
-import org.apache.turbine.util.RunData;
-
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
-
-/**
- * A Screen class for dealing with JSON-RPC requests. Typically you would
- * extend this class and override the doOutput() method to use TurbineJsonRpc
- * to register the POJOs that will provide the functions you are making
- * available via JSON-RPC. Use JSONSecureScreen if you need the user to be
- * logged in prior to executing the functions you provide.
- *
- * <p>Here is an example from a superclass:
- * <code>
- * public void doOutput(RunData data) throws Exception
- * {
- * User user = data.getUser();
- *
- * MyJsonFunctions myFunctions = new MyJsonFunctions(user.getName());
- *
- * // Session specific
- * TurbineJsonRpc.registerObject(data.getSession(), "myFunctions", myFunctions);
- *
- * // Global
- * //TurbineJsonRpc.registerObjectGlobal("testGlobal", testObject);
- *
- * super.doOutput(data);
- * }
- * </code>
- *
- * <p>The class MyFunctions would be something like:
- * <code>
- * public class MyJsonFunctions
- * {
- * private String getHello(String clientParameter)
- * {
- * return "Hello " + clientParameter;
- * }
- * }
- * </code>
- *
- * <p>This code is derived from the com.metaparadigm.jsonrpc.JSONRPCServlet
- *
- * @author brad@folkens.com
- * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
- * @version $Id$
- */
-public class JSONScreen extends RawScreen
-{
- protected static final String JSONRPC_CONTENT_TYPE = "text/plain";
-
- protected final static int BUFFER_SIZE = 4096;
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.turbine.modules.screens.RawScreen#getContentType(org.apache.turbine.util.RunData)
- */
- protected String getContentType(RunData data)
- {
- return JSONRPC_CONTENT_TYPE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.turbine.modules.screens.RawScreen#doOutput(org.apache.turbine.util.RunData)
- */
-
- /**
- * Output the dynamic content.
- *
- * @param data The RunData object.
- */
- protected void doOutput(RunData data) throws Exception
- {
- data.declareDirectResponse();
- HttpServletRequest request = data.getRequest();
-
- //String charset = request.getCharacterEncoding();
- //if(charset == null)
- //{
- // charset = "UTF-8";
- //}
- //BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), charset));
- BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream()));
-
- // Read the request
- CharArrayWriter cdata = new CharArrayWriter();
- char buf[] = new char[BUFFER_SIZE];
- int ret;
- while ((ret = in.read(buf, 0, BUFFER_SIZE)) != -1)
- {
- cdata.write(buf, 0, ret);
- }
-
- // Find the JSONRPCBridge for this session or create one
- // if it doesn't exist
- JSONRPCBridge json_bridge = TurbineJsonRpc.getBridge(data.getSession());
-
- // Process the request
- Object json_res = TurbineJsonRpc.processCall(cdata, json_bridge, request);
-
- PrintWriter out = new PrintWriter(
- new OutputStreamWriter(data.getResponse().getOutputStream()));
- out.print(json_res.toString());
- out.flush();
- out.close();
- }
-}
diff --git a/src/java/org/apache/turbine/modules/screens/JSONSecureScreen.java b/src/java/org/apache/turbine/modules/screens/JSONSecureScreen.java
deleted file mode 100644
index b86c747..0000000
--- a/src/java/org/apache/turbine/modules/screens/JSONSecureScreen.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package org.apache.turbine.modules.screens;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.turbine.modules.screens.JSONScreen;
-import org.apache.turbine.util.RunData;
-
-/**
- * An extension to JSONScreen that performs a Security Check before invoking
- * doBuildTemplate(). You should extend this class and add the specific
- * security check needed. If you have a number of screens that need to perform
- * the same check, you could make a base screen by extending this class and
- * implementing the isAuthorized(). Then each screen that needs to perform the
- * same check could extend your base screen.
- *
- * <p>Typically you would extend this class and override the doOutput() method
- * to use TurbineJsonRpc to register the POJOs that will provide the functions
- * you are making available via JSON-RPC. Use JSONScreen if you <p>do not</b>
- * need the user to be logged in prior to executing the functions you provide.
- *
- * <p>Here is an example from a superclass:
- * <code>
- * public void doOutput(RunData data) throws Exception
- * {
- * User user = data.getUser();
- *
- * MySecureJsonFunctions myFunctions
- * = new MySecureJsonFunctions(user.getName());
- *
- * // Session specific
- * TurbineJsonRpc.registerObject(data.getSession(), "myFunctions", myFunctions);
- *
- * // Global
- * //TurbineJsonRpc.registerObjectGlobal("testGlobal", testObject);
- *
- * super.doOutput(data);
- * }
- * </code>
- *
- * <p>The class MyFunctions would be something like:
- * <code>
- * public class MySecureJsonFunctions
- * {
- * private final String name;
- *
- * public MySecureJsonFunctions(String name)
- * {
- * this.name = name;
- * }
- *
- * private String getName(String clientParameter)
- * {
- * return "Client " + clientParameter + " says Hello World to " + name;
- * }
- * }
- * </code>
- *
- * @author <a href="mailto:seade@policypoint.net">Scott Eade</a>
- * @version $Id$
- */
-public abstract class JSONSecureScreen extends JSONScreen
-{
- /**
- * This method overrides the method in JSONScreen to perform a security
- * check prior to producing the output.
- *
- * @param data Turbine information.
- * @exception Exception, a generic exception.
- */
- protected void doOutput(RunData data) throws Exception
- {
- if (isAuthorized(data))
- {
- super.doOutput(data);
- }
- }
-
- /**
- * Override this method to perform the necessary security checks.
- *
- * @param data Turbine information.
- * @return <code>true</code> if the user is authorized to access the screen.
- * @exception Exception A generic exception.
- */
- protected abstract boolean isAuthorized(RunData data)
- throws Exception;
-}
diff --git a/src/java/org/apache/turbine/services/jsonrpc/JSONProcessor.java b/src/java/org/apache/turbine/services/jsonrpc/JSONProcessor.java
deleted file mode 100644
index 7f95bc7..0000000
--- a/src/java/org/apache/turbine/services/jsonrpc/JSONProcessor.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package org.apache.turbine.services.jsonrpc;
-
-import java.io.CharArrayWriter;
-import java.text.ParseException;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
-import com.metaparadigm.jsonrpc.JSONRPCResult;
-
-public class JSONProcessor
-{
- /** Log. */
- private static Log log = LogFactory.getLog(JSONProcessor.class);
-
- public static Object processCall(CharArrayWriter cdata, JSONRPCBridge json_bridge, HttpServletRequest request)
- {
- // Process the request
- JSONObject json_req = null;
- Object json_res = null;
- try
- {
- json_req = new JSONObject(cdata.toString());
- if (log.isDebugEnabled())
- {
- String methodName = (String) json_req.getString("method");
- JSONArray arguments = json_req.getJSONArray("params");
-
- // If this a CallableReference it will have a non-zero objectID
- int object_id = json_req.optInt("objectID");
- StringBuffer sb = new StringBuffer(".doprocessCall(): call ");
- if (object_id != 0)
- {
- sb.append("objectID=").append(object_id).append(" ");
- }
- sb.append(methodName).append("(").append(arguments).append(")");
- log.debug(sb.toString());
- }
- //json_res = json_bridge.call(new Object[] {request}, object_id, methodName, arguments);
- json_res = json_bridge.call(new Object[] {request}, json_req);
- }
- catch (ParseException e)
- {
- log.error(".processCall(): can't parse call: " + cdata, e);
- json_res = JSONRPCResult.MSG_ERR_PARSE;
- }
- // Write the response
- if (log.isDebugEnabled())
- {
- log.debug(".processCall(): returns " + json_res.toString());
- }
- return json_res;
- }
-
-}
diff --git a/src/java/org/apache/turbine/services/jsonrpc/JsonRpcService.java b/src/java/org/apache/turbine/services/jsonrpc/JsonRpcService.java
deleted file mode 100644
index 7f6f3ad..0000000
--- a/src/java/org/apache/turbine/services/jsonrpc/JsonRpcService.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.apache.turbine.services.jsonrpc;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.CharArrayWriter;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.apache.turbine.services.Service;
-
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
-
-/**
- * The interface an JsonRpcService implements.
- *
- * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
- * @version $Id$
- */
-public interface JsonRpcService
- extends Service
-{
- /** TurbineJsonRpcService. */
- public static final String SERVICE_NAME = "JsonRpcService";
-
- public Object processCall(CharArrayWriter cdata,
- JSONRPCBridge json_bridge, HttpServletRequest request);
-
- public void registerObject(HttpSession session, String key, Object value);
-
- public void registerObjectGlobal(String key, Object value);
-
- public JSONRPCBridge getBridge(HttpSession session);
-
- public void clearBridge(HttpSession session);
-}
diff --git a/src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpc.java b/src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpc.java
deleted file mode 100644
index c92e6ea..0000000
--- a/src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpc.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package org.apache.turbine.services.jsonrpc;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.CharArrayWriter;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.apache.turbine.services.TurbineServices;
-
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
-
-/**
- * This is a static accessor class for {@link JsonRpcService}.
- *
- * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
- * @version $Id$
- */
-public abstract class TurbineJsonRpc
-{
- /**
- * Returns system's configured implementation of {@link JsonRpcService}.
- *
- * @return an implementation of <code>JsonRpcService</code>
- */
- public static JsonRpcService getService()
- {
- return (JsonRpcService) TurbineServices.getInstance()
- .getService(JsonRpcService.SERVICE_NAME);
- }
-
- public static Object processCall(CharArrayWriter cdata,
- JSONRPCBridge json_bridge, HttpServletRequest request)
- {
- return getService().processCall(cdata, json_bridge, request);
- }
-
- public static void registerObject(HttpSession session, String key, Object value)
- {
- getService().registerObject(session, key, value);
- }
-
- public static void registerObjectGlobal(String key, Object value)
- {
- getService().registerObjectGlobal(key, value);
- }
-
- public static JSONRPCBridge getBridge(HttpSession session)
- {
- return getService().getBridge(session);
- }
-
- public static void clearBridge(HttpSession session)
- {
- getService().clearBridge(session);
- }
-}
diff --git a/src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpcService.java b/src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpcService.java
deleted file mode 100644
index 8b2a960..0000000
--- a/src/java/org/apache/turbine/services/jsonrpc/TurbineJsonRpcService.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.apache.turbine.services.jsonrpc;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.CharArrayWriter;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.turbine.services.TurbineBaseService;
-
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
-
-/**
- * This is a service that will respond to JSON-RPC calls.
- *
- * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
- * @version $Id$
- */
-public class TurbineJsonRpcService
- extends TurbineBaseService
- implements JsonRpcService
-{
- /** Log. */
- private static Log log = LogFactory.getLog(TurbineJsonRpcService.class);
-
- /** The key used to store the bridge in the session. */
- public static final String JSON_BRIDGE_KEY = "JSONRPCBridge";
- /**
- * The debug option for the bridge can be enabled by enabling debug level
- * logging for this class.
- */
- private static final boolean DEBUG = log.isDebugEnabled();
-
- public Object processCall(CharArrayWriter cdata,
- JSONRPCBridge json_bridge, HttpServletRequest request)
- {
- return JSONProcessor.processCall(cdata, json_bridge, request);
- }
-
- public void registerObjectGlobal(String key, Object value)
- {
- JSONRPCBridge.getGlobalBridge().setDebug(DEBUG);
- JSONRPCBridge.getGlobalBridge().registerObject(key, value);
- }
-
- public void registerObject(HttpSession session, String key, Object value)
- {
- JSONRPCBridge json_bridge = getBridge(session);
- json_bridge.setDebug(DEBUG);
- json_bridge.registerObject(key, value);
- }
-
- public JSONRPCBridge getBridge(HttpSession session)
- {
- JSONRPCBridge json_bridge = (JSONRPCBridge) session.getAttribute(JSON_BRIDGE_KEY);
- if (json_bridge == null)
- {
- json_bridge = new JSONRPCBridge();
- session.setAttribute(JSON_BRIDGE_KEY, json_bridge);
- }
- return json_bridge;
- }
-
- public void clearBridge(HttpSession session)
- {
- session.removeAttribute(JSON_BRIDGE_KEY);
- }
-
-// The following is modeled on XmlRpcSercice.
-// /**
-// * Initialize the JsonRpcService.
-// *
-// * @throws InitializationException Something went wrong in the init stage.
-// */
-// public void init() throws InitializationException
-// {
-// //Configuration conf = getConfiguration();
-// setInit(true);
-// }
-//
-// /**
-// * Shuts down this service, stopping running threads.
-// */
-// public void shutdown()
-// {
-// setInit(false);
-// }
-
-}
diff --git a/src/java/org/apache/turbine/services/jsonrpc/package.html b/src/java/org/apache/turbine/services/jsonrpc/package.html
deleted file mode 100644
index 14711c3..0000000
--- a/src/java/org/apache/turbine/services/jsonrpc/package.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<html>
-<head>
-<!-- head part is ignored -->
-</head>
-
-<body>
-The JSON-RPC Service supports JavaScript to Java AJAX communications between
-browsers and Turbine applications.<br />
-<font size="-2">$Id$</font>
-</body>
-</html>
diff --git a/src/test/org/apache/turbine/services/jsonrpc/JsonrpcServicelTest.java b/src/test/org/apache/turbine/services/jsonrpc/JsonrpcServicelTest.java
deleted file mode 100644
index 3e21ccf..0000000
--- a/src/test/org/apache/turbine/services/jsonrpc/JsonrpcServicelTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package org.apache.turbine.services.jsonrpc;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.apache.turbine.test.BaseTurbineTest;
-
-import com.metaparadigm.jsonrpc.JSONRPCBridge;
-
-
-public class JsonrpcServicelTest
- extends BaseTurbineTest
-{
- public JsonrpcServicelTest(String name)
- throws Exception
- {
- super(name, "conf/test/TurbineResources.properties");
- }
-
- public static Test suite()
- {
- return new TestSuite(JsonrpcServicelTest.class);
- }
-
- public void testBridgeAccess()
- {
- JSONRPCBridge bridge = new JSONRPCBridge();
- assertNotNull(bridge);
- }
-
-}
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 97b9308..c05a13a 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -158,12 +158,6 @@
and for integer ranges.
</action>
<action type="add" dev="seade">
- Added JSON-RPC Service to support JavaScript to Java AJAX communications
- using <a href="http://oss.metaparadigm.com/jsonrpc/">JSON-RPC-Java</a>.
- For further details see <a href="services/jsonrpc-service.html">JSON-RPC
- Service</a>.
- </action>
- <action type="add" dev="seade">
Added UI Service as a replacement for the UIManager pull tool (now
deprecated in favor of the backwards compatible UITool).
For further details see <a href="services/ui-service.html">UI Service</a>.
diff --git a/xdocs/services/index.xml b/xdocs/services/index.xml
index 03572c2..64f3480 100644
--- a/xdocs/services/index.xml
+++ b/xdocs/services/index.xml
@@ -112,13 +112,6 @@
</li>
<li>
-<a href="jsonrpc-service.html">JSON-RPC Service</a>
-<br/>
-The JSON-RPC Service supports JavaScript to Java AJAX communications using
-<a href="http://oss.metaparadigm.com/jsonrpc/">JSON-RPC-Java</a>.
-</li>
-
-<li>
<a href="jsp-service.html">JSP Service</a>
<br/>
The JSP Service is the set of classes that process JSP files inside the
diff --git a/xdocs/services/jsonrpc-service.xml b/xdocs/services/jsonrpc-service.xml
deleted file mode 100644
index c942cc6..0000000
--- a/xdocs/services/jsonrpc-service.xml
+++ /dev/null
@@ -1,199 +0,0 @@
-<?xml version="1.0"?>
-
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-
-<document>
-
- <properties>
- <title>Turbine Services - JSON-RPC Service</title>
- <author email="seade@backstagetech.com.au">Scott Eade</author>
- </properties>
-
-<body>
-
-<section name="JSON-RPC Service">
-
-<p>
-The JSON-RPC Service supports JavaScript to Java AJAX communications using
-<a href="http://oss.metaparadigm.com/jsonrpc/">JSON-RPC-Java</a>.
-</p>
-
-</section>
-
-<section name="Configuration">
-
-<source><![CDATA[
-# -------------------------------------------------------------------
-#
-# S E R V I C E S
-#
-# -------------------------------------------------------------------
-...
-services.JsonRpcService.classname=org.apache.turbine.services.jsonrpc.TurbineJsonRpcService
-...
-]]></source>
-
-</section>
-
-<section name="Usage">
-
-<p>
-There are a number of things you need to do in order to add AJAX functionality
-to your webapp. First you implement the functions:
-</p>
-
-<source><![CDATA[
-public class MyJsonFunctions
-{
- private String getHello(String clientParameter)
- {
- return "Hello " + clientParameter;
- }
- private String getGoodbye(String clientParameter)
- {
- return "Goodbye " + clientParameter;
- }
-}
-]]></source>
-
-<p>
-Next you implement your Screen class to make your functions available:
-</p>
-
-<source><![CDATA[
-public class MyJsonScreen extends JSONScreen
-{
- public void doOutput(RunData data) throws Exception
- {
- User user = data.getUser();
-
- MyJsonFunctions myFunctions = new MyJsonFunctions(user.getName());
-
- // Session specific
- TurbineJsonRpc.registerObject(data.getSession(), "myFunctions", myFunctions);
-
- // Global
- //TurbineJsonRpc.registerObjectGlobal("testGlobal", testObject);
-
- super.doOutput(data);
- }
-}
-]]></source>
-
-<p>
-Now we shift focus to your template classes. Firstly, there are a few useful
-utility functions that you need to make sure are available to the pages that
-will include AJAX functionality:
-</p>
-
-<source><![CDATA[
-// Body onload utility (supports multiple onload functions)
-function SafeAddOnload(func) {
- var oldonload = window.onload;
- if (typeof window.onload != 'function') {
- window.onload = func;
- } else {
- window.onload = function() {
- oldonload();
- func();
- };
- }
-}
-
-// Prepare for possible JSON-RPC requests.
-// jsonurl must be set before calling this function.
-function jsonOnLoad() {
- try {
- jsonrpc = new JSONRpcClient(jsonurl);
- }
- catch(e) {
- if(e.message) {
- alert(e.message);
- }
- else {
- alert(e);
- }
- }
-}
-
-// Process a JSON-RPC request.
-function jsonEval(evalStr) {
- try {
- return eval(evalStr);
- }
- catch(e) {
- if(e.javaStack) {
- alert("Exception: \n\n" + e.javaStack);
- }
- else {
- alert("Exception: \n\n" + e);
- }
- }
- return null;
-}
-]]></source>
-
-<p>
-In these pages you also need to include the JavaScript necessary to process the
-JSON calls - this file is available as part of the JSON-RPC-Java distribution
-(it is included in the <code>webapps\jaonrpc</code> directory):
-</p>
-
-<source><![CDATA[
-$page.addScript($content.getURI('scripts/jsonrpc.js'))
-]]></source>
-
-<p>
-Then you need to set up the specific handler for the page:
-</p>
-
-<source><![CDATA[
-<script type="text/javascript">
-<!--
- ## Set up the JSON-RPC handler.
- var jsonurl = '$link.setScreen("MyJsonScreen")';
- SafeAddOnload(jsonOnLoad);
- ## myArg below would be provided when you call this function from your
- ## web page (usually you would retrieve something via the DOM or your
- ## favorite JavaScript DOM wrapper library).
- function retrieveHello(myArg) {
- ## This is a synchronous call.
- var helloResult = jsonEval("jsonrpc.myFunctions.getHello(" + myArg + ")");
- if(null == helloResult) {
- alert('Something went wrong!');
- return;
- }
- ## Here you would again use the DOM to include the result somewhere on your
- ## page.
- }
-//-->
-</script>
-]]></source>
-
-<p>
-The above code is executable by users that are not logged into your application.
-Your Screen class can extend JSONSecureScreen to require that users be logged in
-before allowing execution.
-</p>
-
-</section>
-
-</body>
-</document>