You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2010/02/20 19:03:56 UTC
svn commit: r912169 - in /incubator/jspwiki/trunk/src/java/org/apache/wiki:
action/EditDialogActionBean.java action/SearchActionBean.java
search/SearchManager.java
Author: ajaquith
Date: Sat Feb 20 18:03:55 2010
New Revision: 912169
URL: http://svn.apache.org/viewvc?rev=912169&view=rev
Log:
[JSPWIKI-510] Restored AJAX quicksearch. It now respects page ACLs, too. Moved the AJAX "suggestions" method to (new) EditDialogActionBean, which is a placeholder for now. Removed JSON global bridge from SearchManager.
Added:
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditDialogActionBean.java
Modified:
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java
Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditDialogActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditDialogActionBean.java?rev=912169&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditDialogActionBean.java (added)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/EditDialogActionBean.java Sat Feb 20 18:03:55 2010
@@ -0,0 +1,85 @@
+package org.apache.wiki.action;
+
+import java.util.*;
+
+import net.sourceforge.stripes.action.DefaultHandler;
+import net.sourceforge.stripes.action.HandlesEvent;
+import net.sourceforge.stripes.action.Resolution;
+
+import org.apache.commons.lang.time.StopWatch;
+import org.apache.wiki.log.Logger;
+import org.apache.wiki.log.LoggerFactory;
+import org.apache.wiki.parser.MarkupParser;
+import org.apache.wiki.providers.ProviderException;
+import org.apache.wiki.ui.stripes.EventResolution;
+
+public class EditDialogActionBean extends AbstractActionBean
+{
+ private static final Logger log = LoggerFactory.getLogger( EditDialogActionBean.class );
+
+ /**
+ * Provides a list of suggestions to use for a page name links.
+ * Currently the algorithm just looks into the value parameter,
+ * and returns all page names from that.
+ *
+ * @param wikiName the page name
+ * @param maxLength maximum number of suggestions
+ * @return an EventResolution containing the suggestions as a JavaScript array of Strings
+ */
+ @DefaultHandler
+ @HandlesEvent( "suggestions" )
+ public Resolution suggestions( String wikiName, int maxLength )
+ {
+ StopWatch sw = new StopWatch();
+ sw.start();
+ List<String> list = new ArrayList<String>(maxLength);
+
+ if( wikiName.length() > 0 )
+ {
+
+ // split pagename and attachment filename
+ String filename = "";
+ int pos = wikiName.indexOf("/");
+ if( pos >= 0 )
+ {
+ filename = wikiName.substring( pos ).toLowerCase();
+ wikiName = wikiName.substring( 0, pos );
+ }
+
+ String cleanWikiName = MarkupParser.cleanLink(wikiName).toLowerCase() + filename;
+
+ String oldStyleName = MarkupParser.wikifyLink(wikiName).toLowerCase() + filename;
+
+ Set<String> allPages;
+ try
+ {
+ allPages = getContext().getEngine().getReferenceManager().findCreated();
+ }
+ catch( ProviderException e )
+ {
+ // FIXME: THis is probably not very smart.
+ allPages = new TreeSet<String>();
+ }
+
+ int counter = 0;
+ for( Iterator<String> i = allPages.iterator(); i.hasNext() && counter < maxLength; )
+ {
+ String p = i.next();
+ String pp = p.toLowerCase();
+ if( pp.startsWith( cleanWikiName) || pp.startsWith( oldStyleName ) )
+ {
+ list.add( p );
+ counter++;
+ }
+ }
+ }
+
+ sw.stop();
+ if( log.isDebugEnabled() )
+ {
+ log.debug("Suggestion request for "+wikiName+" done in "+sw );
+ }
+
+ return new EventResolution( getContext(), list, false );
+ }
+}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java?rev=912169&r1=912168&r2=912169&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java Sat Feb 20 18:03:55 2010
@@ -36,6 +36,7 @@
import org.apache.wiki.log.Logger;
import org.apache.wiki.log.LoggerFactory;
import org.apache.wiki.search.SearchResult;
+import org.apache.wiki.ui.stripes.EventResolution;
import org.apache.wiki.ui.stripes.TemplateResolution;
import org.apache.wiki.ui.stripes.WikiRequestContext;
@@ -45,20 +46,20 @@
@UrlBinding( "/Search.jsp" )
public class SearchActionBean extends AbstractActionBean
{
- private static Logger log = LoggerFactory.getLogger("JSPWikiSearch");
+ private static Logger log = LoggerFactory.getLogger( "JSPWikiSearch" );
public static final Collection<SearchResult> NO_RESULTS = Collections.emptyList();
-
+
private Collection<SearchResult> m_results = NO_RESULTS;
private String m_query = null;
private int m_maxItems = 20;
-
+
private int m_start = 0;
-
+
private boolean m_details = false;
-
+
/**
* Enumeration of the search scope options.
*/
@@ -75,36 +76,37 @@
/** Attachment contents only. */
ATTACHMENTS
}
-
+
public boolean getDetails()
{
return m_details;
}
-
+
/**
* Sets the search results so that details for each result are displayed.
+ *
* @param details whether details should be displayed
*/
public void setDetails( boolean details )
{
m_details = details;
}
-
+
public int getMaxItems()
{
return m_maxItems;
}
-
+
public void setMaxItems( int maxItems )
{
m_maxItems = maxItems;
}
-
+
public int getStart()
{
return m_start;
}
-
+
public void setStart( int start )
{
m_start = start;
@@ -129,23 +131,25 @@
{
return m_results;
}
-
+
/**
- * Performs a search and returns the results as a list. For a given WikiPage to
- * be included in the results, the user must have permission to view it.
- * If the underlying providers encounter an abnormal IOException or other error,
- * it will be added to the ActionBeanContext's validation messages collection.
+ * Performs a search and returns the results as a list. For a given WikiPage
+ * to be included in the results, the user must have permission to view it.
+ * If the underlying providers encounter an abnormal IOException or other
+ * error, it will be added to the ActionBeanContext's validation messages
+ * collection.
+ *
* @param query the query
* @return the results
*/
private List<SearchResult> doSearch( String query )
{
- log.info("Searching with query '"+ query + "'.");
+ log.info( "Searching with query '" + query + "'." );
WikiEngine engine = getContext().getEngine();
AuthorizationManager mgr = engine.getAuthorizationManager();
-
+
//
- // Filter down to only those that we actually have a permission to view
+ // Filter down to only those that we actually have a permission to view
//
List<SearchResult> filteredResults = new ArrayList<SearchResult>();
try
@@ -156,15 +160,15 @@
WikiPage page = result.getPage();
PagePermission permission = new PagePermission( page, PagePermission.VIEW_ACTION );
try
- {
+ {
if( mgr.checkPermission( getContext().getWikiSession(), permission ) )
{
filteredResults.add( result );
}
}
- catch( Exception e )
- {
- log.error( "Searching for page " + page, e );
+ catch( Exception e )
+ {
+ log.error( "Searching for page " + page, e );
}
}
}
@@ -189,10 +193,9 @@
}
/**
- * Searches the wiki using the query string set for this
- * ActionBean. Search results are made available to callers via the
- * {@link #getResults()} method (and EL expression
- * <code>$wikiActionBean.results</code>).
+ * Searches the wiki using the query string set for this ActionBean. Search
+ * results are made available to callers via the {@link #getResults()}
+ * method (and EL expression <code>$wikiActionBean.results</code>).
*
* @return always returns a {@link ForwardResolution} to the template JSP
* <code>/Search.jsp</code>.
@@ -205,14 +208,14 @@
m_results = m_query == null ? NO_RESULTS : doSearch( m_query );
return new TemplateResolution( "Search.jsp" );
}
-
+
/**
- * Using AJAX, searches a specified wiki space using the query string set for this
- * ActionBean. Results are streamed back to the client as an array of JSON-encoded
- * SearchResult objects.
+ * Using AJAX, searches a specified wiki space using the query string set
+ * for this ActionBean. Results are streamed back to the client as an array
+ * of JSON-encoded SearchResult objects.
*
* @return always returns a {@link JavaScriptResolution} containing the
- * results; this may be a zero-length array
+ * results; this may be a zero-length array
*/
@HandlesEvent( "ajaxSearch" )
public Resolution ajaxSearch()
@@ -220,4 +223,33 @@
m_results = m_query == null ? NO_RESULTS : doSearch( m_query );
return new JavaScriptResolution( m_results );
}
+
+ /**
+ * AJAX event method that provides quick-search used in {@code SearchBox.jsp}.
+ *
+ * @return a {@link EventResolution} containing HTML to be inserted into an
+ * element.
+ */
+ @HandlesEvent( "quickSearch" )
+ public Resolution quickSearch()
+ {
+ m_results = m_query == null ? NO_RESULTS : doSearch( m_query );
+ String html = null;
+ StringBuilder b = new StringBuilder();
+ if( m_results.size() > 0 )
+ {
+ b.append( "<ul>" );
+ for( SearchResult result : m_results )
+ {
+ String url = getContext().getViewURL( result.getPage().getName() );
+ b.append( "<li>" );
+ b.append( "<a href=\"" + url + "\">" + result.getPage().getName() + "</a>" );
+ b.append( " <span class=\"small\">(" + result.getScore() + ")</span>" );
+ b.append( "</li>" );
+ }
+ b.append( "</ul>" );
+ html = b.toString();
+ }
+ return new EventResolution( getContext(), html, true );
+ }
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java?rev=912169&r1=912168&r2=912169&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java Sat Feb 20 18:03:55 2010
@@ -23,7 +23,6 @@
import java.io.IOException;
import java.util.*;
-import org.apache.commons.lang.time.StopWatch;
import org.apache.wiki.InternalWikiException;
import org.apache.wiki.NoRequiredPropertyException;
import org.apache.wiki.WikiEngine;
@@ -36,10 +35,7 @@
import org.apache.wiki.log.Logger;
import org.apache.wiki.log.LoggerFactory;
import org.apache.wiki.modules.InternalModule;
-import org.apache.wiki.parser.MarkupParser;
import org.apache.wiki.providers.ProviderException;
-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;
@@ -87,118 +83,6 @@
}
/**
- * Provides a JSON RPC API to the JSPWiki Search Engine.
- */
- public class JSONSearch implements RPCCallable
- {
- /**
- * Provides a list of suggestions to use for a page name.
- * Currently the algorithm just looks into the value parameter,
- * and returns all page names from that.
- *
- * @param wikiName the page name
- * @param maxLength maximum number of suggestions
- * @return the suggestions
- */
- public List<String> getSuggestions( String wikiName, int maxLength )
- {
- StopWatch sw = new StopWatch();
- sw.start();
- List<String> list = new ArrayList<String>(maxLength);
-
- if( wikiName.length() > 0 )
- {
-
- // split pagename and attachment filename
- String filename = "";
- int pos = wikiName.indexOf("/");
- if( pos >= 0 )
- {
- filename = wikiName.substring( pos ).toLowerCase();
- wikiName = wikiName.substring( 0, pos );
- }
-
- String cleanWikiName = MarkupParser.cleanLink(wikiName).toLowerCase() + filename;
-
- String oldStyleName = MarkupParser.wikifyLink(wikiName).toLowerCase() + filename;
-
- Set<String> allPages;
- try
- {
- allPages = m_engine.getReferenceManager().findCreated();
- }
- catch( ProviderException e )
- {
- // FIXME: THis is probably not very smart.
- allPages = new TreeSet<String>();
- }
-
- int counter = 0;
- for( Iterator<String> i = allPages.iterator(); i.hasNext() && counter < maxLength; )
- {
- String p = i.next();
- String pp = p.toLowerCase();
- if( pp.startsWith( cleanWikiName) || pp.startsWith( oldStyleName ) )
- {
- list.add( p );
- counter++;
- }
- }
- }
-
- sw.stop();
- if( log.isDebugEnabled() ) log.debug("Suggestion request for "+wikiName+" done in "+sw);
- return list;
- }
-
- /**
- * Performs a full search of pages.
- *
- * @param searchString The query string
- * @param maxLength How many hits to return
- * @return the pages found
- */
- public List<HashMap<String,Object>> findPages( String searchString, int maxLength )
- {
- StopWatch sw = new StopWatch();
- sw.start();
-
- List<HashMap<String,Object>> list = new ArrayList<HashMap<String,Object>>(maxLength);
-
- if( searchString.length() > 0 )
- {
- try
- {
- Collection<SearchResult> c;
-
- if( m_searchProvider instanceof LuceneSearchProvider )
- c = ((LuceneSearchProvider)m_searchProvider).findPages( searchString, 0 );
- else
- c = m_searchProvider.findPages( searchString );
-
- int count = 0;
- for( Iterator<SearchResult> i = c.iterator(); i.hasNext() && count < maxLength; count++ )
- {
- SearchResult sr = i.next();
- HashMap<String,Object> hm = new HashMap<String,Object>();
- hm.put( "page", sr.getPage().getName() );
- hm.put( "score", sr.getScore() );
- list.add( hm );
- }
- }
- catch(Exception e)
- {
- log.info("AJAX search failed; ",e);
- }
- }
-
- sw.stop();
- if( log.isDebugEnabled() ) log.debug("AJAX search complete in "+sw);
- return list;
- }
- }
-
- /**
* This particular method starts off indexing and all sorts of various activities,
* so you need to run this last, after things are done.
*
@@ -216,8 +100,6 @@
// Make sure we catch any page add/save/rename events
WikiEventManager.addWikiEventListener( engine.getContentManager(), this );
- JSONRPCManager.registerGlobalObject( JSON_SEARCH, new JSONSearch() );
-
try
{
m_searchProvider.initialize(engine, properties);