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,11 +41,12 @@
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;
import org.apache.wiki.api.filters.PageFilter;
-import org.apache.wiki.auth.permissions.AllPermission;
import org.apache.wiki.auth.permissions.WikiPermission;
import org.apache.wiki.auth.user.AbstractUserDatabase;
import org.apache.wiki.auth.user.DuplicateUserException;
@@ -54,7 +59,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 +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 */
@@ -124,8 +130,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.register( JSON_USERS, new JSONUserModule(this));
+// JSONRPCManager.registerGlobalObject( 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,7 +858,7 @@
* 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;
@@ -864,6 +871,18 @@
m_manager = mgr;
}
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ try {
+ String uid = AjaxUtil.getNextPathPart(req.getRequestURI(),JSON_USERS);
+ System.out.println("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;
@@ -623,6 +625,10 @@
}
if( p instanceof HttpServlet ) {
WikiAjaxDispatcherServlet.register( (HttpServlet) p );
+ String ajaxAlias = info.getAjaxAlias();
+ if (StringUtils.isNotBlank(ajaxAlias)) {
+ WikiAjaxDispatcherServlet.register( 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)
@@ -43,7 +43,7 @@
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;
}
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,47 @@
WikiEventUtils.addWikiEventListener(m_engine.getPageManager(),
WikiPageEvent.PAGE_DELETE_REQUEST, this);
- JSONRPCManager.registerGlobalObject( JSON_SEARCH, new JSONSearch() );
+// JSONRPCManager.registerGlobalObject( JSON_SEARCH, new JSONSearch() );
+ WikiAjaxDispatcherServlet.register( 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
{
+ 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);
+ System.out.println("action="+action);
+ String result = "";
+ if (StringUtils.isNotBlank(action)) {
+ String itemId = AjaxUtil.getNextPathPart(req.getRequestURI(), action);
+ System.out.println("itemId="+itemId);
+ if (action.equals(AJAX_ACTION_SUGGESTIONS)) {
+ List callResults = new ArrayList();
+ System.out.println("Calling getSuggestions() START");
+ callResults = getSuggestions(itemId, maxResults);
+ System.out.println("Calling getSuggestions() DONE. "+callResults.size());
+ result = AjaxUtil.toJson(callResults);
+ } else if (action.equals(AJAX_ACTION_PAGES)) {
+ List