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 1653248)
+++ 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,10 @@
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@@ -37,6 +41,8 @@
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.api.engine.FilterManager;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.WikiException;
@@ -54,7 +60,6 @@
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 +102,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 */
@@ -124,8 +131,9 @@
// Attach the PageManager as a listener
// TODO: it would be better if we did this in PageManager directly
addWikiEventListener( engine.getPageManager() );
-
- JSONRPCManager.registerGlobalObject( "users", new JSONUserModule(this), new AllPermission(null) );
+
+ WikiAjaxDispatcherServlet.registerServlet( JSON_USERS, new JSONUserModule(this), new AllPermission(null));
+// JSONRPCManager.registerGlobalObject( JSON_USERS, new JSONUserModule(this), new AllPermission(null) );
}
/**
@@ -843,7 +851,7 @@
WikiEventManager.fireEvent(this,new WikiSecurityEvent(session,type,profile));
}
}
-
+
/**
* Implements the JSON API for usermanager.
*
@@ -851,9 +859,10 @@
* 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 extends HttpServlet implements RPCCallable
{
- private volatile UserManager m_manager;
+ private static final long serialVersionUID = 6154591769798706915L;
+ private volatile UserManager m_manager;
/**
* Create a new JSONUserModule.
@@ -864,6 +873,18 @@
m_manager = mgr;
}
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ try {
+ String uid = AjaxUtil.getNextPathPart(req.getRequestURI(),JSON_USERS);
+ log.debug("uid="+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 1653248)
+++ 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,9 @@
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.api.engine.PluginManager;
import org.apache.wiki.api.exceptions.PluginException;
import org.apache.wiki.api.plugin.InitializablePlugin;
@@ -546,7 +547,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 +581,7 @@
private String m_className;
private String m_alias;
+ private String m_ajaxAlias;
private Class> m_clazz;
private boolean m_initialized = false;
@@ -611,7 +613,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;
@@ -622,7 +624,11 @@
( ( InitializablePlugin )p ).initialize( engine );
}
if( p instanceof HttpServlet ) {
- WikiAjaxDispatcherServlet.register( (HttpServlet) p );
+ WikiAjaxDispatcherServlet.registerServlet( (HttpServlet) p );
+ String ajaxAlias = info.getAjaxAlias();
+ if (StringUtils.isNotBlank(ajaxAlias)) {
+ WikiAjaxDispatcherServlet.registerServlet( info.getAjaxAlias(), (HttpServlet) p );
+ }
}
} catch( Exception e ) {
log.info( "Cannot initialize plugin " + m_className, e );
@@ -637,6 +643,7 @@
protected void initializeFromXML( Element el ) {
super.initializeFromXML( el );
m_alias = el.getChildText( "alias" );
+ m_ajaxAlias = el.getChildText( "ajaxAlias" );
}
/**
@@ -674,6 +681,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 1653248)
+++ jspwiki-war/src/main/java/org/apache/wiki/plugin/SampleAjaxPlugin.java (working copy)
@@ -29,6 +29,7 @@
import org.apache.wiki.WikiContext;
import org.apache.wiki.api.exceptions.PluginException;
import org.apache.wiki.api.plugin.WikiPlugin;
+import org.apache.wiki.util.TextUtil;
/**
* @author David VIttor
@@ -41,9 +42,8 @@
@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 url = "/SampleAjaxPlugin";
+ String html= "Press Me
\n"+
"";
return html;
}
Index: jspwiki-war/src/main/java/org/apache/wiki/preferences/Preferences.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/preferences/Preferences.java (revision 1653248)
+++ jspwiki-war/src/main/java/org/apache/wiki/preferences/Preferences.java (working copy)
@@ -113,6 +113,8 @@
prefs.put("SectionEditing", TextUtil.getStringProperty( props, "jspwiki.defaultprefs.template.sectionediting",
"" ) );
+ prefs.put("ajaxPrefix", TextUtil.getStringProperty( props, "jspwiki.ajax.url.prefix", "ajax") );
+
// FIXME: "editor" property does not get registered, may be related with http://bugs.jspwiki.org/show_bug.cgi?id=117
// disabling it until knowing why it's happening
// FIXME: editormanager reads jspwiki.editor -- which of both properties should continue
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 1653248)
+++ 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 1653248)
+++ 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/search/SearchManager.java
===================================================================
--- jspwiki-war/src/main/java/org/apache/wiki/search/SearchManager.java (revision 1653248)
+++ 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.HttpServlet;
+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.api.exceptions.FilterException;
import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
import org.apache.wiki.api.exceptions.ProviderException;
@@ -43,11 +52,9 @@
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 +96,57 @@
WikiEventUtils.addWikiEventListener(m_engine.getPageManager(),
WikiPageEvent.PAGE_DELETE_REQUEST, this);
- JSONRPCManager.registerGlobalObject( JSON_SEARCH, new JSONSearch() );
+// JSONRPCManager.registerGlobalObject( JSON_SEARCH, new JSONSearch() );
+ WikiAjaxDispatcherServlet.registerServlet( JSON_SEARCH, new JSONSearch() );
}
/**
* Provides a JSON RPC API to the JSPWiki Search Engine.
*/
- public class JSONSearch implements RPCCallable
+ public class JSONSearch extends HttpServlet implements RPCCallable
{
+ private static final long serialVersionUID = -7247458370410462412L;
+ 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
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ String action = AjaxUtil.getNextPathPart(req.getRequestURI(), JSON_SEARCH);
+ log.debug("action="+action);
+ String result = "";
+ if (StringUtils.isNotBlank(action)) {
+ String itemId = AjaxUtil.getNextPathPart(req.getRequestURI(), action);
+ log.debug("itemId="+itemId);
+
+ if (StringUtils.isNotBlank(itemId)) {
+ String maxResultsParam = AjaxUtil.getNextPathPart(req.getRequestURI(), itemId);
+ log.debug("maxResultsParam="+maxResultsParam);
+ if (StringUtils.isNotBlank(maxResultsParam) && StringUtils.isNumeric(maxResultsParam)) {
+ maxResults = Integer.parseInt(maxResultsParam);
+ }
+ }
+
+ if (action.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 (action.equals(AJAX_ACTION_PAGES)) {
+ List