001 /* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019 package org.apache.wiki.plugin; 020 021 import java.util.Map; 022 023 import org.apache.wiki.WikiContext; 024 import org.apache.wiki.api.exceptions.PluginException; 025 import org.apache.wiki.api.plugin.WikiPlugin; 026 import org.apache.wiki.rpc.RPCCallable; 027 import org.apache.wiki.rpc.json.JSONRPCManager; 028 029 /** 030 * Simple plugin which shows how to add JSON calls to your plugin. 031 * 032 * <p>Parameters : </p> 033 * NONE 034 * 035 * @since 2.5.4 036 */ 037 public class RPCSamplePlugin implements WikiPlugin, RPCCallable 038 { 039 /** 040 * This method is called when the Javascript is encountered by 041 * the browser. 042 * @param echo The parameter 043 * @return the string <code>JSON says:</code>, plus the value 044 * supplied by the <code>echo</code> parameter 045 * 046 * <p>Parameters : </p> 047 * NONE 048 */ 049 public String myFunction(String echo) 050 { 051 return "JSON says: "+echo; 052 } 053 054 055 /** 056 * {@inheritDoc} 057 */ 058 public String execute(WikiContext context, Map<String, String> params) throws PluginException 059 { 060 JSONRPCManager.registerJSONObject( context, this ); 061 062 String s = JSONRPCManager.emitJSONCall( context, this, "myFunction", "'foo'" ); 063 064 return s; 065 } 066 067 }