Hi,
I have been trying to modify the default search-and-result.xsp to suit
my needs and have ran into a rather large problem. I keep on getting
"org.apache.cocoon.ProcessingException: Error executing pipeline.:
org.apache.cocoon.ProcessingException: Error executing pipeline.:
org.apache.cocoon.ProcessingException: Failed to execute pipeline.:
java.lang.NullPointerException "
However, I'm quite sure that the pipeline is ok, since when I comment
out the contents of my search-and-result.xsp file, things seem to work
(I get a rather nicely formated, but 'body' empty page .. which is to be
expected)
When I look in my log4j.log file I see :
372823366 2005-06-21 16:56:48,819 [http-8080-Processor25] ERROR
sitemap.handled-errors.prepareErrorHandler():165 - Error executing
pipeline.
org.apache.cocoon.ProcessingException: Error executing pipeline.:
org.apache.cocoon.ProcessingException: Error executing pipeline.:
org.apache.cocoon.ProcessingException: Failed to execute pipeline.:
java.lang.NullPointerException
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.handleException(AbstractProcessingPipeline.java:940)
at
org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.processXMLPipeline(AbstractCachingProcessingPipeline.java:281)
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(AbstractProcessingPipeline.java:483)
at
...
Does this mean that my problem is my 'handle-errors' pipeline or does it
mean that my problem is an exception which is thrown by my xsp ?
I have tried placing a few System.err.println(".search(): BLAH"); inside
my xsp to no avail.
Any help/hints on where I should look would be greatly appreciated.
Thank you,
Vica
PS. I have attached my xsp file, based on search-and-result.xsp on
http://solprovider.com/lenya/&cat=Search site.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page language="java"
xmlns:xsp="http://apache.org/xsp"
xmlns:util="http://apache.org/xsp/util/2.0"
xmlns:xsp-request="http://apache.org/xsp/request/2.0"
>
<xsp:structure>
<xsp:include>java.io.FileNotFoundException</xsp:include>
<xsp:include>java.util.Enumeration</xsp:include>
<xsp:include>java.util.HashSet</xsp:include>
<xsp:include>java.util.Hashtable</xsp:include>
<xsp:include>java.util.Iterator</xsp:include>
<xsp:include>java.util.StringTokenizer</xsp:include>
<xsp:include>java.util.Vector</xsp:include>
<xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
<xsp:include>org.apache.avalon.framework.component.ComponentException</xsp:include>
<xsp:include>org.apache.cocoon.environment.Session</xsp:include>
<xsp:include>org.apache.lenya.ac.Accreditable</xsp:include>
<xsp:include>org.apache.lenya.ac.Identifiable</xsp:include>
<xsp:include>org.apache.lenya.ac.Identity</xsp:include>
<xsp:include>org.apache.lenya.lucene.ReTokenizeFile</xsp:include>
<xsp:include>org.apache.lenya.lucene.Publication</xsp:include>
<xsp:include>org.apache.lucene.analysis.Analyzer</xsp:include>
<xsp:include>org.apache.lucene.analysis.standard.StandardAnalyzer</xsp:include>
<xsp:include>org.apache.lucene.document.Document</xsp:include>
<xsp:include>org.apache.lucene.document.Field</xsp:include>
<xsp:include>org.apache.lucene.queryParser.QueryParser</xsp:include>
<xsp:include>org.apache.lucene.queryParser.MultiFieldQueryParser</xsp:include>
<xsp:include>org.apache.lucene.search.Hits</xsp:include>
<xsp:include>org.apache.lucene.search.IndexSearcher</xsp:include>
<xsp:include>org.apache.lucene.search.Query</xsp:include>
<xsp:include>org.apache.lucene.search.Searcher</xsp:include>
<xsp:include>org.apache.lucene.search.Sort</xsp:include>
</xsp:structure>
<xsp:logic>
/* ======================================================================================================================== */
/* GLOBAL VARIABLES */
/* ======================================================================================================================== */
File workDir = null;
File indexDir = null;
File excerptDir = null;
Vector roles = new Vector();
Hashtable protectedAreas = new Hashtable();
/* ------------------------------------------------------------------------------------------------------------------------ */
/** Contextualize this class */
/* ------------------------------------------------------------------------------------------------------------------------ */
public void contextualize(Context context) throws ContextException
{
super.contextualize( context );
workDir = (File) context.get(Constants.CONTEXT_WORK_DIR);
}
/* ------------------------------------------------------------------------------------------------------------------------ */
/** Search index */
/* ------------------------------------------------------------------------------------------------------------------------ */
Hits search(String query_string, String sortField, boolean sortReverse)
throws ProcessingException, IOException
{
System.err.println(".search(): VICA EXCEPTION - inside search()");
// Load roles
Session session = request.getSession(true);
if(session != null)
{
Identity id = (Identity) session.getAttribute("org.apache.lenya.ac.Identity");
if (id != null)
{
Identifiable[] ids = id.getIdentifiables();
Accreditable[] acs = id.getAccreditables();
for (int ai = 0; ai < acs.length; ai++)
{
boolean found = false;
for(int i = 0; i < ids.length; i++)
{
if(ids[i].toString().equals(acs[ai].toString()))
found = true;
}
if(!found)
roles.add(acs[ai].toString());
}
} // id
} // session
Hits hits = null;
Searcher searcher = new IndexSearcher(indexDir.getAbsolutePath());
Analyzer l_analyzer = new StandardAnalyzer();
QueryParser l_queryParser = new QueryParser(mSearchFields[0], l_analyzer); // Single field
l_queryParser.setOperator(QueryParser.DEFAULT_OPERATOR_AND);
getLogger().debug(query_string);
Query l_query = l_queryParser.parse(query_string); // Single field
if (sortField != null)
{
Sort sort = new Sort(sortField, sortReverse);
hits = searcher.search(l_query, sort);
}
else
{
hits = searcher.search(l_query);
}
return hits;
}
/* ------------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------------------ */
String getPercent(float score)
{
return(""+java.lang.Math.round(score*100.0));
}
/* ======================================================================================================================== */
/* GLOBAL VARIABLES */
/* ======================================================================================================================== */
Hits mHits;
int mHitsLength=-1;
String[] mWords = new String[0];
int mHitsPerPage;
int mMaxPages;
int mExcerptOffset;
int start;
int end;
System.err.println(".search(): VICA EXCEPTION - in the begining");
</xsp:logic>
<search-and-results>
<xsp:logic>
// ***********************
// *** Protected Areas ***
// ***********************
// DEFINITION: protectedAreas.add("/UrlStart", "group,group");
// UrlStart begins with / after .../live.
// There are no spaces between groups and commas.
//protectedAreas.put("/employee", "employee");
// Get sitemap path
org.apache.excalibur.source.Source input_source=this.resolver.resolveURI("");
String sitemapPath = input_source.getURI().substring(5); //Remove "file:" protocol
// Read publication parameters from sitemap
Publication mPub = new Publication();
mPub.id = parameters.getParameter("pub-id","@ID@");
mPub.name = parameters.getParameter("pub-name","@NAME@");
mPub.indexDir = parameters.getParameter("pub-index-dir","@INDEX-DIR@");
mPub.searchFields = parameters.getParameter("pub-search-fields","title, contents");
mPub.excerptDir = parameters.getParameter("pub-excerpt-dir","@EXCERPT-DIR@");
mPub.prefix = parameters.getParameter("pub-prefix","@PREFIX@");
mHitsPerPage = Integer.parseInt(parameters.getParameter("max-hits-per-page","13"));
mMaxPages = Integer.parseInt(parameters.getParameter("max-pages","5"));
mExcerptOffset = Integer.parseInt(parameters.getParameter("excerpt-offset","100"));
// Read parameters from query string
String mQuery = <xsp-request:get-parameter name="queryStr" default="Holiday"/>;
String sortBy = <xsp-request:get-parameter name="sortBy" default="score"/>;
String sortReverse = <xsp-request:get-parameter name="sortReverse" default="false"/>;
String language = "en";
String[] mSearchFields = (mPub.getFields() == null ? {title, contents} : mPub.getFields());
String startString = <xsp-request:get-parameter name="start" default="1"/>;
String endString = <xsp-request:get-parameter name="end" default="10"/>;
start = new Integer(startString).intValue();
end = (endString == null ? mHitsPerPage : Integer.parseInt(endString));
// Set index and excerpt dir
if(mPub.indexDir.charAt(0) == '/')
indexDir=new File(mPub.indexDir);
else
indexDir=new File(sitemapPath + File.separator + mPub.indexDir);
String param_excerpt_dir = mPub.excerptDir;
if(param_excerpt_dir.charAt(0) == '/')
excerptDir = new File(param_excerpt_dir);
else
excerptDir = new File(sitemapPath + File.separator + param_excerpt_dir);
</xsp:logic>
<configuration>
<publication>
<xsp:attribute name="pid"><xsp:expr>mPub.id</xsp:expr></xsp:attribute>
<name><xsp:expr>mPub.name</xsp:expr></name>
<index-dir><xsp:expr>mPub.indexDir</xsp:expr></index-dir>
<search-fields>
<xsp:logic>
for (int k = 0; k < mSearchFields.length; k++)
{
</xsp:logic>
<field><xsp:expr>mSearchFields[k]</xsp:expr></field>
<xsp:logic>
}
</xsp:logic>
</search-fields>
<excerpt-dir><xsp:expr>mPub.excerptDir</xsp:expr></excerpt-dir>
<prefix><xsp:expr>mPub.prefix</xsp:expr></prefix>
</publication>
<hits-per-page><xsp:expr>mHitsPerPage</xsp:expr></hits-per-page>
<max-pages><xsp:expr>mMaxPages</xsp:expr></max-pages>
<excerpt-offset><xsp:expr>mExcerptOffset</xsp:expr></excerpt-offset>
</configuration>
<!-- Search Results -->
<search>
<xsp:logic>
Enumeration para_names = request.getParameterNames();
if(para_names.hasMoreElements())
{
</xsp:logic>
<request-parameters>
<xsp:logic>
while(para_names.hasMoreElements())
{
String para_name = (String)para_names.nextElement();
String para_value = request.getParameter(para_name);
</xsp:logic>
<parameter>
<xsp:attribute name="name"><xsp:expr>para_name</xsp:expr></xsp:attribute>
<xsp:attribute name="value"><xsp:expr>para_value</xsp:expr></xsp:attribute>
</parameter>
<xsp:element>
<xsp:param name="name"><xsp:expr>para_name</xsp:expr></xsp:param>
<xsp:expr>para_value</xsp:expr>
</xsp:element>
<xsp:logic>
}
</xsp:logic>
</request-parameters>
<xsp:logic>
}
if (mQuery != null && mQuery.length() != 0 && mPub.id != null && mPub.id.length() > 0)
{
try
{
if (sortBy.equals("score"))
mHits = search(mQuery, null, false);
else
mHits = search(mQuery, sortBy, sortReverse.equals("true"));
}
catch(Exception e)
{
System.err.println(".search(): EXCEPTION: "+e);
</xsp:logic>
<exception><xsp:expr>e.toString()</xsp:expr></exception>
<xsp:logic>
}
if (mHits == null)
mHitsLength = -1;
else
mHitsLength = mHits.length();
</xsp:logic>
<publication-id><xsp:expr>mPub.id</xsp:expr></publication-id>
<publication-name><xsp:expr>mPub.name</xsp:expr></publication-name>
<publication-prefix><xsp:expr>mPub.prefix</xsp:expr></publication-prefix>
<sort-by><xsp:expr>sortBy</xsp:expr></sort-by>
<query><xsp:expr>mQuery</xsp:expr></query>
<words>
<xsp:logic>
twords = new Vector();
StringTokenizer st = new StringTokenizer(mQuery," ");
while(st.hasMoreTokens())
{
String word=(String)st.nextElement();
if(!(word.equalsIgnoreCase("OR") || word.equalsIgnoreCase("AND")))
{
<word><xsp:expr>word</xsp:expr></word>
twords.addElement(word);
}
}
mWords = new String[twords.size()];
for(int i = 0; i < twords.size(); i++)
mWords[i] = (String)twords.elementAt(i);
</xsp:logic>
</words>
<start><xsp:expr>start</xsp:expr></start>
<end><xsp:expr>end</xsp:expr></end>
<language><xsp:expr>language</xsp:expr></language>
<fields>
<xsp:logic>
for (int i = 0; i < mSearchFields.length; i++)
{
<field><xsp:expr>mSearchFields[i]</xsp:expr></field>
}
</xsp:logic>
</fields>
<xsp:logic>
}
else
{
mHitsLength = -1;
mHits = null;
}
</xsp:logic>
</search>
<!-- Results -->
<results>
<xsp:logic>
if(mHits != null)
{
int validCount = 0; //number of valid results
if(mHitsLength > 0)
{
</xsp:logic>
<hits>
<xsp:logic>
// i = index of result. validCount = count valid results.
for (int i = 0; (i < mHits.length()); i++)
{
Document ldoc = mHits.doc(i);
Enumeration lfields = ldoc.fields();
String lpath = ldoc.get("path");
String lurl = ldoc.get("url");
String ltitle = ldoc.get("title");
String mime_type = ldoc.get("mime-type");
String docLanguage = "";
if(lpath != null)
{
</xsp:logic>
<hit>
<score>
<xsp:attribute name="percent"><xsp:expr>getPercent(mHits.score(i))</xsp:expr></xsp:attribute>
<xsp:expr>mHits.score(i)</xsp:expr>
</score>
<path><xsp:expr>lpath</xsp:expr></path>
</hit>
<xsp:logic>
}
else if(lurl != null)
{
// Check Language
// This also filters sitetree.xml since it has no language.
docLanguage = "";
while (lfields.hasMoreElements())
{
Field lfield = (Field)lfields.nextElement();
if(lfield.name().compareTo("language") == 0)
docLanguage = lfield.stringValue();
}
</xsp:logic>
<language><xsp:expr>language</xsp:expr></language>
<language-check><xsp:attribute name="doc"><xsp:expr>docLanguage</xsp:expr></xsp:attribute></language-check>
<xsp:logic>
if((docLanguage.length() > 0) && (language.indexOf(docLanguage) != -1))
{
</xsp:logic>
<language-yes/>
<xsp:logic>
// Get URL parts
String parent = "";
String filename = "";
String querystring = "";
if(lurl.lastIndexOf("/") > -1)
{
parent = lurl.substring(0,lurl.lastIndexOf("/"));
filename = lurl.substring(lurl.lastIndexOf("/")+1);
}
if(lurl.indexOf("?") > -1)
querystring = lurl.substring(lurl.indexOf("?"));
// Check Restricted
boolean restricted = false;
// Get list of restricted prefixes and check against roles.
Enumeration protectedArea = protectedAreas.keys();
while((!restricted) && protectedArea.hasMoreElements())
{
String startUrl = (String) protectedArea.nextElement();
if(parent.startsWith(startUrl))
{
StringTokenizer rolesAllowed = new StringTokenizer((String)protectedAreas.get(startUrl), ",");
restricted = true;
while(rolesAllowed.hasMoreElements())
{
// Check roles
if(roles.contains(rolesAllowed.nextElement()))
restricted = false;
}
}
}
if(!restricted)
{
// Build hit
validCount++;
if((validCount >= start) && (validCount <= end))
{
</xsp:logic>
<hit>
<xsp:attribute name="pos"><xsp:expr>validCount</xsp:expr></xsp:attribute>
<fields>
<xsp:logic>
lfields = ldoc.fields();
int first = -1;
while (lfields.hasMoreElements())
{
Field lfield = (Field)lfields.nextElement();
String slfield = lfield.stringValue();
if(lfield.name().equals("htmlbody"))
{
String tmphtmlbody = slfield;
String upperhtmlbody = tmphtmlbody.toUpperCase();
if(mWords.length < 0)
{
for (int idx = 0; idx < mWords.length; idx++)
{
String upperword = mWords[idx].toUpperCase();
int wordLen = upperword.length();
StringBuffer sb = new StringBuffer();
int last = 0;
int current = upperhtmlbody.indexOf(upperword);
if((current < first) || (first == -1)) first = current;
while(current > last)
{
sb.append(tmphtmlbody.substring(last, current));
sb.append("~").append(tmphtmlbody.substring(current, current + wordLen)).append("~");
last = current + wordLen;
current = upperhtmlbody.indexOf(upperword, last);
}
sb.append(tmphtmlbody.substring(last));
tmphtmlbody = sb.toString();
upperhtmlbody = tmphtmlbody.toUpperCase();
}
}
if(slfield.length() > mExcerptOffset)
{
int startIdx = 0;
int endIdx = mExcerptOffset;
int halfIdx = mExcerptOffset/2;
if(first < halfIdx)
{
endIdx = tmphtmlbody.indexOf(' ', mExcerptOffset);
}
else
{
startIdx = tmphtmlbody.indexOf(' ', first - halfIdx);
endIdx = tmphtmlbody.indexOf(' ', startIdx + mExcerptOffset);
}
tmphtmlbody = tmphtmlbody.substring(startIdx, endIdx);
}
StringTokenizer tokens = new StringTokenizer(tmphtmlbody, "~");
boolean needCloseHtmlBody = false;
if(tokens.hasMoreTokens())
{
needCloseHtmlBody = true;
</xsp:logic>
<htmlbody><xsp:expr>tokens.nextToken()</xsp:expr>
<xsp:logic>
}
while(tokens.hasMoreTokens())
{
</xsp:logic>
<word><xsp:expr>tokens.nextToken()</xsp:expr></word>
<xsp:logic>
if(tokens.hasMoreTokens())
{
</xsp:logic>
<xsp:expr>tokens.nextToken()</xsp:expr>
<xsp:logic>
}
}
if(needCloseHtmlBody)
{
</xsp:logic>
</htmlbody>
<xsp:logic>
}
}
else
{
</xsp:logic>
<xsp:element>
<xsp:param name="name"><xsp:expr>lfield.name()</xsp:expr></xsp:param>
<xsp:expr>slfield</xsp:expr>
</xsp:element>
<xsp:logic>
}
} /* 425 */
</xsp:logic>
</fields>
<score>
<xsp:attribute name="percent"><xsp:expr>getPercent(mHits.score(i))</xsp:expr></xsp:attribute>
<xsp:expr>mHits.score(i)</xsp:expr>
</score>
<uri>
<xsp:attribute name="parent"><xsp:expr>parent</xsp:expr></xsp:attribute>
<xsp:attribute name="filename"><xsp:expr>filename</xsp:expr></xsp:attribute>
<xsp:attribute name="querystring"><xsp:expr>querystring</xsp:expr></xsp:attribute>
<xsp:expr>lurl</xsp:expr>
</uri>
<xsp:logic>
File excerptFile=new File(excerptDir+File.separator+lurl);
if((ltitle != null) && (ltitle.length() > 0))
{
<title><xsp:expr>ltitle</xsp:expr></title>
}
else
{
<title><xsp:expr>excerptFile.getName()</xsp:expr></title>
<no-title/>
}
if((mime_type != null) && (mime_type.length() > 0))
{
<mime-type><xsp:expr>mime_type</xsp:expr></mime-type>
}
else
{
<no-mime-type/>
}
try
{
ReTokenizeFile rtf = new ReTokenizeFile();
rtf.setOffset(mExcerptOffset);
String excerpt = rtf.getExcerpt(excerptFile, mWords);
if(excerpt != null)
{
excerpt=rtf.emphasizeAsXML(rtf.tidy(excerpt), mWords);
<util:include-expr><util:expr><xsp:expr>excerpt</xsp:expr></util:expr></util:include-expr>
}
else
{
System.err.println(".search(): EXCEPTION: "+e);
return;
}
} /* 382 */
catch(FileNotFoundException e)
{
System.err.println(".search(): EXCEPTION: "+e);
</xsp:logic>
<no-excerpt>
<file>
<xsp:attribute name="src"><xsp:expr>excerptFile.getAbsolutePath()+" "+mWords[0]+" "+e</xsp:expr></xsp:attribute>
</file>
</no-excerpt>
<xsp:logic>
}
catch(Exception e)
{
System.err.println(".search(): EXCEPTION: "+e);
</xsp:logic>
<excerpt-exception><xsp:expr>""+e</xsp:expr></excerpt-exception>
<xsp:logic>
}
</xsp:logic>
</hit>
<xsp:logic>
}
} // END - Within range (start-end)
} // END - Check Restricted
} // END - Check Language
}
</xsp:logic>
</hits>
<xsp:logic>
}
int number_of_pages = (validCount/mHitsPerPage);
if(number_of_pages * mHitsPerPage != validCount)
number_of_pages = number_of_pages + 1;
if(number_of_pages > mMaxPages)
number_of_pages = mMaxPages;
if(validCount == 0)
{
number_of_pages = 0;
}
else
{
</xsp:logic>
<pages>
<xsp:logic>
for(int i=0; i< number_of_pages; i++)
{
int pstart = i * mHitsPerPage+1;
int pend = (i+1) * mHitsPerPage;
if(validCount < pend)
pend = validCount;
String type="other";
if(pstart == start)
type="current";
else if (pstart == start - mHitsPerPage)
type="previous";
else if (pstart == start + mHitsPerPage)
type="next";
</xsp:logic>
<page>
<xsp:attribute name="start"><xsp:expr>pstart</xsp:expr></xsp:attribute>
<xsp:attribute name="end"><xsp:expr>pend</xsp:expr></xsp:attribute>
<xsp:attribute name="type"><xsp:expr>type</xsp:expr></xsp:attribute>
</page>
<xsp:logic>
}
</xsp:logic>
</pages>
<xsp:logic>
}
</xsp:logic>
<total-hits><xsp:expr>validCount</xsp:expr></total-hits>
<xsp:logic>
}
</xsp:logic>
</results>
</search-and-results>
</xsp:page>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]