jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cko...@apache.org
Subject svn commit: r775875 - /jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
Date Mon, 18 May 2009 09:34:44 GMT
Author: ckoell
Date: Mon May 18 09:34:44 2009
New Revision: 775875

URL: http://svn.apache.org/viewvc?rev=775875&view=rev
Log:
Add support for URL based connection informations.
Sample: jdbc:jcr:http://localhost:8080/rmi?workspace=test&username=user&password=passwd

Modified:
    jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java

Modified: jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java?rev=775875&r1=775874&r2=775875&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
(original)
+++ jackrabbit/sandbox/jackrabbit-jdbc2jcr/src/main/java/org/apache/jackrabbit/jdbc/JCRDriver.java
Mon May 18 09:34:44 2009
@@ -23,7 +23,10 @@
 import java.sql.DriverManager;
 import java.sql.DriverPropertyInfo;
 import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
+import java.util.StringTokenizer;
 
 import javax.jcr.Credentials;
 import javax.jcr.LoginException;
@@ -79,6 +82,10 @@
 
     @Override
     public Connection connect(String url, Properties info) throws SQLException {
+        if (url.indexOf('?') > -1) {
+            info = parseUrl(url);
+            url = getCleanUrl(url);
+        }
         Repository repository = getRepository(url, info);
         if (repository == null) {
             return null;
@@ -118,6 +125,27 @@
         }
     }
 
+    private String getCleanUrl(String url) {
+        return url.substring(0, url.indexOf('?')); 
+    }
+
+    private Properties parseUrl(String url) {
+        String propertyString = url.substring(url.indexOf('?') + 1, url.length());
+        Properties properties = new Properties();
+        try {
+            StringTokenizer stringTokenizer = new StringTokenizer(propertyString, "&");
+            while (stringTokenizer.hasMoreTokens()) {
+                String keyValue = stringTokenizer.nextToken();
+                String key = keyValue.substring(0, keyValue.indexOf('='));
+                String value = keyValue.substring(keyValue.indexOf('=') + 1, keyValue.length());
+                properties.setProperty(key, value);
+            }
+        } catch (Exception e) {
+            e.printStackTrace(); // TODO: Better error handling
+        }
+        return properties;
+    }
+
     @Override
     public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
         // TODO: Should we delegate this to Derby?



Mime
View raw message