Janne, Andrew,
Wiki.jsonrpc() is pretty much doing what you are suggesting. It just needs an update not to work anymore with JsonRPC but with hook-up with Stripes' approach to ajax. This shouldn't be to hard to figure out. I'll check this out over the weekend, unless anyone is moving faster ;-) dirk On Mon, Jun 8, 2009 at 9:53 PM, Janne Jalkanen <[email protected]>wrote: > > Reminds me - the JS code used to call Ajax routines is disgustingly > loathsome and makes my eyes bleed and my stomach retch. Can we upgrade to a > newer Mootools lib (1.2.2, I think) and switch to Request.JSON and create a > JSONFactory or an extension for creating our AJAX requests? > > Something like wiki.json( "Search", "ajaxSearch", { param1 : value1, ... }, > callback(resultobj,resulttext) ); would be nice. This would construct the > URL to SearchActionBean, method ajaxSearch, with the given params. > > /Janne > > On 8 Jun 2009, at 21:52, Andrew Jaquith wrote: > > It will fix this one -- but only after we've hooked it up to the >> client JavaScript. Should not take long. >> >> On Mon, Jun 8, 2009 at 2:44 PM, Harry Metske<[email protected]> >> wrote: >> >>> Andrew, >>> >>> should this patch have fixed >>> https://issues.apache.org/jira/browse/JSPWIKI-510 (only for 3.0 of >>> course) ? >>> >>> Harry >>> >>> 2009/6/8 <[email protected]> >>> >>> >>> Author: ajaquith >>>> Date: Mon Jun 8 01:37:33 2009 >>>> New Revision: 782495 >>>> >>>> URL: http://svn.apache.org/viewvc?rev=782495&view=rev >>>> Log: >>>> Search.jsp migrated to Stripes. SearchActionBean now provides searching >>>> logic, including an ajaxSearch() method that filters results correctly >>>> (this >>>> is not hooked up to the client JavaScript yet, but it should be >>>> straightforward to do). Still some i18n cleanup to do. >>>> >>>> Modified: >>>> incubator/jspwiki/trunk/src/WebContent/Search.jsp >>>> incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js >>>> >>>> incubator/jspwiki/trunk/src/WebContent/templates/default/FindContent.jsp >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiContext.java >>>> >>>> >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/action/SearchActionBean.java >>>> >>>> >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IfNoSearchResultsTag.java >>>> >>>> >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultIteratorTag.java >>>> >>>> >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsSizeTag.java >>>> >>>> >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsTag.java >>>> >>>> Modified: incubator/jspwiki/trunk/src/WebContent/Search.jsp >>>> URL: >>>> >>>> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/Search.jsp?rev=782495&r1=782494&r2=782495&view=diff >>>> >>>> >>>> ============================================================================== >>>> --- incubator/jspwiki/trunk/src/WebContent/Search.jsp (original) >>>> +++ incubator/jspwiki/trunk/src/WebContent/Search.jsp Mon Jun 8 >>>> 01:37:33 >>>> 2009 >>>> @@ -18,108 +18,12 @@ >>>> specific language governing permissions and limitations >>>> under the License. >>>> --%> >>>> -<%@ page import="org.apache.wiki.log.Logger" %> >>>> -<%@ page import="org.apache.wiki.log.LoggerFactory" %> >>>> -<%@ page import="org.apache.wiki.*" %> >>>> -<%@ page import="org.apache.wiki.auth.*" %> >>>> -<%@ page import="org.apache.wiki.auth.permissions.*" %> >>>> -<%@ page import="java.util.*" %> >>>> +<%@ taglib uri="http://stripes.sourceforge.net/stripes.tld" prefix="s" >>>> %> >>>> <%@ page errorPage="/Error.jsp" %> >>>> -<%@ page import="org.apache.wiki.search.*" %> >>>> -<%@ taglib uri="http://jakarta.apache.org/jspwiki.tld" prefix="wiki" >>>> %> >>>> -<%@ taglib uri="http://stripes.sourceforge.net/stripes.tld" >>>> prefix="stripes" %> >>>> -<%@ page import="org.apache.wiki.util.TextUtil" %> >>>> -<%@ page import="org.apache.wiki.api.WikiPage" %> >>>> -<stripes:useActionBean >>>> beanclass="org.apache.wiki.action.SearchActionBean" >>>> event="find" id="wikiActionBean" /> >>>> +<s:useActionBean beanclass="org.apache.wiki.action.SearchActionBean" >>>> event="search" executeResolution="true" id="wikiActionBean" /> >>>> +<s:layout-render name="${templates['DefaultLayout.jsp']}"> >>>> + <s:layout-component name="content"> >>>> + <jsp:include page="${templates['FindContent.jsp']}" /> >>>> + </s:layout-component> >>>> +</s:layout-render> >>>> >>>> -<%! >>>> - Logger log = LoggerFactory.getLogger("JSPWikiSearch"); >>>> -%> >>>> - >>>> -<% >>>> - WikiEngine wiki = WikiEngine.getInstance( getServletConfig() ); >>>> - // Create wiki context and check for authorization >>>> - WikiContext wikiContext = wiki.createContext( request, >>>> WikiContext.FIND ); >>>> - String pagereq = wikiContext.getPage().getName(); >>>> - >>>> - // Get the search results >>>> - Collection list = null; >>>> - String query = request.getParameter( "query"); >>>> - String go = request.getParameter("go"); >>>> - >>>> - if( query != null ) >>>> - { >>>> - log.info("Searching for string "+query); >>>> - >>>> - try >>>> - { >>>> - list = wiki.findPages( query ); >>>> - >>>> - // >>>> - // Filter down to only those that we actually have a >>>> permission to view >>>> - // >>>> - AuthorizationManager mgr = wiki.getAuthorizationManager(); >>>> - >>>> - ArrayList filteredList = new ArrayList(); >>>> - >>>> - for( Iterator i = list.iterator(); i.hasNext(); ) >>>> - { >>>> - SearchResult r = (SearchResult)i.next(); >>>> - >>>> - WikiPage p = r.getPage(); >>>> - >>>> - PagePermission pp = new PagePermission( p, >>>> PagePermission.VIEW_ACTION ); >>>> - >>>> - try >>>> - { >>>> - if( mgr.checkPermission( >>>> wikiContext.getWikiSession(), >>>> pp ) ) >>>> - { >>>> - filteredList.add( r ); >>>> - } >>>> - } >>>> - catch( Exception e ) { log.error( "Searching for page >>>> "+p, >>>> e ); } >>>> - } >>>> - >>>> - pageContext.setAttribute( "searchresults", >>>> - filteredList, >>>> - PageContext.REQUEST_SCOPE ); >>>> - } >>>> - catch( Exception e ) >>>> - { >>>> - wikiContext.getWikiSession().addMessage( e.getMessage() ); >>>> - } >>>> - >>>> - query = TextUtil.replaceEntities( query ); >>>> - >>>> - pageContext.setAttribute( "query", >>>> - query, >>>> - PageContext.REQUEST_SCOPE ); >>>> - >>>> - // >>>> - // Did the user click on "go"? >>>> - // >>>> - if( go != null ) >>>> - { >>>> - if( list != null && list.size() > 0 ) >>>> - { >>>> - SearchResult sr = (SearchResult) >>>> list.iterator().next(); >>>> - >>>> - WikiPage wikiPage = sr.getPage(); >>>> - >>>> - String url = wikiContext.getViewURL( wikiPage.getName() >>>> ); >>>> - >>>> - response.sendRedirect( url ); >>>> - >>>> - return; >>>> - } >>>> - } >>>> - } >>>> - >>>> - // Set the content type and include the response content >>>> - response.setContentType("text/html; >>>> charset="+wiki.getContentEncoding() ); >>>> - String contentPage = wiki.getTemplateManager().findJSP( >>>> pageContext, >>>> - >>>> wikiContext.getTemplate(), >>>> - >>>> "ViewTemplate.jsp" ); >>>> -%><wiki:Include page="<%=contentPage%>" /><% >>>> - log.debug("SEARCH COMPLETE"); >>>> -%> >>>> >>>> Modified: >>>> incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js >>>> URL: >>>> >>>> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js?rev=782495&r1=782494&r2=782495&view=diff >>>> >>>> >>>> ============================================================================== >>>> --- incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js >>>> (original) >>>> +++ incubator/jspwiki/trunk/src/WebContent/scripts/jspwiki-common.js Mon >>>> Jun 8 01:37:33 2009 >>>> @@ -931,9 +931,9 @@ >>>> if (option.value == match) option.selected = true; >>>> }); >>>> >>>> - new Ajax(Wiki.TemplateUrl+'AJAXSearch.jsp', { >>>> - postBody: $('searchform2').toQueryString(), >>>> - update: 'searchResult2', >>>> + new Ajax(Wiki.BasePath+'Search.action', { >>>> + postBody: >>>> "ajaxSearch=&"+$('searchform2').toQueryString(), >>>> + update: 'searchResult2', >>>> method: 'post', >>>> onComplete: function() { >>>> $('spin').hide(); >>>> >>>> Modified: >>>> incubator/jspwiki/trunk/src/WebContent/templates/default/FindContent.jsp >>>> URL: >>>> >>>> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/templates/default/FindContent.jsp?rev=782495&r1=782494&r2=782495&view=diff >>>> >>>> >>>> ============================================================================== >>>> --- >>>> incubator/jspwiki/trunk/src/WebContent/templates/default/FindContent.jsp >>>> (original) >>>> +++ >>>> incubator/jspwiki/trunk/src/WebContent/templates/default/FindContent.jsp >>>> Mon >>>> Jun 8 01:37:33 2009 >>>> @@ -27,24 +27,18 @@ >>>> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> >>>> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> >>>> <%@ page import="javax.servlet.jsp.jstl.fmt.*" %> >>>> -<%@ taglib uri="http://stripes.sourceforge.net/stripes.tld" >>>> prefix="stripes" %> >>>> +<%@ taglib uri="http://stripes.sourceforge.net/stripes.tld" prefix="s" >>>> %> >>>> >>>> <wiki:TabbedSection> >>>> <wiki:Tab id="findcontent" titleKey="find.tab" accesskey="s"> >>>> >>>> -<form action="<wiki:Link format='url' jsp='Search.jsp'/>" >>>> - class="wikiform" >>>> - id="searchform2" >>>> - accept-charset="<wiki:ContentEncoding/>"> >>>> - >>>> +<s:form beanclass="org.apache.wiki.action.SearchActionBean" >>>> class="wikiform" >>>> + id="searchform2" acceptcharset="UTF-8"> >>>> + >>>> <h4><fmt:message key="find.input" /></h4> >>>> <p> >>>> - <input type="text" >>>> - name="query" id="query2" >>>> - value="<c:out value='${query}'/>" >>>> - size="32" /> >>>> - >>>> - <input type="checkbox" name="details" id="details" <c:if >>>> test='${param.details == "on"}'>checked='checked'</c:if> /> >>>> + <s:text name="query" id="query2" size="32" /> >>>> + <s:checkbox name="details" id="details" /> >>>> <fmt:message key="find.details" /> >>>> >>>> <select name="scope" id="scope"> >>>> @@ -55,16 +49,83 @@ >>>> <option value="attachment:" <c:if test='${param.scope eq >>>> "attachment:"}'>selected="selected"</c:if> ><fmt:message >>>> key='find.scope.attach' /></option> >>>> </select> >>>> >>>> - <input type="submit" name="ok" id="ok" value="<fmt:message >>>> key="find.submit.find" />" /> >>>> - <input type="submit" name="go" id="go" value="<fmt:message >>>> key="find.submit.go" />" /> >>>> - <input type="hidden" name="start" id="start" value="0" /> >>>> - <input type="hidden" name="maxitems" id="maxitems" value="20" /> >>>> + <s:submit name="search" id="ok" value="<fmt:message >>>> key='find.submit.find' />" /> >>>> + <s:submit name="go" id="go" value="<fmt:message >>>> key='find.submit.go' >>>> />" /> >>>> + <s:hidden name="start" id="start" value="0" /> >>>> + <s:hidden name="maxItems" id="maxitems" value="20" /> >>>> >>>> <span id="spin" class="spin" >>>> style="position:absolute;display:none;"></span> >>>> </p> >>>> -</form> >>>> +</s:form> >>>> + >>>> +<div id="searchResult2"> >>>> + <wiki:SearchResults> >>>> + >>>> + <h4><fmt:message key="find.heading.results"><fmt:param><c:out >>>> value="${wikiActionBean.query}" /></fmt:param></fmt:message></h4> >>>> + <p> >>>> + <fmt:message key="find.externalsearch" /> >>>> + <a class="external" href="http://www.google.com/search?q=<c:out >>>> value='${wikiActionBean.query}' />" title="Google Search '<c:out >>>> value='${wikiActionBean.query}' />'" target="_blank">Google</a><img >>>> class="outlink" src="images/out.png" alt="" /> >>>> + | >>>> + <a class="external" href=" >>>> http://en.wikipedia.org/wiki/Special:Search?search=<c:out >>>> value='${wikiActionBean.query}' />" title="Wikipedia Search '<c:out >>>> value='${wikiActionBean.query}' />'" target="_blank">Wikipedia</a><img >>>> class="outlink" src="images/out.png" alt="" /> >>>> + </p> >>>> + >>>> + <wiki:SetPagination start="${wikiActionBean.start}" >>>> total="${wikiActionBean.resultsCount}" pagesize="20" maxlinks="9" >>>> fmtkey="info.pagination" onclick="$('start').value=%s; >>>> SearchBox.runfullsearch();" /> >>>> + >>>> + <div class="graphBars"> >>>> + <div class="zebra-table"> >>>> + <table class="wikitable"> >>>> + >>>> + <tr> >>>> + <th align="left"><fmt:message key="find.results.page" >>>> /></th> >>>> + <th align="left"><fmt:message key="find.results.score" >>>> /></th> >>>> + </tr> >>>> + >>>> + <wiki:SearchResultIterator id="searchref" >>>> start="${wikiActionBean.start}" maxItems="${wikiActionBean.maxItems}"> >>>> + <tr> >>>> + <td><wiki:LinkTo><wiki:PageName/></wiki:LinkTo></td> >>>> + <td><span class="gBar"><%= searchref.getScore() >>>> %></span></td> >>>> + </tr> >>>> + >>>> + <c:if test="${wikiActionBean.details == 'true'}"> >>>> + <% >>>> + String[] contexts = searchref.getContexts(); >>>> + if( (contexts != null) && (contexts.length > 0) ) >>>> + { >>>> + %> >>>> + <tr class="odd"> >>>> + <td colspan="2"> >>>> + <div class="fragment"> >>>> + <% >>>> + for (int i = 0; i < contexts.length; i++) >>>> + { >>>> + %> >>>> + <%= (i > 0 ) ? "<span class='fragment_ellipsis'> ... >>>> </span>" : "" %> >>>> + <%= contexts[i] %> >>>> + <% >>>> + } >>>> + %> >>>> + </div> >>>> + </td> >>>> + </tr> >>>> + <% >>>> + } >>>> + %> >>>> + </c:if><%-- details --%> >>>> + </wiki:SearchResultIterator> >>>> + >>>> + <wiki:IfNoSearchResults> >>>> + <tr> >>>> + <td class="nosearchresult" colspan="2"><fmt:message >>>> key="find.noresults" /></td> >>>> + </tr> >>>> + </wiki:IfNoSearchResults> >>>> + >>>> + </table> >>>> + </div> >>>> + </div> >>>> + ${pagination} >>>> >>>> -<div id="searchResult2"><wiki:Include page="AJAXSearch.jsp" /></div> >>>> + </wiki:SearchResults> >>>> +</div> >>>> >>>> </wiki:Tab> >>>> >>>> >>>> Modified: >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiContext.java >>>> URL: >>>> >>>> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiContext.java?rev=782495&r1=782494&r2=782495&view=diff >>>> >>>> >>>> ============================================================================== >>>> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiContext.java >>>> (original) >>>> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiContext.java >>>> Mon >>>> Jun 8 01:37:33 2009 >>>> @@ -103,7 +103,7 @@ >>>> public static final String COMMENT = HandlerInfo.getHandlerInfo( >>>> EditActionBean.class, "comment" ).getRequestContext(); >>>> >>>> /** User is searching for content. */ >>>> - public static final String FIND = >>>> HandlerInfo.getHandlerInfo( >>>> SearchActionBean.class, "find" ).getRequestContext(); >>>> + public static final String FIND = >>>> HandlerInfo.getHandlerInfo( >>>> SearchActionBean.class, "search" ).getRequestContext(); >>>> >>>> /** User wishes to create a new group */ >>>> public static final String CREATE_GROUP = >>>> HandlerInfo.getHandlerInfo( GroupActionBean.class, "create" >>>> ).getRequestContext(); >>>> >>>> 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=782495&r1=782494&r2=782495&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 >>>> Mon Jun 8 01:37:33 2009 >>>> @@ -21,18 +21,191 @@ >>>> >>>> package org.apache.wiki.action; >>>> >>>> -import org.apache.wiki.ui.stripes.WikiRequestContext; >>>> +import java.util.ArrayList; >>>> +import java.util.Collection; >>>> +import java.util.Collections; >>>> +import java.util.List; >>>> >>>> import net.sourceforge.stripes.action.*; >>>> +import net.sourceforge.stripes.ajax.JavaScriptResolution; >>>> + >>>> +import org.apache.wiki.WikiEngine; >>>> +import org.apache.wiki.api.WikiPage; >>>> +import org.apache.wiki.auth.AuthorizationManager; >>>> +import org.apache.wiki.auth.permissions.PagePermission; >>>> +import org.apache.wiki.log.Logger; >>>> +import org.apache.wiki.log.LoggerFactory; >>>> +import org.apache.wiki.search.SearchResult; >>>> +import org.apache.wiki.ui.stripes.WikiRequestContext; >>>> >>>> +/** >>>> + * Searches the WikiPage collection for a given wiki. >>>> + */ >>>> @UrlBinding( "/Search.jsp" ) >>>> public class SearchActionBean extends AbstractActionBean >>>> { >>>> + private 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; >>>> + >>>> + 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; >>>> + } >>>> + >>>> + /** >>>> + * Returns the query string for the search. >>>> + * >>>> + * @return the query string >>>> + */ >>>> + public String getQuery() >>>> + { >>>> + return m_query; >>>> + } >>>> + >>>> + /** >>>> + * Returns the results of the search. >>>> + * >>>> + * @return the results >>>> + */ >>>> + public Collection<SearchResult> getResults() >>>> + { >>>> + return m_results; >>>> + } >>>> + >>>> + /** >>>> + * Returns the number of items returned by the current search. >>>> + * @return the number of items >>>> + */ >>>> + public int getResultsCount() >>>> + { >>>> + return m_results.size(); >>>> + } >>>> + >>>> + /** >>>> + * 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 + "'."); >>>> + WikiEngine engine = getContext().getEngine(); >>>> + AuthorizationManager mgr = engine.getAuthorizationManager(); >>>> + >>>> + // >>>> + // Filter down to only those that we actually have a >>>> permission >>>> to view >>>> + // >>>> + List<SearchResult> filteredResults = new >>>> ArrayList<SearchResult>(); >>>> + try >>>> + { >>>> + List<SearchResult> results = engine.findPages( query ); >>>> + for( SearchResult result : results ) >>>> + { >>>> + 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.debug( "Could not search using query '" + query + "'.", >>>> e >>>> ); >>>> + Message message = new SimpleMessage( e.getMessage() ); >>>> + getContext().getMessages().add( message ); >>>> + e.printStackTrace(); >>>> + } >>>> + return filteredResults; >>>> + } >>>> + >>>> + /** >>>> + * Sets the query string for the search. >>>> + * >>>> + * @param query the query string >>>> + */ >>>> + public void setQuery( String query ) >>>> + { >>>> + m_query = query; >>>> + } >>>> + >>>> + /** >>>> + * 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 >>>> + * <code>/Search.jsp</code>. >>>> + */ >>>> @DefaultHandler >>>> - @HandlesEvent( "find" ) >>>> + @HandlesEvent( "search" ) >>>> @WikiRequestContext( "find" ) >>>> - public Resolution view() >>>> + public Resolution search() >>>> { >>>> + m_results = m_query == null ? NO_RESULTS : doSearch( m_query ); >>>> return new ForwardResolution( "/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. >>>> + * >>>> + * @return always returns a {...@link JavaScriptResolution} containing >>>> the >>>> + * results; this may be a zero-length array >>>> + */ >>>> + @HandlesEvent( "ajaxSearch" ) >>>> + public Resolution ajaxSearch() >>>> + { >>>> + m_results = m_query == null ? NO_RESULTS : doSearch( m_query ); >>>> + return new JavaScriptResolution( m_results ); >>>> + } >>>> } >>>> >>>> Modified: >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IfNoSearchResultsTag.java >>>> URL: >>>> >>>> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IfNoSearchResultsTag.java?rev=782495&r1=782494&r2=782495&view=diff >>>> >>>> >>>> ============================================================================== >>>> --- >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IfNoSearchResultsTag.java >>>> (original) >>>> +++ >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/IfNoSearchResultsTag.java >>>> Mon Jun 8 01:37:33 2009 >>>> @@ -22,8 +22,8 @@ >>>> >>>> import java.io.IOException; >>>> import java.util.Collection; >>>> -import javax.servlet.jsp.PageContext; >>>> >>>> +import org.apache.wiki.action.SearchActionBean; >>>> import org.apache.wiki.search.SearchResult; >>>> >>>> /** >>>> @@ -36,17 +36,18 @@ >>>> { >>>> private static final long serialVersionUID = 0L; >>>> >>>> - @SuppressWarnings("unchecked") >>>> public final int doWikiStartTag() >>>> throws IOException >>>> { >>>> - Collection<SearchResult> list = >>>> (Collection<SearchResult>)pageContext.getAttribute( "searchresults", >>>> - >>>> PageContext.REQUEST_SCOPE ); >>>> - if( list == null || list.size() == 0 ) >>>> - { >>>> - return EVAL_BODY_INCLUDE; >>>> + if ( m_wikiActionBean != null && m_wikiActionBean instanceof >>>> SearchActionBean ) >>>> + { >>>> + boolean emptyQuery = >>>> ((SearchActionBean)m_wikiActionBean).getQuery() == null; >>>> + Collection<SearchResult> results = >>>> ((SearchActionBean)m_wikiActionBean).getResults(); >>>> + if ( emptyQuery || results.size() > 0 ) >>>> + { >>>> + return SKIP_BODY; >>>> + } >>>> } >>>> - >>>> - return SKIP_BODY; >>>> + return EVAL_BODY_INCLUDE; >>>> } >>>> } >>>> >>>> Modified: >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultIteratorTag.java >>>> URL: >>>> >>>> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultIteratorTag.java?rev=782495&r1=782494&r2=782495&view=diff >>>> >>>> >>>> ============================================================================== >>>> --- >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultIteratorTag.java >>>> (original) >>>> +++ >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultIteratorTag.java >>>> Mon Jun 8 01:37:33 2009 >>>> @@ -20,12 +20,12 @@ >>>> */ >>>> package org.apache.wiki.tags; >>>> >>>> -import java.util.ArrayList; >>>> import java.util.Collection; >>>> >>>> -import javax.servlet.jsp.PageContext; >>>> - >>>> +import org.apache.wiki.action.SearchActionBean; >>>> +import org.apache.wiki.action.WikiActionBean; >>>> import org.apache.wiki.search.SearchResult; >>>> +import org.apache.wiki.ui.stripes.WikiInterceptor; >>>> >>>> /** >>>> * Iterator tag for the current search results, as identified by a >>>> @@ -36,19 +36,17 @@ >>>> private static final long serialVersionUID = 1L; >>>> >>>> /** >>>> - * \ Returns the list of SearchResults to iterate over. >>>> + * Returns the list of SearchResults to iterate over. >>>> */ >>>> @Override >>>> - @SuppressWarnings( "unchecked" ) >>>> protected Collection<SearchResult> initItems() >>>> { >>>> - Collection<SearchResult> results = (Collection<SearchResult>) >>>> pageContext.getAttribute( "searchresults", >>>> - >>>> PageContext.REQUEST_SCOPE ); >>>> - if( results == null ) >>>> + WikiActionBean actionBean = WikiInterceptor.findActionBean( >>>> pageContext ); >>>> + if ( actionBean != null && actionBean instanceof >>>> SearchActionBean >>>> ) >>>> { >>>> - return new ArrayList<SearchResult>(); >>>> + return ((SearchActionBean)actionBean).getResults(); >>>> } >>>> - return results; >>>> + return SearchActionBean.NO_RESULTS; >>>> } >>>> >>>> /** >>>> >>>> Modified: >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsSizeTag.java >>>> URL: >>>> >>>> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsSizeTag.java?rev=782495&r1=782494&r2=782495&view=diff >>>> >>>> >>>> ============================================================================== >>>> --- >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsSizeTag.java >>>> (original) >>>> +++ >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsSizeTag.java >>>> Mon Jun 8 01:37:33 2009 >>>> @@ -22,8 +22,8 @@ >>>> >>>> import java.io.IOException; >>>> import java.util.Collection; >>>> -import javax.servlet.jsp.PageContext; >>>> >>>> +import org.apache.wiki.action.SearchActionBean; >>>> import org.apache.wiki.search.SearchResult; >>>> >>>> /** >>>> @@ -37,17 +37,14 @@ >>>> { >>>> private static final long serialVersionUID = 0L; >>>> >>>> - @SuppressWarnings("unchecked") >>>> public final int doWikiStartTag() >>>> throws IOException >>>> { >>>> - Collection<SearchResult> list = >>>> (Collection<SearchResult>)pageContext.getAttribute( "searchresults", >>>> - >>>> PageContext.REQUEST_SCOPE ); >>>> - if( list != null ) >>>> + if ( m_wikiActionBean != null && m_wikiActionBean instanceof >>>> SearchActionBean ) >>>> { >>>> - pageContext.getOut().print( list.size() ); >>>> + Collection<SearchResult> results = >>>> ((SearchActionBean)m_wikiActionBean).getResults(); >>>> + pageContext.getOut().print( results.size() ); >>>> } >>>> - >>>> return SKIP_BODY; >>>> } >>>> } >>>> >>>> Modified: >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsTag.java >>>> URL: >>>> >>>> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsTag.java?rev=782495&r1=782494&r2=782495&view=diff >>>> >>>> >>>> ============================================================================== >>>> --- >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsTag.java >>>> (original) >>>> +++ >>>> >>>> incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SearchResultsTag.java >>>> Mon Jun 8 01:37:33 2009 >>>> @@ -21,10 +21,10 @@ >>>> package org.apache.wiki.tags; >>>> >>>> import java.io.IOException; >>>> -import java.util.Collection; >>>> + >>>> import javax.servlet.jsp.PageContext; >>>> >>>> -import org.apache.wiki.search.SearchResult; >>>> +import org.apache.wiki.action.SearchActionBean; >>>> >>>> /** >>>> * Includes the body content, if there are any search results. >>>> @@ -36,16 +36,16 @@ >>>> { >>>> private static final long serialVersionUID = 0L; >>>> >>>> - @SuppressWarnings("unchecked") >>>> public final int doWikiStartTag() >>>> throws IOException >>>> { >>>> - Collection<SearchResult> list = >>>> (Collection<SearchResult>)pageContext.getAttribute( "searchresults", >>>> - >>>> PageContext.REQUEST_SCOPE ); >>>> - >>>> - if( list != null ) >>>> + if ( m_wikiActionBean != null && m_wikiActionBean instanceof >>>> SearchActionBean ) >>>> { >>>> - return EVAL_BODY_INCLUDE; >>>> + boolean emptyQuery = >>>> ((SearchActionBean)m_wikiActionBean).getQuery() == null; >>>> + if ( !emptyQuery ) >>>> + { >>>> + return EVAL_BODY_INCLUDE; >>>> + } >>>> } >>>> >>>> String message = (String)pageContext.getAttribute( "err", >>>> >>>> >>>> >>>> >>> >
