Overview
I've read lots of messsages of people with problems making Xindice work with Cocoon. I succeded and I could even make a logicsheet work with Xindice. It takes some time but if you follow the steps below carefully you should get a working Xindice in Cocoon through the pseudo protocol and the mentioned logicsheet.
Ready?
I assume you have a Cocoon working installation and a Xindice one (examples included) but maybe you have problems connecting them. I also assume you have Tomcat running on port 8080 and Xindice on port 4080 and COCOON_HOME is your home directory of the cocoon webapp inside Tomcat.
You will also need to download the eXist project or get only its XSP logicsheet from CVS repository.
The process explained below was tested on Cocoon 2.1-dev with Tomcat 4.1.9 and Xindice 1.0 release on Windows XP and also on Cocoon 2.0.3 release with Tomcat 4.1.9 and Xindice 1.0 release on Windows 2000 Professional SP3.
Let's go
- If you have Tomcat or Xindice running, stop them.
Follow the steps detailed at the well-known article on Xindice and Cocoon at Cocooncenter. Be very very careful about the last step. Remember: Copy xindice.jar from %XINDICE_HOME/java/lib to COCOON_HOME/WEB-INF/lib. This is esential and I've seen many exceptions because of this.
After the first two steps and following the last directions at cocooncenter you should be able to query the database. Try URLs like: http://localhost:8080/cocoon/xmldb/addressbook/.
- Let's install the logicsheet. If you have installed custome logicsheets previously just put the eXist logicsheet there, but if not, follow this steps.
Go to COCOON_HOME/WEB-INF/classes and make a new subdirectory. Call it logicsheets.
Copy the xmldb.xsl eXist logicsheet there.
Edit the file cocoon.xconf. You can find it in the COCOON_HOME/WEB-INF directory.
Look for a section starting with <markup-languages> and then look for <target-language name="java">. In that section you'll see several logicsheets defined. Let's define ours. Copy this there:{{{<!-- XMLDB logicsheet from eXist -->
<builtin-logicsheet>
<parameter name="prefix" value="xmldb"/> <parameter name="uri" value="http://exist-db.org/xmldb/1.0"/> <parameter name="href" value="resource://logicsheets/xmldb.xsl"/>
</builtin-logicsheet>}}}
- Please, remember, be careful. Double check you have copied it into the java language section. If you copy it for example at the end of the other logicsheets it won't work, cause the last ones are defined for a javascript target language.
- The logicsheet uses LOG4J as logger. So you have three choices:
Download LOG4J and copy the jar to COCOON_HOME/WEB-INF/lib.
- Edit the logicsheet and change the code. Move the LOG4J code to Logkit code. I do not know much about these logging tools, but remember Cocoon uses now Logkit.
Edit the logicsheet and comment out all the references to the logger. It's easy. You just have to look for LOG, logger or Category in the java sections. Remember that's Java code, so you shoould comment out using // or /* */, do not use <!-- -->.
Make a sample XSP file. You can find information at eXist website. And you can find also there the full documentation for the stylesheet.
Those examples won't work out of the box cause they're using eXist driver, so before querying the database you must set the driver to Xindice this way:
<xmldb:driver class="org.apache.xindice.client.xmldb.DatabaseImpl"/>
This can be accomplished also by editing the logicsheet, look carefully at the driver section.Save the following full working XSP as address.xsp in your webapp directory
{{{<?xml version="1.0"?> <xsp:page xmlns:xsp="http://apache.org/xsp"
xmlns:xmldb="http://exist-db.org/xmldb/1.0" xmlns:util="http://apache.org/xsp/util/2.0"> <document>
<xmldb:driver class="org.apache.xindice.client.xmldb.DatabaseImpl"/>
<xmldb:collection uri="xmldb:xindice://localhost:4080/db/addressbook/">
<xml-source>
<xmldb:get-document encoding="ISO-8859-1" as="xml">
<xmldb:name>request.getParameter("doc")</xmldb:name>
</xmldb:get-document>
</xml-source>
</xmldb:collection>
</document>
</xsp:page>}}}
Stop Tomcat and restart it, so changes to cocoon.xconf can take into effect.
Try http://localhost:8080/your_cocoon/your_app/address.xsp?doc=address1.xml
Maybe you'll get some error at the browser stage but look into the source code. The XML document is there! This is due to a non-valid XML Namespace. They cannot start with 'xml', see http://www.w3.org/TR/REC-xml-names/, and 'xmldb' starts with it. You can leave it that way, probably you'll use this document to feed a transformer so don't mind. If you care, edit the logicsheet and your XSP and change the eXist namespace from 'xmldb' for, for example, 'dbxml'.
I double checked my notes and I think that's all. Oh, unfortunately it does not do XUpdate...so we should learn more and try to write a custom transformer for that.
-- JosemaAlonso
Note
I'm not a guru, just a newbie, this is just the result of a hard work until late at night for some days, reading hundreds of email messages in the mailing archive and trying it very very hard. This has worked for me, hope it'll do for you. I tried to explain it the easiest way possible. I could only tried the get-collection and get-document tags by now.