dims 01/08/23 05:54:58 Modified: . build.xml src/org/apache/cocoon/generation XMLDBGenerator.java xdocs docs-book.xml generators.xml Log: "Patches and additions to XML:DB" from "Gianugo Rabellino <[EMAIL PROTECTED]>" Revision Changes Path 1.52 +10 -3 xml-cocoon2/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/build.xml,v retrieving revision 1.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- build.xml 2001/08/20 16:14:01 1.51 +++ build.xml 2001/08/23 12:54:58 1.52 @@ -101,9 +101,10 @@ - HTML Generator : Requires the JTidy package (included in the dist) <map:generator name="html" src="org.apache.cocoon.generation.HTMLGenerator" label="content"/> -- XML:DB Generator: Requires the XML:DB API and a valid implementation - (notincluded in the dist) +- XML:DB Generators: Require the XML:DB API and a valid implementation + (not included in the dist) <map:generator name="xmldb" src="org.apache.cocoon.generation.XMLDBGenerator"/> + <map:generator name="xmldbcollection" src="org.apache.cocoon.generation.XMLDBCollectionGenerator"/> Transformers @@ -311,7 +312,7 @@ <exclude name="**/Sendmail*.java" unless="mail.present"/> <exclude name="**/LDAPTransformer*.java" unless="naming.present"/> <exclude name="**/JSPEngineImplWLS.java" unless="weblogic.present"/> - <exclude name="**/XMLDBGenerator.java" unless="xmldb.present"/> + <exclude name="**/XMLDB*.java" unless="xmldb.present"/> <exclude name="**/browser/*.x*"/> </fileset> </copy> @@ -630,6 +631,12 @@ <property name="xmldb.conf" value="<driver>org.dbxml.client.xmldb.DatabaseImpl</driver><base>xmldb:dbxml:///db/</base>"/> <java classname="st"> <arg line="-i ${build.war}/sitemap.xmap -o ${build.war}/sitemap.xmap -a generators xmldb org.apache.cocoon.generation.XMLDBGenerator ${xmldb.conf}"/> + <classpath> + <pathelement location="${bin.dir}"/> + </classpath> + </java> + <java classname="st"> + <arg line="-i ${build.war}/sitemap.xmap -o ${build.war}/sitemap.xmap -a generators xmldbcollection org.apache.cocoon.generation.XMLDBCollectionGenerator ${xmldb.conf}"/> <classpath> <pathelement location="${bin.dir}"/> </classpath> 1.2 +67 -19 xml-cocoon2/src/org/apache/cocoon/generation/XMLDBGenerator.java Index: XMLDBGenerator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/generation/XMLDBGenerator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- XMLDBGenerator.java 2001/08/20 16:14:01 1.1 +++ XMLDBGenerator.java 2001/08/23 12:54:58 1.2 @@ -19,6 +19,7 @@ import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.XMLResource; +import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.component.Component; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; @@ -45,9 +46,14 @@ * XML:DB compliant database. * It must to be configured as follows: * <pre> - * <driver>(a valid DB:XML compliant driver)</driver> - * <base>xmldb:yourdriver://host/an/optional/path/to/be/prepended</base> + * <driver> + * (a valid DB:XML compliant driver) + * </driver> + * <base> + * xmldb:yourdriver://host/an/optional/path/to/be/prepended + * </base> * </pre> + * * NOTE: the driver can be any DB:XML compliant driver (although this * component has been tested only with * <a href="http://www.dbxml.org">dbXML</a>, and the trailing @@ -57,7 +63,7 @@ */ public class XMLDBGenerator extends ComposerGenerator - implements Cacheable, Recyclable,Configurable { + implements Cacheable, Recyclable,Configurable,Initializable { protected String driver; protected String base; @@ -72,7 +78,8 @@ } /** - * Recycle the component, keep only the configuration variables. + * Recycle the component, keep only the configuration variables + * and the database instance for reuse. * */ @@ -80,9 +87,8 @@ super.recycle(); this.col = null; this.res = null; - this.database = null; - this.collection = null; this.xmlResource = null; + this.collection = null; } /** @@ -109,10 +115,44 @@ throw new ConfigurationException("XMLDB configuration not found"); } } + + /** + * Initialize the component getting a database instance. + * + * @exception Exception if an error occurs + */ + + public void initialize() throws Exception { + try { - public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) + Class c = Class.forName(driver); + database = (Database)c.newInstance(); + DatabaseManager.registerDatabase(database); + + } catch (XMLDBException xde) { + + this.getLogger().warn("Unable to connect to the XML:DB database"); + throw new ProcessingException("Unable to connect to the XML DB" + + xde.getMessage()); + + } catch (Exception e) { + + this.getLogger().warn("There was a problem setting up the connection"); + this.getLogger().warn("Make sure that your driver is available"); + throw new ProcessingException("Problem setting up the connection: " + + e.getMessage()); + + } + } + + public void setup(SourceResolver resolver, + Map objectModel, + String src, + Parameters par) throws ProcessingException, SAXException,IOException { + super.setup(resolver, objectModel, src, par); + } /** @@ -145,27 +185,35 @@ public void generate() throws IOException, SAXException, ProcessingException { String col = "/"; - this.getLogger().debug("Processing resource: " + source); + if (source.indexOf('/') != -1) col = "/" + source.substring(0, source.lastIndexOf('/')); res = source.substring(source.lastIndexOf('/') + 1); + try { - Class c = Class.forName(driver); - Database database = (Database)c.newInstance(); - DatabaseManager.registerDatabase(database); collection = DatabaseManager.getCollection(base + col); xmlResource = (XMLResource) collection.getResource(res); + if (xmlResource == null) - throw new ResourceNotFoundException("Document " + col + "/" +res + - "not found"); + throw new ResourceNotFoundException("Document " + col + "/" + res + + " not found"); + xmlResource.getContentAsSAX(this.xmlConsumer); + + collection.close(); + } catch (XMLDBException xde) { + throw new ProcessingException("Unable to fetch content: " + xde.getMessage()); - } catch (Exception e) { - this.getLogger().debug("Driver: " + driver +"/" + "Base: " + base); - throw new ProcessingException("Unable to set up XMLDB connection (NULL?): " + - e.getMessage()); - } + + } catch (NullPointerException npe) { + + this.getLogger().debug("The XML:DB driver raised an exception"); + this.getLogger().debug("probably the document was not found"); + throw new ProcessingException("Null pointer exception while " + + "retrieving document : " + npe.getMessage()); + + } } - } +} 1.24 +1 -0 xml-cocoon2/xdocs/docs-book.xml Index: docs-book.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/xdocs/docs-book.xml,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- docs-book.xml 2001/08/20 16:25:59 1.23 +++ docs-book.xml 2001/08/23 12:54:58 1.24 @@ -31,6 +31,7 @@ <hidden id="stream-generator" label="Stream Generator" source="stream-generator.xml"/> <hidden id="php-generator" label="Php Generator" source="php-generator.xml"/> <hidden id="xmldb-generator" label="XML:DB Generator" source="xmldb-generator.xml"/> + <hidden id="xmldbcollection-generator" label="XML:DB Generator" source="xmldbcollection-generator.xml"/> <!-- The transformers --> <page id="transformers" label="Transformers" source="transformers.xml"/> 1.8 +1 -0 xml-cocoon2/xdocs/generators.xml Index: generators.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/xdocs/generators.xml,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- generators.xml 2001/08/20 16:14:01 1.7 +++ generators.xml 2001/08/23 12:54:58 1.8 @@ -38,6 +38,7 @@ <li><link href="stream-generator.html">Stream Generator</link></li> <li><link href="php-generator.html">Php Generator</link> (optional)</li> <li><link href="xmldb-generator.html">XML:DB Generator</link> (optional)</li> + <li><link href="xmldbcollection-generator.html">XML:DB Collection Generator</link> (optional)</li> </ul> </s1> </body> ---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]