cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r369503 - in /cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon: acting/DbXMLAuthenticatorAction.java generation/XMLDBCollectionGenerator.java generation/XMLDBGenerator.java transformation/XMLDBTransformer.java
Date Mon, 16 Jan 2006 16:02:03 GMT
Author: jbq
Date: Mon Jan 16 08:01:55 2006
New Revision: 369503

URL: http://svn.apache.org/viewcvs?rev=369503&view=rev
Log:
Merging the xmldb block with branch 2.1

Added:
    cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
  (with props)
    cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBGenerator.java
  (with props)
Modified:
    cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/acting/DbXMLAuthenticatorAction.java
    cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/transformation/XMLDBTransformer.java

Modified: cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/acting/DbXMLAuthenticatorAction.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/acting/DbXMLAuthenticatorAction.java?rev=369503&r1=369502&r2=369503&view=diff
==============================================================================
--- cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/acting/DbXMLAuthenticatorAction.java
(original)
+++ cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/acting/DbXMLAuthenticatorAction.java
Mon Jan 16 08:01:55 2006
@@ -252,42 +252,31 @@
     getLogger ().debug ("DBXMLAUTH: query is: " + query);
 
 
-    Collection col = CreateConnection( conf );
+    Collection col = CreateConnection(conf);
 
-    if ( col != null )
-    {
-      if ( col.isOpen() )
-      {
-
-        try
-        {
+    if (col != null) {
+      if (col.isOpen()) {
+        try {
           XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService",
"1.0");
 
           rs = service.query(query);
           ResourceIterator results = rs.getIterator();
 
-          if (results.hasMoreResources() == false)
-          {
+          if (results.hasMoreResources() == false) {
               getLogger ().debug ("DBXMLAUTH: auth failed");
               return null;
           } else {
             getLogger ().debug ("DBXMLAUTH: auth OK");
             return rs;
           }
-
         } catch (XMLDBException e) {
-
           getLogger ().debug ("DBXMLAUTH: got exception: " + e);
           return null;
-
         } finally {
-
           // close col
-          if (col != null) {
-            try {
-              col.close();
-            } catch (Exception e) { /* ignore */ }
-          }
+          try {
+            col.close();
+          } catch (Exception e) { /* ignore */ }
           getLogger ().debug ("DBXMLAUTH: collection closed");
 
         }

Added: cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java?rev=369503&view=auto
==============================================================================
--- cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
(added)
+++ cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
Mon Jan 16 08:01:55 2006
@@ -0,0 +1,252 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.generation;
+
+import org.apache.avalon.framework.activity.Initializable;
+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.cocoon.util.Deprecation;
+
+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>
+ * &lt;driver&gt;
+ *   (a valid DB:XML compliant driver)
+ * &lt;/driver&gt;
+ * &lt;base&gt;
+ *   xmldb:yourdriver://host/an/optional/path/to/be/prepended
+ * &lt;/base&gt;
+ * </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:gianugo@rabellino.it">Gianugo Rabellino</a>
+ * @version CVS $Id$
+ * @deprecated Use the XML:DB pseudo protocol instead.
+ */
+public class XMLDBCollectionGenerator extends ServiceableGenerator
+        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();
+
+    /**
+     * 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>
+    * &lt;driver&gt;org.dbxml.client.xmldb.DatabaseImpl&lt;/driver&gt;
+    * &lt;base&gt;xmldb:dbxml:///db/&lt;/base&gt;
+    * </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) {
+           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) {
+           getLogger().error("There was a problem setting up the connection");
+           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 {
+        Deprecation.logger.warn("The XMLDBCollectionGenerator is deprecated. Use the XML:DB
pseudo protocol instead");
+        super.setup(resolver, objectModel, src, par);
+    }
+
+    /**
+     * The component isn't cached (yet)
+     */
+    public SourceValidity getValidity() {
+        return null;
+    }
+
+    /**
+     * The component isn't cached (yet)
+     */
+    public java.io.Serializable getKey() {
+        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) {
+            getLogger().error("The XML:DB driver raised an exception");
+            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) {
+            getLogger().warn("Collection listing failed: " + xde.getMessage());
+            throw new SAXException("Collection listing failed: " + xde.getMessage());
+        }
+    }
+}

Propchange: cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBCollectionGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBGenerator.java?rev=369503&view=auto
==============================================================================
--- cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBGenerator.java
(added)
+++ cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBGenerator.java
Mon Jan 16 08:01:55 2006
@@ -0,0 +1,184 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.generation;
+
+import org.apache.avalon.framework.activity.Initializable;
+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.cocoon.util.Deprecation;
+
+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>
+ * &lt;driver&gt;
+ *   (a valid DB:XML compliant driver)
+ * &lt;/driver&gt;
+ * &lt;base&gt;
+ *   xmldb:yourdriver://host/an/optional/path/to/be/prepended
+ * &lt;/base&gt;
+ * </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:gianugo@rabellino.it">Gianugo Rabellino</a>
+ * @version CVS $Id$
+ * @deprecated Use the XML:DB pseudo protocol instead.
+ */
+public class XMLDBGenerator extends ServiceableGenerator
+        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;
+
+    /**
+     * 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>
+     * &lt;driver&gt;org.dbxml.client.xmldb.DatabaseImpl&lt;/driver&gt;
+     * &lt;base&gt;xmldb:dbxml:///db/&lt;/base&gt;
+     * </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) {
+            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) {
+            getLogger().error("There was a problem setting up the connection");
+            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 {
+        Deprecation.logger.warn("The XMLDBGenerator is deprecated. Use the XML:DB pseudo
protocol instead");
+        super.setup(resolver, objectModel, src, par);
+    }
+
+    /**
+     * The component isn't cached (yet)
+     */
+    public SourceValidity getValidity() {
+        return null;
+    }
+
+    /**
+     * The component isn't cached (yet)
+     */
+    public java.io.Serializable getKey() {
+        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) {
+            getLogger().error("The XML:DB driver raised an exception");
+            getLogger().error("probably the document was not found");
+            throw new ProcessingException("Null pointer exception while " +
+                                          "retrieving document : " + npe.getMessage());
+        }
+    }
+}

Propchange: cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/generation/XMLDBGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/transformation/XMLDBTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/transformation/XMLDBTransformer.java?rev=369503&r1=369502&r2=369503&view=diff
==============================================================================
--- cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/transformation/XMLDBTransformer.java
(original)
+++ cocoon/trunk/cocoon-xmldb/src/main/java/org/apache/cocoon/transformation/XMLDBTransformer.java
Mon Jan 16 08:01:55 2006
@@ -15,24 +15,35 @@
  */
 package org.apache.cocoon.transformation;
 
+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;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.sax.SAXTransformerFactory;
+import javax.xml.transform.sax.TransformerHandler;
+import javax.xml.transform.stream.StreamResult;
+
 import org.apache.avalon.framework.activity.Initializable;
 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.cocoon.util.TraxErrorHandler;
-
 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.DatabaseManager;
 import org.xmldb.api.base.Collection;
 import org.xmldb.api.base.Database;
@@ -41,22 +52,6 @@
 import org.xmldb.api.modules.CollectionManagementService;
 import org.xmldb.api.modules.XUpdateQueryService;
 
-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;
-
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.stream.StreamResult;
-
 /**
  * This transformer allows to perform resource creation, deletion, and
  * XUpdate command execution in XML:DB. All operations are performed either
@@ -71,13 +66,18 @@
  *   &lt;driver&gt;org.apache.xindice.client.xmldb.DatabaseImpl&lt;/driver&gt;
  *   --&gt;
  *   &lt;base&gt;xmldb:xindice:///db/collection&lt;/base&gt;
+ *   &lt;user&gt;myDatabaseLogin&lt;/user&gt;
+ *   &lt;password&gt;myDatabasePassword&lt;/password&gt;
  * &lt;/map:transformer&gt;
  * </pre>
  *
- * <p>Invocation:</p>
+ * <p>The component configuration defined in &lt;map:transformer&gt; can be
+ * overriden with sitemap parameters on the &lt;map:transform&gt;:</p>
  * <pre>
  * &lt;map:transform type="xmldb"&gt;
  *   &lt;map:parameter name="base" value="xmldb:xindice:///db/collection"/&gt;
+ *   &lt;map:parameter name="user" value="myDatabaseLogin"/&gt;
+ *   &lt;map:parameter name="password" value="myDatabasePassword"/&gt;
  * &lt;/map:transform&gt;
  * </pre>
  *
@@ -109,7 +109,7 @@
  *   &lt;db:query type="create" oid="inner/"/&gt;
  *
  *   &lt;p&gt;Create XML resource in context collection with specified object ID&lt;/p&gt;
- *   &lt;xmldb:query type="create" collection="inner" oid="xmldb-object-id"&gt;
+ *   &lt;db:query type="create" collection="inner" oid="xmldb-object-id"&gt;
  *     &lt;page&gt;
  *       XML Object body
  *     &lt;/page&gt;
@@ -138,7 +138,6 @@
  * <li>No namespaces with Xalan (see AbstractTextSerializer)</li>
  * </ul>
  *
- * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
  * @version $Id$
  */
 public class XMLDBTransformer extends AbstractTransformer
@@ -164,6 +163,12 @@
     /** Default collection name. */
     private String default_base;
 
+    /** Default user name. */
+    private String default_user;
+
+    /** Default password. */
+    private String default_password;
+
     /** Current collection name. */
     private String local_base;
 
@@ -173,6 +178,12 @@
     /** Current collection. */
     private Collection collection;
 
+    /** database login */
+    private String local_user = null;
+
+    /** database password */
+    private String local_password = null;
+
     /** Operation. One of: create, delete, update. */
     private String operation;
 
@@ -205,6 +216,8 @@
         }
 
         this.default_base = configuration.getChild("base").getValue(null);
