stefano 2003/02/17 10:27:56 Added: src/blocks/xmldb/java/apache/cocoon/components/source XMLDBSource.java XMLDBSourceFactory.java src/blocks/xmldb/java/apache/cocoon/generation XMLDBCollectionGenerator.java XMLDBGenerator.java src/blocks/xmldb/java/apache/cocoon/transformation XMLDBTransformer.java src/blocks/xmldb/lib xmldb-api-20011111.jar Log: creating xmldb block Revision Changes Path 1.1 xml-cocoon2/src/blocks/xmldb/java/apache/cocoon/components/source/XMLDBSource.java Index: XMLDBSource.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.source; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.logger.Logger; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.components.source.helpers.SourceCredential; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.xml.IncludeXMLConsumer; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import org.xmldb.api.DatabaseManager; import org.xmldb.api.base.Collection; import org.xmldb.api.base.Database; import org.xmldb.api.base.ResourceIterator; import org.xmldb.api.base.ResourceSet; import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.XMLResource; import org.xmldb.api.modules.XPathQueryService; /** * This class implements the xmldb:// pseudo-protocol and allows to get XML * content from an XML:DB enabled XML database. * * @author <a href="mailto:[EMAIL PROTECTED]">Gianugo Rabellino</a> * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> * @version CVS $Id: XMLDBSource.java,v 1.1 2003/02/17 18:27:55 stefano Exp $ */ public class XMLDBSource extends AbstractSAXSource { /** The driver implementation class */ protected String driver; /** The connection status. */ protected boolean connected = false; /** The requested URL */ protected String url; /** The supplied user */ protected String user = null; /** The supplied password */ protected String password; /** The part of URL after # sign */ protected String query = null; /** The System ID */ protected String systemId; /** Static Strings used for XML Collection representation */ protected static final String URI = "http://apache.org/cocoon/xmldb/1.0"; // FIXME (VG): Should not be this more generic? Say, "xmldb"? protected static final String PREFIX = "collection"; /** Root element <collections> */ protected static final String COLLECTIONS = "collections"; protected static final String QCOLLECTIONS = PREFIX + ":" + COLLECTIONS; protected static final String RESOURCE_COUNT_ATTR = "resources"; protected static final String COLLECTION_COUNT_ATTR = "collections"; // protected static final String COLLECTION_BASE_ATTR = "base"; /** Element <collection> */ protected static final String COLLECTION = "collection"; protected static final String QCOLLECTION = PREFIX + ":" + COLLECTION; /** Element <resource> */ protected static final String RESOURCE = "resource"; protected static final String QRESOURCE = PREFIX + ":" + RESOURCE; protected static final String NAME_ATTR = "name"; /** Root element <results> */ protected static final String RESULTSET = "results"; protected static final String QRESULTSET = PREFIX + ":" + RESULTSET; protected static final String QUERY_ATTR = "query"; protected static final String RESULTS_COUNT_ATTR = "resources"; /** Element <result> */ protected static final String RESULT = "result"; protected static final String QRESULT = PREFIX + ":" + RESULT; protected static final String RESULT_DOCID_ATTR = "docid"; protected static final String RESULT_ID_ATTR = "id"; protected static final String CDATA = "CDATA"; /** * The constructor. * * @param environment the Cocoon Environment. * @param url the URL being queried. * @param driver the XML:DB driver class name. */ public XMLDBSource(Environment environment, ComponentManager manager, Logger logger, String driver, SourceCredential credential, String url) { super(environment, manager, logger); int start; this.driver = driver; this.user = credential.getPrincipal(); this.password = credential.getPassword(); if ((start = url.indexOf('#')) != -1) { this.url = url.substring(0, start); this.query = url.substring(start + 1); } else { this.url = url; } } /** * Initialize the XML:DB connection. * */ public void connect() throws ProcessingException { if (log.isDebugEnabled()) { this.log.debug("Initializing XML:DB connection, using driver " + driver); } try { Class c = Class.forName(driver); DatabaseManager.registerDatabase((Database)c.newInstance()); } catch (XMLDBException xde) { String error = "Unable to connect to the XMLDB database. Error " + xde.errorCode + ": " + xde.getMessage(); this.log.debug(error, xde); throw new ProcessingException(error, xde); } catch (Exception e) { throw new ProcessingException("Problem setting up the connection to XML:DB: " + e.getMessage() + ". Make sure that your driver is available.", e); } this.connected = true; } /** * Stream SAX events to a given ContentHandler. If the requested * resource is a collection, build an XML view of it. * */ public void toSAX(ContentHandler handler) throws SAXException, ProcessingException { if (!connected) { this.connect(); } if (url.endsWith("/")) this.collectionToSAX(handler); else this.resourceToSAX(handler); } private void resourceToSAX(ContentHandler handler) throws SAXException, ProcessingException { final String col = url.substring(0, url.lastIndexOf('/')); final String res = url.substring(url.lastIndexOf('/') + 1); try { Collection collection = DatabaseManager.getCollection(col, user, password); if (collection == null) { throw new ResourceNotFoundException("Document " + url + " not found"); } XMLResource xmlResource = (XMLResource) collection.getResource(res); if (xmlResource == null) { throw new ResourceNotFoundException("Document " + url + " not found"); } if (query != null) { // Query resource if (log.isDebugEnabled()) { this.log.debug("Querying resource " + res + " from collection " + url + "; query= " + this.query); } queryToSAX(handler, collection, res); } else { // Return entire resource if (log.isDebugEnabled()) { this.log.debug("Obtaining resource " + res + " from collection " + col); } xmlResource.getContentAsSAX(handler); } collection.close(); } catch (XMLDBException xde) { String error = "Unable to fetch content. Error " + xde.errorCode + ": " + xde.getMessage(); throw new SAXException(error, xde); } } private void collectionToSAX(ContentHandler handler) throws SAXException, ProcessingException { AttributesImpl attributes = new AttributesImpl(); try { Collection collection = DatabaseManager.getCollection(url, user, password); if (collection == null) { throw new ResourceNotFoundException("Collection " + url + " not found"); } if (query != null) { // Query collection if (log.isDebugEnabled()) { this.log.debug("Querying collection " + url + "; query= " + this.query); } queryToSAX(handler, collection, null); } else { // List collection if (log.isDebugEnabled()) { this.log.debug("Listing collection " + url); } final String ncollections = Integer.toString(collection.getChildCollectionCount()); final String nresources = Integer.toString(collection.getResourceCount()); attributes.addAttribute("", RESOURCE_COUNT_ATTR, RESOURCE_COUNT_ATTR, "CDATA", nresources); attributes.addAttribute("", COLLECTION_COUNT_ATTR, COLLECTION_COUNT_ATTR, "CDATA", ncollections); // attributes.addAttribute("", COLLECTION_BASE_ATTR, // COLLECTION_BASE_ATTR, "CDATA", url); handler.startDocument(); handler.startPrefixMapping(PREFIX, URI); handler.startElement(URI, COLLECTIONS, QCOLLECTIONS, attributes); // Print child collections String[] collections = collection.listChildCollections(); for (int i = 0; i < collections.length; i++) { attributes.clear(); attributes.addAttribute("", NAME_ATTR, NAME_ATTR, CDATA, collections[i]); handler.startElement(URI, COLLECTION, QCOLLECTION, attributes); handler.endElement(URI, COLLECTION, COLLECTION); } // Print child resources String[] resources = collection.listResources(); for (int i = 0; i < resources.length; i++) { attributes.clear(); attributes.addAttribute("", NAME_ATTR, NAME_ATTR, CDATA, resources[i]); handler.startElement(URI, RESOURCE, QRESOURCE, attributes); handler.endElement(URI, RESOURCE, RESOURCE); } handler.endElement(URI, COLLECTIONS, QCOLLECTIONS); handler.endPrefixMapping(PREFIX); handler.endDocument(); } collection.close(); } catch (XMLDBException xde) { String error = "Collection listing failed. Error " + xde.errorCode + ": " + xde.getMessage(); throw new SAXException(error, xde); } } private void queryToSAX(ContentHandler handler, Collection collection, String resource) throws SAXException { AttributesImpl attributes = new AttributesImpl(); try { XPathQueryService service = (XPathQueryService) collection.getService("XPathQueryService", "1.0"); ResourceSet resultSet = (resource == null) ? service.query(query) : service.queryResource(resource, query); attributes.addAttribute("", QUERY_ATTR, QUERY_ATTR, "CDATA", query); attributes.addAttribute("", RESULTS_COUNT_ATTR, RESULTS_COUNT_ATTR, "CDATA", Long.toString(resultSet.getSize())); handler.startDocument(); handler.startPrefixMapping(PREFIX, URI); handler.startElement(URI, RESULTSET, QRESULTSET, attributes); IncludeXMLConsumer includeHandler = new IncludeXMLConsumer(handler); // Print search results ResourceIterator results = resultSet.getIterator(); while (results.hasMoreResources()) { XMLResource result = (XMLResource)results.nextResource(); final String id = result.getId(); final String documentId = result.getDocumentId(); attributes.clear(); if (id != null) { attributes.addAttribute("", RESULT_ID_ATTR, RESULT_ID_ATTR, CDATA, id); } if (documentId != null) { attributes.addAttribute("", RESULT_DOCID_ATTR, RESULT_DOCID_ATTR, CDATA, documentId); } handler.startElement(URI, RESULT, QRESULT, attributes); result.getContentAsSAX(includeHandler); handler.endElement(URI, RESULT, RESULT); } handler.endElement(URI, RESULTSET, QRESULTSET); handler.endPrefixMapping(PREFIX); handler.endDocument(); } catch (XMLDBException xde) { String error = "Query failed. Error " + xde.errorCode + ": " + xde.getMessage(); throw new SAXException(error, xde); } } public void recycle() { this.driver = null; this.log = null; this.manager = null; this.url = null; this.query = null; } public String getSystemId() { return url; } } 1.1 xml-cocoon2/src/blocks/xmldb/java/apache/cocoon/components/source/XMLDBSourceFactory.java Index: XMLDBSourceFactory.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.components.source; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.source.helpers.SourceCredential; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.Source; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; /** * This class implements the xmldb:// pseudo-protocol and allows to get XML * content from an XML:DB enabled XML database. * * @author <a href="mailto:[EMAIL PROTECTED]">Gianugo Rabellino</a> * @version CVS $Id: XMLDBSourceFactory.java,v 1.1 2003/02/17 18:27:55 stefano Exp $ */ public final class XMLDBSourceFactory extends AbstractLogEnabled implements SourceFactory, Configurable, Composable { /** The driver implementation class */ protected String driver; /** The authentication info */ protected SourceCredential credential; /** The Component Manager class */ protected ComponentManager m_manager; /** A Map containing the driver list */ protected HashMap driverMap; /** A Map containing the authentication credentials */ protected HashMap credentialMap; /** * Configure the instance. */ public void configure(final Configuration conf) throws ConfigurationException { driverMap = new HashMap(); credentialMap = new HashMap(); Configuration[] xmldbConfigs = conf.getChildren("driver"); for (int i = 0; i < xmldbConfigs.length; i++) { SourceCredential credential = new SourceCredential(null, null); driverMap.put(xmldbConfigs[i].getAttribute("type"), xmldbConfigs[i].getAttribute("class")); credential.setPrincipal(xmldbConfigs[i].getAttribute("user", null)); credential.setPassword(xmldbConfigs[i].getAttribute("password", null)); credentialMap.put(xmldbConfigs[i].getAttribute("type"), credential); } } /** * Compose this Composable object. We need to pass on the * ComponentManager to the actual Source. */ public void compose(ComponentManager cm) { this.m_manager = cm; } /** * Resolve the source */ public Source getSource(Environment environment, String location) throws ProcessingException, IOException, MalformedURLException { int start = location.indexOf(':') + 1; int end = location.indexOf(':', start); if (start == -1 || end == -1) { throw new MalformedURLException("Mispelled XML:DB URL. " + "The syntax is \"xmldb:databasetype://host/collection/resource\""); } String type = location.substring(start, end); driver = (String)driverMap.get(type); credential = (SourceCredential)credentialMap.get(type); if (driver == null) { throw new ProcessingException("Unable to find a driver for the \"" + type + " \" database type, please check the configuration"); } return new XMLDBSource(environment, m_manager, this.getLogger(), driver, credential, location); } /** * Resolve the source */ public Source getSource(Environment environment, URL base, String location) throws ProcessingException, IOException, MalformedURLException { return getSource(environment, base.toExternalForm() + location); } } 1.1 xml-cocoon2/src/blocks/xmldb/java/apache/cocoon/generation/XMLDBCollectionGenerator.java Index: XMLDBCollectionGenerator.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.generation; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.caching.CacheableProcessingComponent; import org.apache.cocoon.environment.SourceResolver; import org.apache.excalibur.source.SourceValidity; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import org.xmldb.api.DatabaseManager; import org.xmldb.api.base.Collection; import org.xmldb.api.base.Database; import org.xmldb.api.base.XMLDBException; import java.io.IOException; import java.util.Map; /** * This class implements generation of a XML:DB collection * contents as a directory listing. * * <pre> * <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 * slash in the base tag is important! * * @author <a href="mailto:[EMAIL PROTECTED]">Gianugo Rabellino</a> * @version CVS $Id: XMLDBCollectionGenerator.java,v 1.1 2003/02/17 18:27:55 stefano Exp $ * @deprecated Use the XML:DB pseudo protocol instead. */ public class XMLDBCollectionGenerator extends ComposerGenerator implements CacheableProcessingComponent, Configurable,Initializable { protected static final String URI = "http://apache.org/cocoon/xmldb/1.0"; protected static final String PREFIX = "collection"; protected static final String RESOURCE_COUNT_ATTR = "resources"; protected static final String COLLECTION_COUNT_ATTR = "collections"; protected static final String COLLECTION = "collection"; protected static final String QCOLLECTION = PREFIX + ":collection"; protected static final String RESOURCE = "resource"; protected static final String QRESOURCE = PREFIX + ":resource"; protected String driver; protected String base; protected String col; protected Database database; protected Collection collection; protected final AttributesImpl attributes = new AttributesImpl(); public void compose(ComponentManager manager) throws ComponentException { super.compose(manager); } /** * Recycle the component, keep only the configuration variables * and the database instance for reuse. */ public void recycle() { super.recycle(); this.col = null; this.collection = null; } /** * Configure the component. This class is expecting a configuration * like the following one: * <pre> * <driver>org.dbxml.client.xmldb.DatabaseImpl</driver> * <base>xmldb:dbxml:///db/</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 * slash in the base tag is important! * * @exception ConfigurationException (configuration invalid or missing) */ public void configure(Configuration conf) throws ConfigurationException { this.driver = conf.getChild("driver").getValue(); this.base = conf.getChild("base").getValue(); } /** * Initialize the component getting a database instance. * * @exception Exception if an error occurs */ public void initialize() throws Exception { try { Class c = Class.forName(driver); database = (Database)c.newInstance(); DatabaseManager.registerDatabase(database); } catch (XMLDBException xde) { this.getLogger().error("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().error("There was a problem setting up the connection"); this.getLogger().error("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); } /** * The component isn't cached (yet) */ public SourceValidity getValidity() { return null; } /** * The component isn't cached (yet) */ public SourceValidity generateValidity() { return null; } /** * The component isn't cached (yet) */ public java.io.Serializable generateKey() { return null; } /** * Parse the requested URI, connect to the XML:DB database * and fetch the requested resource. * * @exception ProcessingException something unexpected happened with the DB */ public void generate() throws IOException, SAXException, ProcessingException { //String col = "/"; //if (source.indexOf('/') != -1) col = source; try { collection = DatabaseManager.getCollection(base + col); if (collection == null) { throw new ResourceNotFoundException("Collection " + col + " not found"); } collectionToSAX(collection); collection.close(); } catch (XMLDBException xde) { throw new ProcessingException("Unable to fetch content '" + source + "':" + xde.getMessage()); } catch (NullPointerException npe) { this.getLogger().error("The XML:DB driver raised an exception"); this.getLogger().error("probably the document was not found"); throw new ProcessingException("Null pointer exception while " + "retrieving document : " + npe.getMessage()); } } /** * Output SAX events listing the collection. * * @exception SAXException */ public void collectionToSAX(Collection collection) throws SAXException { String ncollections; String nresources; String[] resources; String[] collections; try { ncollections = Integer.toString(collection.getChildCollectionCount()); nresources = Integer.toString(collection.getResourceCount()); attributes.clear(); attributes.addAttribute("", RESOURCE_COUNT_ATTR, RESOURCE_COUNT_ATTR, "CDATA", nresources); attributes.addAttribute("", COLLECTION_COUNT_ATTR, COLLECTION_COUNT_ATTR, "CDATA", ncollections); collections = collection.listChildCollections(); resources = collection.listResources(); this.xmlConsumer.startDocument(); this.xmlConsumer.startPrefixMapping(PREFIX, URI); this.xmlConsumer.startElement(URI, "collections", "collection:collections", attributes); // Print child collections for (int i = 0; i < collections.length; i++) { attributes.clear(); attributes.addAttribute("", "name", "name", "CDATA", collections[i]); this.xmlConsumer.startElement(URI, COLLECTION, QCOLLECTION, attributes); this.xmlConsumer.endElement(URI, COLLECTION, COLLECTION); } // Print child resources for (int i = 0; i < resources.length; i++) { attributes.clear(); attributes.addAttribute("", "name", "name", "CDATA", resources[i]); this.xmlConsumer.startElement(URI, RESOURCE, QRESOURCE, attributes); this.xmlConsumer.endElement(URI, RESOURCE, RESOURCE); } this.xmlConsumer.endElement(URI, "collections", "collection:collections"); this.xmlConsumer.endPrefixMapping(PREFIX); this.xmlConsumer.endDocument(); } catch (XMLDBException xde) { this.getLogger().warn("Collection listing failed" + xde.getMessage()); throw new SAXException("Collection listing failed" + xde.getMessage()); } } } 1.1 xml-cocoon2/src/blocks/xmldb/java/apache/cocoon/generation/XMLDBGenerator.java Index: XMLDBGenerator.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.generation; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.caching.CacheableProcessingComponent; import org.apache.cocoon.environment.SourceResolver; import org.apache.excalibur.source.SourceValidity; import org.xml.sax.SAXException; import org.xmldb.api.DatabaseManager; import org.xmldb.api.base.Collection; import org.xmldb.api.base.Database; import org.xmldb.api.base.XMLDBException; import org.xmldb.api.modules.XMLResource; import java.io.IOException; import java.util.Map; /** * This class implements generation of XML documents from a * 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> * </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 * slash in the base tag is important! * * @author <a href="mailto:[EMAIL PROTECTED]">Gianugo Rabellino</a> * @version CVS $Id: XMLDBGenerator.java,v 1.1 2003/02/17 18:27:55 stefano Exp $ * @deprecated Use the XML:DB pseudo protocol instead. */ public class XMLDBGenerator extends ComposerGenerator implements CacheableProcessingComponent, Configurable,Initializable { protected String driver; protected String base; protected String col; protected String res; protected Database database; protected Collection collection; protected XMLResource xmlResource; public void compose(ComponentManager manager) throws ComponentException { super.compose(manager); } /** * Recycle the component, keep only the configuration variables * and the database instance for reuse. */ public void recycle() { super.recycle(); this.col = null; this.res = null; this.xmlResource = null; this.collection = null; } /** * Configure the component. This class is expecting a configuration * like the following one: * <pre> * <driver>org.dbxml.client.xmldb.DatabaseImpl</driver> * <base>xmldb:dbxml:///db/</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 * slash in the base tag is important! * * @exception ConfigurationException (configuration invalid or missing) */ public void configure(Configuration conf) throws ConfigurationException { this.driver = conf.getChild("driver").getValue(); this.base = conf.getChild("base").getValue(); } /** * Initialize the component getting a database instance. * * @exception Exception if an error occurs */ public void initialize() throws Exception { try { Class c = Class.forName(driver); database = (Database)c.newInstance(); DatabaseManager.registerDatabase(database); } catch (XMLDBException xde) { this.getLogger().error("Unable to connect to the XML:DB database"); throw new ProcessingException("Unable to connect to the XMLDB database: " + xde.getMessage()); } catch (Exception e) { this.getLogger().error("There was a problem setting up the connection"); this.getLogger().error("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); } /** * The component isn't cached (yet) */ public SourceValidity getValidity() { return null; } /** * The component isn't cached (yet) */ public SourceValidity generateValidity() { return null; } /** * The component isn't cached (yet) */ public java.io.Serializable generateKey() { return null; } /** * Parse the requested URI, connect to the XML:DB database * and fetch the requested resource. * * @exception ProcessingException something unexpected happened with the DB */ public void generate() throws IOException, SAXException, ProcessingException { String col = "/"; if (source.indexOf('/') != -1) col = "/" + source.substring(0, source.lastIndexOf('/')); res = source.substring(source.lastIndexOf('/') + 1); try { collection = DatabaseManager.getCollection(base + col); xmlResource = (XMLResource) collection.getResource(res); if (xmlResource == null) { 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 (NullPointerException npe) { this.getLogger().error("The XML:DB driver raised an exception"); this.getLogger().error("probably the document was not found"); throw new ProcessingException("Null pointer exception while " + "retrieving document : " + npe.getMessage()); } } } 1.1 xml-cocoon2/src/blocks/xmldb/java/apache/cocoon/transformation/XMLDBTransformer.java Index: XMLDBTransformer.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.transformation; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.cocoon.util.TraxErrorHandler; //import org.apache.cocoon.caching.CacheValidity; //import org.apache.cocoon.caching.Cacheable; import org.apache.cocoon.caching.CacheableProcessingComponent; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.ResourceNotFoundException; import org.apache.excalibur.source.SourceValidity; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import org.xmldb.api.base.Database; import org.xmldb.api.base.Resource; import org.xmldb.api.base.Collection; import org.xmldb.api.base.XMLDBException; import org.xmldb.api.DatabaseManager; import org.xmldb.api.modules.XUpdateQueryService; import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.TransformerFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.TransformerConfigurationException; import java.io.IOException; import java.io.Serializable; import java.io.StringWriter; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Properties; /** * This transformer allows to perform resource creation, deletion, and * XUpdate command execution in XML:DB. * * <p>Definition:</p> * <pre> * <map:transformer name="xmldb" src="www.XMLDBTransformer"> * <driver>org.apache.xindice.client.xmldb.DatabaseImpl</driver> * <base>xmldb:xindice:///db/collection</base> * </map:transformer> * </pre> * * <p>Invokation:</p> * <pre> * <map:transform type="xmldb"> * <map:parameter name="base" value="xmldb:xindice:///db/collection"/> * </map:transform> * </pre> * * <p>Input XML document example:</p> * <pre> * <page xmlns:xindice="http://apache.org/cocoon/xmldb/1.0"> * ... * <xindice:query type="create" oid="xmldb-object-id"> * <page> * XML Object body * </page> * </xindice:query> * * <xindice:query type="delete" oid="xmldb-object-id"/> * * <xindice:query type="update" oid="xmldb-object-id"> * <xu:modifications version="1.0" xmlns:xu="http://www.xmldb.org/xupdate"> * <xu:remove select="/person/phone[@type = 'home']"/> * <xu:update select="/person/phone[@type = 'work']"> * 480-300-3003 * </xu:update> * </xu:modifications> * </xindice:query> * ... * </page> * </pre> * * <p>Output XML document example:</p> * <pre> * <page xmlns:xindice="http://apache.org/cocoon/xmldb/1.0"> * ... * <xindice:query type="create" oid="xmldb-object-id" result="success"/> * * <xindice:query type="delete" oid="xmldb-object-id" result="success"/> * * <xindice:query type="update" oid="xmldb-object-id" result="failure"> * Resource xmldb-object-id is not found * </xindice:query> * ... * </page> * </pre> * * <p>Known bugs and limitations:</p> * <ul> * <li>No namespaces with Xalan (see AbstractTextSerializer)</li> * </ul> * * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a> * @version CVS $Id: XMLDBTransformer.java,v 1.1 2003/02/17 18:27:56 stefano Exp $ */ public class XMLDBTransformer extends AbstractTransformer implements Disposable, CacheableProcessingComponent, Configurable, Initializable { private static String XMLDB_URI = "http://apache.org/cocoon/xmldb/1.0"; private static String XMLDB_QUERY_ELEMENT = "query"; private static String XMLDB_QUERY_TYPE_ATTRIBUTE = "type"; private static String XMLDB_QUERY_OID_ATTRIBUTE = "oid"; private static String XMLDB_QUERY_RESULT_ATTRIBUTE = "result"; /** The trax <code>TransformerFactory</code> used by this transformer. */ private SAXTransformerFactory tfactory = null; private Properties format = new Properties(); /** The map of namespace prefixes. */ private Map prefixMap = new HashMap(); /** XML:DB driver class name. */ private String driver = null; /** Default collection name. */ private String default_base = null; /** Current collection name. */ private String base = null; /** Current collection. */ private Collection collection; /** Operation. One of: create, delete, update. */ private String operation; /** Document ID. Can be null if update is performed on collection. */ private String key; private StringWriter queryWriter; private TransformerHandler queryHandler; /** True when inside <query> element. */ private boolean processing; public XMLDBTransformer() { format.put(OutputKeys.ENCODING, "utf-8"); format.put(OutputKeys.INDENT, "no"); format.put(OutputKeys.OMIT_XML_DECLARATION, "yes"); } public void configure(Configuration configuration) throws ConfigurationException { Configuration driver = configuration.getChild("driver"); if (driver == null || driver.getValue() == null) throw new ConfigurationException("Required driver parameter is missing."); this.driver = driver.getValue(); Configuration default_base = configuration.getChild("base"); if (default_base != null) this.default_base = default_base.getValue(); } /** * Initializes XML:DB database instance using specified driver class. */ public void initialize() throws Exception { Class c = Class.forName(driver); Database database = (Database)c.newInstance(); DatabaseManager.registerDatabase(database); } /** Setup the transformer. */ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { this.base = par.getParameter("base", this.default_base); if (this.base == null) throw new ProcessingException("Required base parameter is missing. Syntax is: xmldb:xindice:///db/collection"); try { this.collection = DatabaseManager.getCollection(base); } catch (XMLDBException e) { throw new ProcessingException("Could not get collection " + base + ": " + e.errorCode, e); } if(this.collection == null) throw new ResourceNotFoundException("Collection " + base + " does not exist"); } /** * Helper for TransformerFactory. */ protected SAXTransformerFactory getTransformerFactory() { if(tfactory == null) { tfactory = (SAXTransformerFactory) TransformerFactory.newInstance(); tfactory.setErrorListener(new TraxErrorHandler(getLogger())); } return tfactory; } /** * Generate the unique key. * This key must be unique inside the space of this component. * This method must be invoked before the generateValidity() method. * * @return The generated key or <code>null</code> if the component * is currently not cacheable. */ public Serializable generateKey() { return null; } /** * Generate the validity object. * Before this method can be invoked the generateKey() method * must be invoked. * * @return The generated validity object or <code>null</code> if the * component is currently not cacheable. */ public SourceValidity generateValidity() { return null; } /** * Receive notification of the beginning of a document. */ public void startDocument() throws SAXException { super.startDocument(); } /** * Receive notification of the end of a document. */ public void endDocument() throws SAXException { super.endDocument(); } /** * Begin the scope of a prefix-URI Namespace mapping. * * @param prefix The Namespace prefix being declared. * @param uri The Namespace URI the prefix is mapped to. */ public void startPrefixMapping(String prefix, String uri) throws SAXException { if (!processing) { super.startPrefixMapping(prefix,uri); prefixMap.put(prefix,uri); } else if (this.queryHandler != null){ this.queryHandler.startPrefixMapping(prefix, uri); } } /** * End the scope of a prefix-URI mapping. * * @param prefix The prefix that was being mapping. */ public void endPrefixMapping(String prefix) throws SAXException { if (!processing) { super.endPrefixMapping(prefix); prefixMap.remove(prefix); } else if (this.queryHandler != null){ this.queryHandler.endPrefixMapping(prefix); } } /** * Receive notification of the beginning of an element. * * @param uri The Namespace URI, or the empty string if the element has no * Namespace URI or if Namespace * processing is not being performed. * @param loc The local name (without prefix), or the empty string if * Namespace processing is not being performed. * @param raw The raw XML 1.0 name (with prefix), or the empty string if * raw names are not available. * @param a The attributes attached to the element. If there are no * attributes, it shall be an empty Attributes object. */ public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException { if (!processing) { if (XMLDB_URI.equals(uri) && XMLDB_QUERY_ELEMENT.equals(loc)){ this.operation = a.getValue(XMLDB_QUERY_TYPE_ATTRIBUTE); if(!"create".equals(operation) && !"delete".equals(operation) && !"update".equals(operation)) { throw new SAXException("Supported operation types are: create, delete"); } this.key = a.getValue(XMLDB_QUERY_OID_ATTRIBUTE); if(!"update".equals(operation) && this.key == null) { throw new SAXException("Object ID is missing in xmldb element"); } processing = true; if (!"delete".equals(operation)) { // Prepare SAX query writer queryWriter = new StringWriter(256); try { this.queryHandler = getTransformerFactory().newTransformerHandler(); this.queryHandler.setResult(new StreamResult(queryWriter)); this.queryHandler.getTransformer().setOutputProperties(format); } catch (TransformerConfigurationException e) { throw new SAXException("Failed to get transformer handler", e); } // Start query document this.queryHandler.startDocument(); Iterator itt = prefixMap.entrySet().iterator(); while ( itt.hasNext() ) { Map.Entry entry = (Map.Entry)itt.next(); this.queryHandler.startPrefixMapping((String)entry.getKey(), (String)entry.getValue()); } } } else { super.startElement(uri,loc,raw,a); } } else if (this.queryHandler != null){ this.queryHandler.startElement(uri,loc,raw,a); } } /** * Receive notification of the end of an element. * * @param uri The Namespace URI, or the empty string if the element has no * Namespace URI or if Namespace * processing is not being performed. * @param loc The local name (without prefix), or the empty string if * Namespace processing is not being performed. * @param raw The raw XML 1.0 name (with prefix), or the empty string if * raw names are not available. */ public void endElement(String uri, String loc, String raw) throws SAXException { if (!processing) { super.endElement(uri,loc,raw); } else { if (XMLDB_URI.equals(uri) && XMLDB_QUERY_ELEMENT.equals(loc)){ processing = false; String document = null; if (this.queryHandler != null){ // Finish building query. Remove existing prefix mappings. Iterator itt = prefixMap.entrySet().iterator(); while ( itt.hasNext() ) { Map.Entry entry = (Map.Entry) itt.next(); this.queryHandler.endPrefixMapping((String)entry.getKey()); } this.queryHandler.endDocument(); document = this.queryWriter.toString(); } // Perform operation String result = "failure"; String message = null; if("create".equals(operation)) { try { Resource resource = collection.createResource(key, "XMLResource"); resource.setContent(document); collection.storeResource(resource); result = "success"; } catch (XMLDBException e) { message = "Failed to create resource " + key + ": " + e.errorCode; getLogger().debug(message, e); } } else if("delete".equals(operation)) { try { Resource resource = collection.getResource(this.key); if (resource == null) { message = "Resource " + this.key + " does not exist"; getLogger().debug(message); } else { collection.removeResource(resource); result = "success"; } } catch (XMLDBException e) { message = "Failed to delete resource " + key + ": " + e.errorCode; getLogger().debug(message, e); } } else if("update".equals(operation)) { try { XUpdateQueryService service = (XUpdateQueryService) collection.getService("XUpdateQueryService", "1.0"); long count = (this.key == null)? service.update(document) : service.updateResource(this.key, document); message = count + " entries updated."; result = "success"; } catch (XMLDBException e) { message = "Failed to update resource " + key + ": " + e.errorCode; getLogger().debug(message, e); } } // Report result AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(null, XMLDB_QUERY_OID_ATTRIBUTE, XMLDB_QUERY_OID_ATTRIBUTE, "CDATA", this.key); attrs.addAttribute(null, XMLDB_QUERY_TYPE_ATTRIBUTE, XMLDB_QUERY_TYPE_ATTRIBUTE, "CDATA", this.operation); attrs.addAttribute(null, XMLDB_QUERY_RESULT_ATTRIBUTE, XMLDB_QUERY_RESULT_ATTRIBUTE, "CDATA", result); super.startElement(uri, loc, raw, attrs); if (message != null) { super.characters(message.toCharArray(), 0, message.length()); } super.endElement(uri, loc, raw); } else if (this.queryHandler != null){ this.queryHandler.endElement(uri, loc, raw); } } } /** * Receive notification of character data. * * @param c The characters from the XML document. * @param start The start position in the array. * @param len The number of characters to read from the array. */ public void characters(char c[], int start, int len) throws SAXException { if (!processing) { super.characters(c,start,len); } else if (this.queryHandler != null){ this.queryHandler.characters(c,start,len); } } /** * Receive notification of ignorable whitespace in element content. * * @param c The characters from the XML document. * @param start The start position in the array. * @param len The number of characters to read from the array. */ public void ignorableWhitespace(char c[], int start, int len) throws SAXException { if (!processing) { super.ignorableWhitespace(c,start,len); } else if (this.queryHandler != null){ this.queryHandler.ignorableWhitespace(c,start,len); } } /** * Receive notification of a processing instruction. * * @param target The processing instruction target. * @param data The processing instruction data, or null if none was * supplied. */ public void processingInstruction(String target, String data) throws SAXException { if (!processing) { super.processingInstruction(target,data); } else if (this.queryHandler != null){ this.queryHandler.processingInstruction(target,data); } } /** * Receive notification of a skipped entity. * * @param name The name of the skipped entity. If it is a parameter * entity, the name will begin with '%'. */ public void skippedEntity(String name) throws SAXException { if (!processing) { super.skippedEntity(name); } else if (this.queryHandler != null){ this.queryHandler.skippedEntity(name); } } /** * Report the start of DTD declarations, if any. * * @param name The document type name. * @param publicId The declared public identifier for the external DTD * subset, or null if none was declared. * @param systemId The declared system identifier for the external DTD * subset, or null if none was declared. */ public void startDTD(String name, String publicId, String systemId) throws SAXException { if (!processing) { super.startDTD(name,publicId,systemId); } else { throw new SAXException( "Recieved startDTD after beginning SVG extraction process." ); } } /** * Report the end of DTD declarations. */ public void endDTD() throws SAXException { if (!processing) { super.endDTD(); } else { throw new SAXException("Recieved endDTD after xmldb element."); } } /** * Report the beginning of an entity. * * @param name The name of the entity. If it is a parameter entity, the * name will begin with '%'. */ public void startEntity(String name) throws SAXException { if (!processing) { super.startEntity(name); } else if (this.queryHandler != null){ this.queryHandler.startEntity(name); } } /** * Report the end of an entity. * * @param name The name of the entity that is ending. */ public void endEntity(String name) throws SAXException { if (!processing) { super.endEntity(name); } else if (this.queryHandler != null){ this.queryHandler.endEntity(name); } } /** * Report the start of a CDATA section. */ public void startCDATA() throws SAXException { if (!processing) { super.startCDATA(); } else if (this.queryHandler != null){ this.queryHandler.startCDATA(); } } /** * Report the end of a CDATA section. */ public void endCDATA() throws SAXException { if (!processing) { super.endCDATA(); } else if (this.queryHandler != null){ this.queryHandler.endCDATA(); } } /** * Report an XML comment anywhere in the document. * * @param ch An array holding the characters in the comment. * @param start The starting position in the array. * @param len The number of characters to use from the array. */ public void comment(char ch[], int start, int len) throws SAXException { if (!processing) { super.comment(ch,start,len); } else if (this.queryHandler != null){ this.queryHandler.comment(ch,start,len); } } public void recycle() { this.prefixMap.clear(); this.queryHandler = null; this.queryWriter = null; try { if (collection != null) collection.close(); } catch (XMLDBException e) { getLogger().error("Failed to close collection " + base + ". Error " + e.errorCode, e); } collection = null; } /** * dispose */ public void dispose() { } } 1.1 xml-cocoon2/src/blocks/xmldb/lib/xmldb-api-20011111.jar <<Binary file>>
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]