getAttributes()
{
- return m_attributes;
+ return attributes;
}
/**
@@ -312,7 +312,7 @@
*/
public Date getLockExpiry()
{
- return isLocked() ? m_lockExpiry : null;
+ return isLocked() ? lockExpiry : null;
}
/**
@@ -320,7 +320,7 @@
*/
public String getUid()
{
- return m_uid;
+ return uid;
}
/**
@@ -328,12 +328,12 @@
*/
public boolean isLocked()
{
- boolean locked = m_lockExpiry != null && System.currentTimeMillis() < m_lockExpiry.getTime();
+ boolean locked = lockExpiry != null && System.currentTimeMillis() < lockExpiry.getTime();
// Clear the lock if it's expired already
- if ( !locked && m_lockExpiry != null )
+ if ( !locked && lockExpiry != null )
{
- m_lockExpiry = null;
+ lockExpiry = null;
}
return locked;
}
@@ -343,7 +343,7 @@
*/
public void setLockExpiry( Date expiry )
{
- m_lockExpiry = expiry;
+ this.lockExpiry = expiry;
}
/**
@@ -351,6 +351,6 @@
*/
public void setUid( String uid )
{
- m_uid = uid;
+ this.uid = uid;
}
}
Index: jspwiki-war/src/main/java/org/apache/wiki/auth/UserManager.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/auth/UserManager.java (revision 1655294)
+++ jspwiki-war/src/main/java/org/apache/wiki/auth/UserManager.java (working copy)
@@ -18,6 +18,7 @@
*/
package org.apache.wiki.auth;
+import java.io.IOException;
import java.security.Permission;
import java.security.Principal;
import java.text.MessageFormat;
@@ -30,7 +31,9 @@
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@@ -37,6 +40,9 @@
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiSession;
+import org.apache.wiki.ajax.AjaxUtil;
+import org.apache.wiki.ajax.WikiAjaxDispatcherServlet;
+import org.apache.wiki.ajax.WikiAjaxServlet;
import org.apache.wiki.api.engine.FilterManager;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.WikiException;
@@ -53,8 +59,6 @@
import org.apache.wiki.filters.SpamFilter;
import org.apache.wiki.i18n.InternationalizationManager;
import org.apache.wiki.preferences.Preferences;
-import org.apache.wiki.rpc.RPCCallable;
-import org.apache.wiki.rpc.json.JSONRPCManager;
import org.apache.wiki.ui.InputValidator;
import org.apache.wiki.util.ClassUtil;
import org.apache.wiki.util.MailUtil;
@@ -97,6 +101,8 @@
protected static final String PREFS_FULL_NAME = "prefs.fullname";
protected static final String PREFS_EMAIL = "prefs.email";
+ public static final String JSON_USERS = "users";
+
// private static final String PROP_ACLMANAGER = "jspwiki.aclManager";
/** Associates wiki sessions with profiles */
@@ -125,7 +131,8 @@
// TODO: it would be better if we did this in PageManager directly
addWikiEventListener( engine.getPageManager() );
- JSONRPCManager.registerGlobalObject( "users", new JSONUserModule(this), new AllPermission(null) );
+ //TODO: Replace with custom annotations. See JSPWIKI-566
+ WikiAjaxDispatcherServlet.registerServlet( JSON_USERS, new JSONUserModule(this), new AllPermission(null));
}
/**
@@ -843,7 +850,7 @@
WikiEventManager.fireEvent(this,new WikiSecurityEvent(session,type,profile));
}
}
-
+
/**
* Implements the JSON API for usermanager.
*
@@ -851,9 +858,9 @@
* this gets reinstalled to the session when JSPWiki starts. This means
* that it's not actually necessary to save anything.
*/
- public static final class JSONUserModule implements RPCCallable
+ public static final class JSONUserModule implements WikiAjaxServlet
{
- private volatile UserManager m_manager;
+ private volatile UserManager m_manager;
/**
* Create a new JSONUserModule.
@@ -864,6 +871,27 @@
m_manager = mgr;
}
+ @Override
+ public String getServletMapping() {
+ return JSON_USERS;
+ }
+
+ public void service(HttpServletRequest req, HttpServletResponse resp, String actionName, List params) throws ServletException, IOException {
+ try {
+ String uid = null;
+ if (params.size()<1) {
+ uid = params.get(1);
+ }
+ log.debug("uid="+uid);
+ if (StringUtils.isNotBlank(uid)) {
+ UserProfile prof = getUserInfo(uid);
+ resp.getWriter().write(AjaxUtil.toJson(prof));
+ }
+ } catch (NoSuchPrincipalException e) {
+ throw new ServletException(e);
+ }
+ }
+
/**
* Directly returns the UserProfile object attached to an uid.
*
Index: jspwiki-war/src/main/java/org/apache/wiki/plugin/DefaultPluginManager.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/plugin/DefaultPluginManager.java (revision 1655294)
+++ jspwiki-war/src/main/java/org/apache/wiki/plugin/DefaultPluginManager.java (working copy)
@@ -20,6 +20,7 @@
package org.apache.wiki.plugin;
import org.apache.commons.lang.ClassUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.MatchResult;
@@ -29,9 +30,10 @@
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
import org.apache.wiki.InternalWikiException;
-import org.apache.wiki.WikiAjaxDispatcherServlet;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
+import org.apache.wiki.ajax.WikiAjaxDispatcherServlet;
+import org.apache.wiki.ajax.WikiAjaxServlet;
import org.apache.wiki.api.engine.PluginManager;
import org.apache.wiki.api.exceptions.PluginException;
import org.apache.wiki.api.plugin.InitializablePlugin;
@@ -546,7 +548,7 @@
m_pluginClassMap.put( name, pluginClass );
}
- pluginClass.initializePlugin( m_engine , m_searchPath, m_externalJars);
+ pluginClass.initializePlugin( pluginClass, m_engine , m_searchPath, m_externalJars);
}
private void registerPlugins() {
@@ -580,6 +582,7 @@
private String m_className;
private String m_alias;
+ private String m_ajaxAlias;
private Class> m_clazz;
private boolean m_initialized = false;
@@ -611,7 +614,7 @@
* @param searchPath A List of Strings, containing different package names.
* @param externalJars the list of external jars to search
*/
- protected void initializePlugin( WikiEngine engine , List searchPath, List externalJars) {
+ protected void initializePlugin( WikiPluginInfo info, WikiEngine engine , List searchPath, List externalJars) {
if( !m_initialized ) {
// This makes sure we only try once per class, even if init fails.
m_initialized = true;
@@ -621,8 +624,12 @@
if( p instanceof InitializablePlugin ) {
( ( InitializablePlugin )p ).initialize( engine );
}
- if( p instanceof HttpServlet ) {
- WikiAjaxDispatcherServlet.register( (HttpServlet) p );
+ if( p instanceof WikiAjaxServlet ) {
+ WikiAjaxDispatcherServlet.registerServlet( (WikiAjaxServlet) p );
+ String ajaxAlias = info.getAjaxAlias();
+ if (StringUtils.isNotBlank(ajaxAlias)) {
+ WikiAjaxDispatcherServlet.registerServlet( info.getAjaxAlias(), (WikiAjaxServlet) p );
+ }
}
} catch( Exception e ) {
log.info( "Cannot initialize plugin " + m_className, e );
@@ -637,6 +644,7 @@
protected void initializeFromXML( Element el ) {
super.initializeFromXML( el );
m_alias = el.getChildText( "alias" );
+ m_ajaxAlias = el.getChildText( "ajaxAlias" );
}
/**
@@ -674,6 +682,14 @@
public String getAlias() {
return m_alias;
}
+
+ /**
+ * Returns the ajax alias name for this object.
+ * @return An ajax alias name for the plugin.
+ */
+ public String getAjaxAlias() {
+ return m_ajaxAlias;
+ }
/**
* Creates a new plugin instance.
Index: jspwiki-war/src/main/java/org/apache/wiki/plugin/SampleAjaxPlugin.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/plugin/SampleAjaxPlugin.java (revision 1655294)
+++ jspwiki-war/src/main/java/org/apache/wiki/plugin/SampleAjaxPlugin.java (working copy)
@@ -19,48 +19,46 @@
package org.apache.wiki.plugin;
import java.io.IOException;
+import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.wiki.WikiContext;
+import org.apache.wiki.ajax.WikiAjaxServlet;
import org.apache.wiki.api.exceptions.PluginException;
import org.apache.wiki.api.plugin.WikiPlugin;
/**
- * @author David VIttor
- * @date 20/01/2015
* @since 2.10.2-svn10
*/
-public class SampleAjaxPlugin extends HttpServlet implements WikiPlugin {
- private static final long serialVersionUID = 1L;
+public class SampleAjaxPlugin implements WikiPlugin, WikiAjaxServlet {
+
+ private static final String SERVLET_MAPPING = "SampleAjaxPlugin";
@Override
public String execute(WikiContext context, Map params) throws PluginException {
String id = Integer.toString(this.hashCode());
- String baseUrl = context.getEngine().getBaseURL();
- String url = baseUrl+"ajax/SampleAjaxPlugin";
- String html= "Press Me
\n"+
+ String html= "Press Me
\n"+
"";
return html;
}
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ @Override
+ public String getServletMapping() {
+ return SERVLET_MAPPING;
+ }
+
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response, String actionName, List params) throws ServletException, IOException {
try {
Thread.sleep(5000); // Wait 5 seconds
} catch (Exception e) {}
- resp.getWriter().print("You called by get!");
- }
+ response.getWriter().print("You called!");
+ }
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- try {
- Thread.sleep(5000); // Wait 5 seconds
- } catch (Exception e) {}
- resp.getWriter().print("You called by post!");
- }
+
+
}
Index: jspwiki-war/src/main/java/org/apache/wiki/Release.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/Release.java (revision 1655294)
+++ jspwiki-war/src/main/java/org/apache/wiki/Release.java (working copy)
@@ -72,7 +72,7 @@
*
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "11";
+ public static final String BUILD = "12";
/**
* This is the generic version string you should use when printing out the version. It is of
Index: jspwiki-war/src/main/java/org/apache/wiki/rpc/json/JSONRPCManager.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/rpc/json/JSONRPCManager.java (revision 1655294)
+++ jspwiki-war/src/main/java/org/apache/wiki/rpc/json/JSONRPCManager.java (working copy)
@@ -27,15 +27,15 @@
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
-
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiSession;
+import org.apache.wiki.ajax.WikiAjaxDispatcherServlet;
import org.apache.wiki.auth.WikiSecurityException;
import org.apache.wiki.auth.permissions.PagePermission;
import org.apache.wiki.rpc.RPCCallable;
import org.apache.wiki.rpc.RPCManager;
-import org.apache.wiki.ui.TemplateManager;
+
import com.metaparadigm.jsonrpc.InvocationCallback;
import com.metaparadigm.jsonrpc.JSONRPCBridge;
@@ -51,10 +51,13 @@
* Due to some limitations of the JSON-RPC library, we do not use the
* Global bridge object.
*
+ * Deprecated: Use {@link WikiAjaxDispatcherServlet}
+ *
* @see org.apache.wiki.rpc.RPCCallable
* @since 2.5.4
*/
// FIXME: Must be mootool-ified.
+@Deprecated
public final class JSONRPCManager extends RPCManager {
private static final String JSONRPCBRIDGE = "JSONRPCBridge";
private static HashMap c_globalObjects = new HashMap();
Index: jspwiki-war/src/main/java/org/apache/wiki/rpc/RPCCallable.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/rpc/RPCCallable.java (revision 1655294)
+++ jspwiki-war/src/main/java/org/apache/wiki/rpc/RPCCallable.java (working copy)
@@ -18,11 +18,16 @@
*/
package org.apache.wiki.rpc;
+import org.apache.wiki.ajax.WikiAjaxDispatcherServlet;
+
/**
* Defines an interface for anything which can be called using the RPC methods.
*
+ * Deprecated. Use {@link WikiAjaxDispatcherServlet}
+ *
* @since 2.5.4
*/
+@Deprecated
public interface RPCCallable
{
Index: jspwiki-war/src/main/java/org/apache/wiki/rpc/RPCManager.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/rpc/RPCManager.java (revision 1655294)
+++ jspwiki-war/src/main/java/org/apache/wiki/rpc/RPCManager.java (working copy)
@@ -18,11 +18,16 @@
*/
package org.apache.wiki.rpc;
+import org.apache.wiki.ajax.WikiAjaxDispatcherServlet;
+
/**
* A base class for managing RPC calls.
*
* @since 2.5.4
+ *
+ * Deprecated. Use {@link WikiAjaxDispatcherServlet}
*/
+@Deprecated
public class RPCManager
{
/**
Index: jspwiki-war/src/main/java/org/apache/wiki/search/SearchManager.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/search/SearchManager.java (revision 1655294)
+++ jspwiki-war/src/main/java/org/apache/wiki/search/SearchManager.java (working copy)
@@ -24,14 +24,23 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.log4j.Logger;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.WikiPage;
+import org.apache.wiki.ajax.AjaxUtil;
+import org.apache.wiki.ajax.WikiAjaxDispatcherServlet;
+import org.apache.wiki.ajax.WikiAjaxServlet;
import org.apache.wiki.api.exceptions.FilterException;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
@@ -42,12 +51,9 @@
import org.apache.wiki.event.WikiPageEvent;
import org.apache.wiki.modules.InternalModule;
import org.apache.wiki.parser.MarkupParser;
-import org.apache.wiki.rpc.RPCCallable;
-import org.apache.wiki.rpc.json.JSONRPCManager;
import org.apache.wiki.util.ClassUtil;
import org.apache.wiki.util.TextUtil;
-
/**
* Manages searching the Wiki.
*
@@ -89,14 +95,61 @@
WikiEventUtils.addWikiEventListener(m_engine.getPageManager(),
WikiPageEvent.PAGE_DELETE_REQUEST, this);
- JSONRPCManager.registerGlobalObject( JSON_SEARCH, new JSONSearch() );
+ //TODO: Replace with custom annotations. See JSPWIKI-566
+ WikiAjaxDispatcherServlet.registerServlet( JSON_SEARCH, new JSONSearch() );
}
/**
* Provides a JSON RPC API to the JSPWiki Search Engine.
*/
- public class JSONSearch implements RPCCallable
+ public class JSONSearch implements WikiAjaxServlet
{
+ public static final String AJAX_ACTION_SUGGESTIONS = "suggestions";
+ public static final String AJAX_ACTION_PAGES = "pages";
+ public static final int DEFAULT_MAX_RESULTS = 20;
+ public int maxResults = DEFAULT_MAX_RESULTS;
+
+ @Override
+ public String getServletMapping() {
+ return JSON_SEARCH;
+ }
+
+ @Override
+ public void service(HttpServletRequest req, HttpServletResponse resp, String actionName, List params)
+ throws ServletException, IOException {
+ String result = "";
+ if (StringUtils.isNotBlank(actionName)) {
+ if (params.size()<1) {
+ return;
+ }
+ String itemId = params.get(1);
+ log.debug("itemId="+itemId);
+ if (params.size()>1) {
+ String maxResultsParam = params.get(2);
+ log.debug("maxResultsParam="+maxResultsParam);
+ if (StringUtils.isNotBlank(maxResultsParam) && StringUtils.isNumeric(maxResultsParam)) {
+ maxResults = Integer.parseInt(maxResultsParam);
+ }
+ }
+
+ if (actionName.equals(AJAX_ACTION_SUGGESTIONS)) {
+ List callResults = new ArrayList();
+ log.debug("Calling getSuggestions() START");
+ callResults = getSuggestions(itemId, maxResults);
+ log.debug("Calling getSuggestions() DONE. "+callResults.size());
+ result = AjaxUtil.toJson(callResults);
+ } else if (actionName.equals(AJAX_ACTION_PAGES)) {
+ List