+        this.default_user = configuration.getChild("user").getValue(null);
+        this.default_password = configuration.getChild("password").getValue(null);
     }
 
     /**
@@ -227,8 +240,12 @@
             throw new ProcessingException("Required base parameter is missing. Syntax is:
xmldb:xindice:///db/collection");
         }
 
+        /** Get user password from parameter for the database. Usefull for update action
*/
+        this.local_user     = par.getParameter("user",     this.default_user);
+        this.local_password = par.getParameter("password", this.default_password);
+
         try {
-            this.collection = DatabaseManager.getCollection(this.local_base);
+            this.collection = DatabaseManager.getCollection(this.local_base, this.local_user,
this.local_password);
         } catch (XMLDBException e) {
             throw new ProcessingException("Could not get collection " + this.local_base +
": " + e.errorCode, e);
         }
@@ -414,7 +431,7 @@
                 Collection collection = null;
                 try {
                     // Obtain collection for the current operation
-                    collection = (xbase != null)? DatabaseManager.getCollection(local_base
+ "/" + xbase) : this.collection;
+                    collection = (xbase != null)? DatabaseManager.getCollection(local_base
+ "/" + xbase, this.local_user, this.local_password) : this.collection;
 
                     if (collection == null) {
                         message = "Failed to " + operation + " resource " + this.key + ":
Collection " + local_base + "/" + xbase + " not found.";



Mime
View raw message