<%@ taglib uri="/WEB-INF/jspwiki.tld" prefix="wiki" %> <%@ page language="java" pageEncoding="UTF-8"%> <%@ page import="org.apache.log4j.*" %> <%@ page import="java.util.Collection" %> <%@ page import="com.ecyrd.jspwiki.*" %> <%@ page import="com.ecyrd.jspwiki.ui.*" %> <%@ page import="java.util.*" %> <%@ page import="org.apache.commons.lang.*" %> <%@ page import="java.net.URLEncoder" %> <%@ page import="com.ecyrd.jspwiki.auth.*" %> <%@ page import="com.ecyrd.jspwiki.auth.permissions.*" %> <%@ 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.*" %> <%! public void jspInit() { wiki = WikiEngine.getInstance( getServletConfig() ); } Logger log = Logger.getLogger("JSPWikiSearch"); WikiEngine wiki; %> <%! // FIXME: this should better be something like a wiki:Pagination TLD tag // FIXME: how to i18n // // 0 20 40 60 // 0 20 40 60 80 next // previous 20 40 *60* 80 100 next // previous 40 60 80 100 120 /* makePagination : return html string with pagination links * (eg: previous 1 2 3 next) * startitem : cursor * itemcount : total number of items * pagesize : number of items per page * maxpages : number of pages directly accessible via a pagination link * linkAttr : html attributes of the generated links: use '%s' to replace with item offset */ String wiki_Pagination( int startitem, int itemcount, int pagesize, int maxpages, String linkAttr, PageContext pageContext ) { if( itemcount <= pagesize ) return null; int maxs = pagesize * maxpages; int mids = pagesize * ( maxpages / 2 ); StringBuffer pagination = new StringBuffer(); pagination.append( "" ); pagination.append( LocaleSupport.getLocalizedMessage(pageContext, "info.pagination.total", new Object[]{new Integer(itemcount)} ) ); pagination.append( "" ); return pagination.toString(); } // linkAttr : use '%s' to replace with cursor offset // eg : // linkAttr = "href='#' title='%s' onclick='$(start).value= %s; updateSearchResult();'"; void appendLink( StringBuffer sb, String linkAttr, int linkFrom, int pagesize, String linkText, PageContext pageContext ) { String title = LocaleSupport.getLocalizedMessage(pageContext, "info.pagination.showall"); //if( linkFrom > -1 ) title = "Show page from " + (linkFrom+1) + " to "+ (linkFrom+pagesize) ; if( linkFrom > -1 ) title = LocaleSupport.getLocalizedMessage(pageContext, "info.pagination.show", new Object[]{new Integer(linkFrom+1), new Integer(linkFrom+pagesize) } ); sb.append( "" + linkText + "  " ); } ; %> <% /* ********************* actual start ********************* */ /* FIXME: too much hackin on this level */ /* Create wiki context and check for authorization */ WikiContext wikiContext = wiki.createContext( request, WikiContext.FIND ); if(!wikiContext.hasAccess( response )) return; String query = request.getParameter( "query"); if( (query != null) && ( !query.trim().equals("") ) ) { try { Collection list = wiki.findPages( query ); // Filter down to only those that we actually have a permission to view AuthorizationManager mgr = wiki.getAuthorizationManager(); ArrayList items = 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 ) ) { items.add( r ); } } catch( Exception e ) { log.error( "Searching for page "+p, e ); } } pageContext.setAttribute( "searchresults", items, PageContext.REQUEST_SCOPE ); } catch( Exception e ) { wikiContext.getWikiSession().addMessage( e.getMessage() ); } } /**************************************************************/ int startitem = 0; // first item to show int pagesize = 20; // #items to show in one go int maxpages = 9; // max pagination links -- odd figure int itemcount; // #items in items String parm_start = request.getParameter( "start"); if( parm_start != null ) startitem = Integer.parseInt( parm_start ) ; String parm_pagesize = request.getParameter( "pagesize"); if( parm_pagesize != null ) pagesize = Integer.parseInt( parm_pagesize ) ; String parm_details = request.getParameter( "details"); /**********/ String start = (String)request.getParameter("start"); int startVal = 0; try { startVal = Integer.parseInt(start); } catch(Exception e) {} if( startVal < 0 ) startVal = 0; int endVal = startVal + 20; Collection list = (Collection)pageContext.getAttribute( "searchresults", PageContext.REQUEST_SCOPE ); int prevSize = 0, nextSize = 0; if( list != null ) { if( endVal > list.size() ) endVal = list.size(); prevSize = Math.max( startVal, 20 ); nextSize = Math.min(list.size() - endVal, 20); } %>

Google | Wikipedia

<%--

<%=startVal+1%> <%=endVal%>

<%-- <% if( startVal > 0 ) { %> <%=prevSize%> . <% } %> <% if( endVal < list.size() ) { %> <%=nextSize%> . <% } %>

--%> <% String linkAttr = "href='#' title='Show search block starting at %s' onclick='$(\"start\").value=%s; updateSearchResult();'"; String pagination = wiki_Pagination(startitem, list.size(), pagesize, maxpages, linkAttr, pageContext); %> <%= (pagination == null) ? "" : pagination %>

<% if( parm_details != null ) { String[] contexts = searchref.getContexts(); if( (contexts != null) && (contexts.length > 0) ) { %> <% } } /* parm_details */ %>
<%= searchref.getScore() %>
<% for (int i = 0; i < contexts.length; i++) { %> <%= (i > 0 ) ? " ... " : "" %> <%= contexts[i] %> <% } %>
<%= (pagination == null) ? "" : pagination %>