Wednesday
Jan 21, 2009
5:43 pm
JHTML Parameter Munging with Java
On our site, we have a search engine that does a file system crawl and returns a list of items, generating the URL to that item as it goes. We recently started using Teamsite forms for editors to create content and save it as XML. That XML is then rendered using a custom JHTML page that applies the appropriate XSL sheet and does some other work, but there’s no way to inform the search engine when that’s the case (at least not without splitting search into multiple repositories and doing a bunch of other work with the repositories).
One possible solution that I came up with, before abandoning it as a maintenance headache, is to detect the content type by its extension and then insert the necessary render page into the URL.
So we take the orginal JHTML values with the item parameter
<param name="searchItemURL" value="param:element.URLString">
that comes from the search results bean as it iterates through each item and generates the list of results within
<oparam name="output">
The results used to generate the href for the item result is this (note the backticks for the href):
<a href="`request.getParameter("searchItemURL")`"> <valueof param="element.title"></valueof></a>And replace that with this snippet of Java code:
<java> String searchItemURL = request.getParameter( "element.URLString" ); if(searchItemURL.endsWith(".xml")) { String[] linkStringArr = searchItemURL.split("/open"); if(linkStringArr.length!=0) { searchItemURL = linkStringArr[0]+"/open/render.jhtml?item=/open"+linkStringArr[1]; } } if(searchItemURL != null) { out.print("<a href=\""+searchItemURL+"\">"+request.getParameter( "element.title" )+"</a>"); } </java>