gianugo 2002/12/16 16:03:45 Modified: src/java/org/apache/cocoon/components/source XMLDBSource.java XMLDBSourceFactory.java Log: Added optional "user" and "password" attributes to the XML:DB configuration Revision Changes Path 1.11 +14 -3 xml-cocoon2/src/java/org/apache/cocoon/components/source/XMLDBSource.java Index: XMLDBSource.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/XMLDBSource.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- XMLDBSource.java 5 Dec 2002 10:17:29 -0000 1.10 +++ XMLDBSource.java 17 Dec 2002 00:03:45 -0000 1.11 @@ -54,6 +54,7 @@ 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; @@ -87,6 +88,12 @@ /** 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; @@ -140,6 +147,7 @@ ComponentManager manager, Logger logger, String driver, + SourceCredential credential, String url) { super(environment, manager, logger); @@ -147,6 +155,9 @@ 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); @@ -212,7 +223,7 @@ final String res = url.substring(url.lastIndexOf('/') + 1); try { - Collection collection = DatabaseManager.getCollection(col); + Collection collection = DatabaseManager.getCollection(col, user, password); if (collection == null) { throw new ResourceNotFoundException("Document " + url + " not found"); } @@ -251,7 +262,7 @@ AttributesImpl attributes = new AttributesImpl(); try { - Collection collection = DatabaseManager.getCollection(url); + Collection collection = DatabaseManager.getCollection(url, user, password); if (collection == null) { throw new ResourceNotFoundException("Collection " + url + " not found"); 1.8 +20 -4 xml-cocoon2/src/java/org/apache/cocoon/components/source/XMLDBSourceFactory.java Index: XMLDBSourceFactory.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/XMLDBSourceFactory.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- XMLDBSourceFactory.java 5 Dec 2002 10:17:29 -0000 1.7 +++ XMLDBSourceFactory.java 17 Dec 2002 00:03:45 -0000 1.8 @@ -56,7 +56,9 @@ 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; @@ -81,12 +83,18 @@ /** The driver implementation class */ protected String driver; - /** The driver implementation class */ + /** 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. */ @@ -96,12 +104,19 @@ if (conf != null) { 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")); + 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); } } else { @@ -136,6 +151,7 @@ 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 \"" + @@ -143,7 +159,7 @@ } return new XMLDBSource(environment, m_manager, this.getLogger(), - driver, location); + driver, credential, location); } /**
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]