Huge progress with the search functionality
Because testing with a Java class can be risky, Greg's set up a test environment for me to hack at, with a working Tomcat/Cocoon/eXist stack containing teiJournal.
In this environment, I've deployed the Java classes I wrote, and integrated them into the XQuery. This is how you do it:
- Add the jar file which contains your classes to the
Cocoon/WEB-INF/libdirectory. - Add a namespace for your class like this:
declare namespace su="java:SearchParser";
My class is not qualified by a hierarchy; it's a top-level class in a library calledxqSearchUtils.jar. It appears that the name of the jar file does not have to match the name of the class; the two classes in my jar file are calledSearchParserandSearchBit. - Construct an instance of your class like this:
declare variable $sp := su:new($search);
This is equivalent to Java:SearchParser sp = new SearchParser(search);
In this case, $search is the variable containing the search string the user has submitted. - Call functions on the object like this:
declare variable $searchStringBit := su:escGetXQueryClauses($sp);
which is equivalent to Java:String searchStringBit = sp.escGetXQueryClauses();
The only slight complications I encountered concerned the escaping of strings coming back from the Java object; to handle this, I added extra functions to the object to escape strings for XML. However, I have one slight issue remaining: the "phrases to highlight" stuff is coming back as a string, even though it's a set of XML <seg> elements. I need to figure out how to get elements from it.
Once that's all working, I need to turn on XACML, and figure out how to nail down the use of Java so only my classes can be called.