Index: jspwiki-war/pom.xml =================================================================== --- jspwiki-war/pom.xml (revision 1653248) +++ jspwiki-war/pom.xml (working copy) @@ -99,6 +99,11 @@ + com.google.code.gson + gson + + + org.jvnet.hudson org.suigeneris.jrcs.diff Index: jspwiki-war/src/main/java/org/apache/wiki/ajax/AjaxUtil.java =================================================================== --- jspwiki-war/src/main/java/org/apache/wiki/ajax/AjaxUtil.java (revision 0) +++ jspwiki-war/src/main/java/org/apache/wiki/ajax/AjaxUtil.java (working copy) @@ -0,0 +1,52 @@ +package org.apache.wiki.ajax; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; + +import org.apache.commons.lang.StringUtils; + +import com.google.gson.Gson; + +public class AjaxUtil extends HttpServlet { + private static final long serialVersionUID = 3170439306358345408L; + private static Gson gson = new Gson(); + + public static String toJson(Object input) { + String result = ""; + if (input != null) { + result = gson.toJson(input); + } + return result; + } + + public static String getNextPathPart(String path, String lastPart) throws ServletException { + String result = null; + if (StringUtils.isBlank(path)) { + return result; + } + if (!lastPart.endsWith("/")) { + lastPart += "/"; + } + int index = path.indexOf(lastPart); + if (index<0) { + throw new ServletException("Invalid path provided " + path + " does not contain '" + lastPart + "'"); + } + path = path.substring(index+lastPart.length()); + index = path.indexOf("/"); + if (index == -1) { + index = path.indexOf("#"); + if (index == -1) { + index = path.indexOf("?"); + } + } + if (index == -1) { + result = path; + } + else { + result = path.substring(0,index); + } + + return result; + } + +} Property changes on: jspwiki-war/src/main/java/org/apache/wiki/ajax/AjaxUtil.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jspwiki-war/src/main/java/org/apache/wiki/ajax/AjaxUtil.java =================================================================== --- jspwiki-war/src/main/java/org/apache/wiki/ajax/AjaxUtil.java (revision 0) +++ jspwiki-war/src/main/java/org/apache/wiki/ajax/AjaxUtil.java (working copy) @@ -0,0 +1,52 @@ +package org.apache.wiki.ajax; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; + +import org.apache.commons.lang.StringUtils; + +import com.google.gson.Gson; + +public class AjaxUtil extends HttpServlet { + private static final long serialVersionUID = 3170439306358345408L; + private static Gson gson = new Gson(); + + public static String toJson(Object input) { + String result = ""; + if (input != null) { + result = gson.toJson(input); + } + return result; + } + + public static String getNextPathPart(String path, String lastPart) throws ServletException { + String result = null; + if (StringUtils.isBlank(path)) { + return result; + } + if (!lastPart.endsWith("/")) { + lastPart += "/"; + } + int index = path.indexOf(lastPart); + if (index<0) { + throw new ServletException("Invalid path provided " + path + " does not contain '" + lastPart + "'"); + } + path = path.substring(index+lastPart.length()); + index = path.indexOf("/"); + if (index == -1) { + index = path.indexOf("#"); + if (index == -1) { + index = path.indexOf("?"); + } + } + if (index == -1) { + result = path; + } + else { + result = path.substring(0,index); + } + + return result; + } + +} Property changes on: jspwiki-war/src/main/java/org/apache/wiki/ajax/AjaxUtil.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jspwiki-war/src/main/java/org/apache/wiki/auth/user/DefaultUserProfile.java =================================================================== --- jspwiki-war/src/main/java/org/apache/wiki/auth/user/DefaultUserProfile.java (revision 1653248) +++ jspwiki-war/src/main/java/org/apache/wiki/auth/user/DefaultUserProfile.java (working copy) @@ -39,25 +39,25 @@ private static final String WHITESPACE = "\\s"; - private Map m_attributes = new HashMap(); + private Map attributes = new HashMap(); - private Date m_created = null; + private Date created = null; - private String m_email = null; + private String email = null; - private String m_fullname = null; + private String fullname = null; - private Date m_lockExpiry = null; + private Date lockExpiry = null; - private String m_loginName = null; + private String loginName = null; - private Date m_modified = null; + private Date modified = null; - private String m_password = null; + private String password = null; - private String m_uid = null; + private String uid = null; - private String m_wikiname = null; + private String wikiname = null; /** * Private constructor to prevent direct instantiation. @@ -86,9 +86,9 @@ if ( ( o != null ) && ( o instanceof UserProfile ) ) { DefaultUserProfile u = (DefaultUserProfile) o; - return same( m_fullname, u.m_fullname ) && same( m_password, u.m_password ) - && same( m_loginName, u.m_loginName ) && same(StringUtils.lowerCase( m_email ), StringUtils.lowerCase( u.m_email ) ) && same( m_wikiname, - u.m_wikiname ); + return same( fullname, u.fullname ) && same( password, u.password ) + && same( loginName, u.loginName ) && same(StringUtils.lowerCase( email ), StringUtils.lowerCase( u.email ) ) && same( wikiname, + u.wikiname ); } return false; @@ -96,11 +96,11 @@ public int hashCode() { - return (m_fullname != null ? m_fullname.hashCode() : 0) ^ - (m_password != null ? m_password.hashCode() : 0) ^ - (m_loginName != null ? m_loginName.hashCode() : 0) ^ - (m_wikiname != null ? m_wikiname.hashCode() : 0) ^ - (m_email != null ? StringUtils.lowerCase( m_email ).hashCode() : 0); + return (fullname != null ? fullname.hashCode() : 0) ^ + (password != null ? password.hashCode() : 0) ^ + (loginName != null ? loginName.hashCode() : 0) ^ + (wikiname != null ? wikiname.hashCode() : 0) ^ + (email != null ? StringUtils.lowerCase( email ).hashCode() : 0); } /** @@ -110,7 +110,7 @@ */ public Date getCreated() { - return m_created; + return created; } /** @@ -119,7 +119,7 @@ */ public String getEmail() { - return m_email; + return email; } /** @@ -128,7 +128,7 @@ */ public String getFullname() { - return m_fullname; + return fullname; } /** @@ -138,7 +138,7 @@ */ public Date getLastModified() { - return m_modified; + return modified; } /** @@ -147,7 +147,7 @@ */ public String getLoginName() { - return m_loginName; + return loginName; } /** @@ -161,7 +161,7 @@ */ public String getPassword() { - return m_password; + return password; } /** @@ -170,7 +170,7 @@ */ public String getWikiName() { - return m_wikiname; + return wikiname; } /** @@ -182,7 +182,7 @@ */ public boolean isNew() { - return m_modified == null; + return modified == null; } /** @@ -191,7 +191,7 @@ */ public void setCreated(Date date) { - m_created = date; + created = date; } /** @@ -200,7 +200,7 @@ */ public void setEmail( String email ) { - m_email = email; + this.email = email; } /** @@ -209,12 +209,12 @@ */ public void setFullname( String arg ) { - m_fullname = arg; + fullname = arg; // Compute wiki name - if ( m_fullname != null ) + if ( fullname != null ) { - m_wikiname = m_fullname.replaceAll(WHITESPACE, EMPTY_STRING); + wikiname = fullname.replaceAll(WHITESPACE, EMPTY_STRING); } } @@ -225,7 +225,7 @@ */ public void setLastModified( Date date ) { - m_modified = date; + modified = date; } /** @@ -238,7 +238,7 @@ */ public void setLoginName( String name ) { - m_loginName = name; + loginName = name; } /** @@ -253,7 +253,7 @@ */ public void setPassword( String arg ) { - m_password = arg; + password = arg; } /** @@ -304,7 +304,7 @@ */ public Map 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,18 +31,22 @@ 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; +import org.apache.wiki.WikiAjaxDispatcherServlet; 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.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/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.WikiAjaxDispatcherServlet; 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.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> callResults = new ArrayList>(); + System.out.println("Calling findPages() START"); + callResults = findPages(itemId, maxResults); + System.out.println("Calling findPages() DONE. "+callResults.size()); + result = AjaxUtil.toJson(callResults); + } + } + System.out.println("result="+result); + resp.getWriter().write(result); + } + /** * Provides a list of suggestions to use for a page name. * Currently the algorithm just looks into the value parameter, @@ -106,7 +146,7 @@ * @param maxLength maximum number of suggestions * @return the suggestions */ - public List getSuggestions( String wikiName, int maxLength ) + public List getSuggestions( String wikiName, int maxLength ) { StopWatch sw = new StopWatch(); sw.start(); @@ -155,12 +195,12 @@ * @param maxLength How many hits to return * @return the pages found */ - public List findPages( String searchString, int maxLength ) + public List> findPages( String searchString, int maxLength ) { StopWatch sw = new StopWatch(); sw.start(); - List list = new ArrayList(maxLength); + List> list = new ArrayList>(maxLength); if( searchString.length() > 0 ) { @@ -168,11 +208,12 @@ { Collection c; - if( m_searchProvider instanceof LuceneSearchProvider ) + if( m_searchProvider instanceof LuceneSearchProvider ) { c = ((LuceneSearchProvider)m_searchProvider).findPages( searchString, 0 ); - else + } else { c = m_searchProvider.findPages( searchString ); - + } + int count = 0; for( Iterator i = c.iterator(); i.hasNext() && count < maxLength; count++ ) { @@ -195,6 +236,7 @@ } } + /** * This particular method starts off indexing and all sorts of various activities, * so you need to run this last, after things are done. Index: jspwiki-war/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java =================================================================== --- jspwiki-war/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java (revision 1653248) +++ jspwiki-war/src/main/java/org/apache/wiki/ui/progress/ProgressManager.java (working copy) @@ -18,12 +18,19 @@ */ package org.apache.wiki.ui.progress; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.UUID; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.apache.log4j.Logger; - +import org.apache.wiki.WikiAjaxDispatcherServlet; +import org.apache.wiki.ajax.AjaxUtil; import org.apache.wiki.rpc.RPCCallable; import org.apache.wiki.rpc.json.JSONRPCManager; @@ -52,7 +59,8 @@ */ public ProgressManager() { - JSONRPCManager.registerGlobalObject( JSON_PROGRESSTRACKER, new JSONTracker() ); +// JSONRPCManager.registerGlobalObject( JSON_PROGRESSTRACKER, new JSONTracker() ); + WikiAjaxDispatcherServlet.register( JSON_PROGRESSTRACKER, new JSONTracker() ); } /** @@ -117,7 +125,7 @@ * Progress of zero (0) means that the progress has just started, and a progress of * 100 means that it is complete. */ - public class JSONTracker implements RPCCallable + public class JSONTracker extends HttpServlet implements RPCCallable { /** * Returns upload progress in percents so far. @@ -129,5 +137,25 @@ { return ProgressManager.this.getProgress( progressId ); } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException + { + System.out.println("ProgressManager.doGet() START"); + String progressId = AjaxUtil.getNextPathPart(req.getRequestURI(), JSON_PROGRESSTRACKER); + System.out.println("progressId="+progressId); + String progressString = ""; + try { + int progress = getProgress(progressId); + progressString = Integer.toString(progress); + } catch (IllegalArgumentException e) { + // ignore + System.out.println("Error occured"); + } + System.out.println("progressString="+progressString); + resp.getWriter().write(progressString); + System.out.println("ProgressManager.doGet() DONE"); + } } } Index: jspwiki-war/src/main/java/org/apache/wiki/WikiAjaxDispatcherServlet.java =================================================================== --- jspwiki-war/src/main/java/org/apache/wiki/WikiAjaxDispatcherServlet.java (revision 1653248) +++ jspwiki-war/src/main/java/org/apache/wiki/WikiAjaxDispatcherServlet.java (working copy) @@ -30,6 +30,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import org.apache.wiki.ajax.AjaxUtil; /** * This provides a simple ajax servlet for handling /ajax/ requests. @@ -55,10 +56,18 @@ log.info("WikiAjaxDispatcherServlet initialized."); } + /** + * Register a servlet using the class simple name as the alias + */ public static void register(HttpServlet servlet) { - log.info("WikiAjaxDispatcherServlet registering "+servlet.getClass().getSimpleName()+"="+servlet); - ajaxServlets.put(servlet.getClass().getSimpleName(),servlet); + register(servlet.getClass().getSimpleName(),servlet); } + + public static void register(String alias, HttpServlet servlet) { + log.info("WikiAjaxDispatcherServlet registering "+alias+"="+servlet); + System.out.println("WikiAjaxDispatcherServlet registering "+alias+"="+servlet); + ajaxServlets.put(alias,servlet); + } /** * Calls {@link this.performAction} @@ -107,32 +116,9 @@ * @throws ServletException if the path is invalid */ public String getServletName(String path) throws ServletException { - String result = null; - if (StringUtils.isBlank(path)) { - return result; - } - int index = path.indexOf(PATH_AJAX); - if (index<0) { - throw new ServletException("Invalid path provided " + path + " does not contain '" + PATH_AJAX + "'"); - } - path = path.substring(index+6); - index = path.indexOf("/"); - if (index == -1) { - index = path.indexOf("#"); - if (index == -1) { - index = path.indexOf("?"); - } - } - if (index == -1) { - result = path; - } - else { - result = path.substring(0,index); - } - - return result; + return AjaxUtil.getNextPathPart(path, PATH_AJAX); } - + /** * Find the servlet as registered in {@link WikiAjaxDispatcherServlet.register}. * Index: jspwiki-war/src/main/scripts/jspwiki-common.js =================================================================== --- jspwiki-war/src/main/scripts/jspwiki-common.js (revision 1653248) +++ jspwiki-war/src/main/scripts/jspwiki-common.js (working copy) @@ -250,7 +250,13 @@ /* * AJAX call starts with this function */ -function makeRequest(method,url,responseId,loading) { +function ajaxHtmlCall(url,responseId,method,loading) { + if (!method) { + method = "GET"; + } + if (!loading) { + loading = "Loading..."; + } var xmlHttpRequest = getXMLHttpRequest(); xmlHttpRequest.onreadystatechange = getReadyStateHandler(xmlHttpRequest,responseId,loading); xmlHttpRequest.open(method, url, true); @@ -258,21 +264,46 @@ xmlHttpRequest.send(null); } +function ajaxJsonCall(url,callback,method) { + if (!method) { + method = "GET"; + } + var xmlHttpRequest = getXMLHttpRequest(); + xmlHttpRequest.onreadystatechange = getReadyStateHandler(xmlHttpRequest,null,null,callback); + xmlHttpRequest.open(method, url, true); + xmlHttpRequest.setRequestHeader("Content-Type", "application/json"); + xmlHttpRequest.send(null); +} + /* * Returns a function that waits for the state change in XMLHttpRequest */ -function getReadyStateHandler(xmlHttpRequest,responseId,loading) { +function getReadyStateHandler(xmlHttpRequest,responseId,loading,callback) { // an anonymous function returned // it listens to the XMLHttpRequest instance return function() { if (xmlHttpRequest.readyState >=1 && xmlHttpRequest.readyState <4) { - document.getElementById(responseId).innerHTML = loading; + if (responseId && document.getElementById(responseId) != null) { + document.getElementById(responseId).innerHTML = loading; + } } if (xmlHttpRequest.readyState == 4) { if (xmlHttpRequest.status == 200) { - document.getElementById(responseId).innerHTML = xmlHttpRequest.responseText; + if (responseId && document.getElementById(responseId) != null) { + document.getElementById(responseId).innerHTML = xmlHttpRequest.responseText; + } else { + // Javascript function JSON.parse to parse JSON data + var jsonResponse = JSON.parse(xmlHttpRequest.responseText); + callback(jsonResponse); + } } else { - document.getElementById(responseId).innerHTML("HTTP error " + xmlHttpRequest.status + ": " + xmlHttpRequest.statusText); + var errorMsg = "HTTP error " + xmlHttpRequest.status + ": " + xmlHttpRequest.statusText; + if (responseId && document.getElementById(responseId) != null) { + document.getElementById(responseId).innerHTML(errorMsg); + } else { + console.log(errorMsg); + callback(errorMsg); + } } } }; @@ -439,7 +470,7 @@ submitUpload: function(form, progress){ $('progressbar').setStyle('visibility','visible'); this.progressbar = - Wiki.jsonrpc.periodical(1000, this, ["progressTracker.getProgress",[progress],function(result){ + ajaxJsonCall.periodical(1000, this, ["ajax/progressTracker/"+progress,function(result){ result = result.stripScripts(); //xss vulnerability if(!result.code) $('progressbar').getFirst().setStyle('width',result+'%').setHTML(result+'%'); }]); @@ -1005,20 +1036,20 @@ $('searchTarget').setHTML('('+qv+') :'); $('searchSpin').show(); - Wiki.jsonrpc('search.findPages', [qv,20], function(result){ - $('searchSpin').hide(); - if(!result.list) return; - var frag = new Element('ul'); + ajaxJsonCall("ajax/search/pages/"+qv, function(result) { + $('searchSpin').hide(); + if(!result.list) return; + var frag = new Element('ul'); - result.list.each(function(el){ - new Element('li').adopt( - new Element('a',{'href':Wiki.getUrl(el.map.page) }).setHTML(el.map.page), - new Element('span',{'class':'small'}).setHTML(" ("+el.map.score+")") - ).inject(frag); - }); - $('searchOutput').empty().adopt(frag); - Wiki.locatemenu( $('query'), $('searchboxMenu') ); - }); + result.list.each(function(el){ + new Element('li').adopt( + new Element('a',{'href':Wiki.getUrl(el.map.page) }).setHTML(el.map.page), + new Element('span',{'class':'small'}).setHTML(" ("+el.map.score+")") + ).inject(frag); + }); + $('searchOutput').empty().adopt(frag); + Wiki.locatemenu( $('query'), $('searchboxMenu') ); + }); } , /* navigate to url, after smart pagename handling */ Index: jspwiki-war/src/main/scripts/jspwiki-edit.js =================================================================== --- jspwiki-war/src/main/scripts/jspwiki-edit.js (revision 1653248) +++ jspwiki-war/src/main/scripts/jspwiki-edit.js (working copy) @@ -456,7 +456,7 @@ if(end!=-1) sel.end = sel.start+end; } - Wiki.jsonrpc('search.getSuggestions', [searchword,30], function(result,exception){ + Wiki.jsonrpc('/ajax/search/suggestions/'+searchWord, [searchword,30], function(result,exception){ if(exception) { alert(exception.message); } else if(!result.list || (result.list.length == 0)) { Index: jspwiki-war/src/main/scripts/wiki-edit/Wiki.Snips.js =================================================================== --- jspwiki-war/src/main/scripts/wiki-edit/Wiki.Snips.js (revision 1653248) +++ jspwiki-war/src/main/scripts/wiki-edit/Wiki.Snips.js (working copy) @@ -371,17 +371,14 @@ if( !key || (key.trim()=='')) key = Wiki.PageName + '/'; //console.log('json lookup for '+key); - Wiki.jsonrpc('search.getSuggestions', [key,30], function(result,exception){ - - if( result.list && result.list[0] /*length!=0*/ ){ - dialog.setBody( result.list ); - } else { - dialog.hide(); - } - - }); + ajaxJsonCall("ajax/search/suggestions/"+key,"", function(result,exception) { + if( result.list && result.list[0] /*length!=0*/ ){ + dialog.setBody( result.list ); + } else { + dialog.hide(); + } + }); } - }] Index: jspwiki-war/src/main/scripts/wiki/Wiki.js =================================================================== --- jspwiki-war/src/main/scripts/wiki/Wiki.js (revision 1653248) +++ jspwiki-war/src/main/scripts/wiki/Wiki.js (working copy) @@ -166,7 +166,7 @@ //activate Quick Navigation functionality new wiki.Findpages(element,{ rpc: function(value, callback){ - wiki.jsonrpc('search.findPages', [value,16], callback); + wiki.jsonrpc('/ajax/search/pages/'+value, [value,16], callback); }, toUrl: wiki.toUrl.bind(wiki) }); @@ -189,7 +189,7 @@ .add('#files', Form.File, { max:1, //CHECK: jspwiki v.2.10.x seems to only support 1 upload-file at a time ?? rpc: function(progressid, callback){ - wiki.jsonrpc('progressTracker.getProgress', [progressid], callback); + ajaxJsonCall('ajax/progressTracker/'+progressId, callback); }, }); Index: jspwiki-war/src/main/webapp/templates/default/admin/UserManagement.jsp =================================================================== --- jspwiki-war/src/main/webapp/templates/default/admin/UserManagement.jsp (revision 1653248) +++ jspwiki-war/src/main/webapp/templates/default/admin/UserManagement.jsp (working copy) @@ -41,13 +41,13 @@ if( userid == '--New--' ) return; - Wiki.jsonrpc("users.getUserInfo", [userid], function(userprofile){ - $('loginname').value = userprofile.loginName; - $('loginid').value = userprofile.loginName; - $('fullname').value = userprofile.fullname; - $('email').value = userprofile.email; - $('lastmodified').setHTML(constructdate(userprofile.lastModified)); - $('creationdate').setHTML(constructdate(userprofile.created)); + ajaxJsonCall("ajax/users/"+userid, function(userprofile) { + $('loginname').value = userprofile.loginName; + $('loginid').value = userprofile.loginName; + $('fullname').value = userprofile.fullname; + $('email').value = userprofile.email; + $('lastmodified').setHTML(constructdate(userprofile.lastModified)); + $('creationdate').setHTML(constructdate(userprofile.created)); }); } Index: jspwiki-war/src/main/webapp/templates/haddock/admin/UserManagement.jsp =================================================================== --- jspwiki-war/src/main/webapp/templates/haddock/admin/UserManagement.jsp (revision 1653248) +++ jspwiki-war/src/main/webapp/templates/haddock/admin/UserManagement.jsp (working copy) @@ -41,13 +41,13 @@ if( userid == '--New--' ) return; - Wiki.jsonrpc("users.getUserInfo", [userid], function(userprofile){ - $('loginname').value = userprofile.loginName; - $('loginid').value = userprofile.loginName; - $('fullname').value = userprofile.fullname; - $('email').value = userprofile.email; - $('lastmodified').setHTML(constructdate(userprofile.lastModified)); - $('creationdate').setHTML(constructdate(userprofile.created)); + ajaxJsonCall("ajax/UserInfoServlet/"+userid, function(userprofile) { + $('loginname').value = userprofile.loginName; + $('loginid').value = userprofile.loginName; + $('fullname').value = userprofile.fullname; + $('email').value = userprofile.email; + $('lastmodified').setHTML(constructdate(userprofile.lastModified)); + $('creationdate').setHTML(constructdate(userprofile.created)); }); } Index: pom.xml =================================================================== --- pom.xml (revision 1653248) +++ pom.xml (working copy) @@ -71,6 +71,12 @@ json-rpc 1.0 + + + com.google.code.gson + gson + 2.3.1 + commons-fileupload