jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r923654 - /jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Date Tue, 16 Mar 2010 09:55:55 GMT
Author: jukka
Date: Tue Mar 16 09:55:55 2010
New Revision: 923654

URL: http://svn.apache.org/viewvc?rev=923654&view=rev
Log:
JCR-2569: Implement jcr-jackrabbit://... repository URIs

Automatically parse possible query parameters in the repository URI, and pass them in the
parameter map instead.

Modified:
    jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java

Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=923654&r1=923653&r2=923654&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
Tue Mar 16 09:55:55 2010
@@ -16,7 +16,12 @@
  */
 package org.apache.jackrabbit.commons;
 
+import static java.net.URLDecoder.decode;
+
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -160,11 +165,15 @@ public class JcrUtils {
     }
 
     /**
-     * Returns the repository identified by the given URI. See the
-     * documentation of the repository implementation you want to use for
-     * whether it supports this repository URI convention and for what
-     * the repository URI should look like. For example, Jackrabbit 2.0
-     * supports the following types of repository URIs:
+     * Returns the repository identified by the given URI. This feature
+     * is implemented by calling the {@link #getRepository(Map)} method
+     * with the {@link #REPOSITORY_URI} parameter set to the given URI.
+     * Any query parameters are moved from the URI to the parameter map.
+     * <p>
+     * See the documentation of the repository implementation you want
+     * to use for whether it supports this repository URI convention and
+     * for what the repository URI should look like. For example,
+     * Jackrabbit 2.0 supports the following types of repository URIs:
      * <dl>
      *   <dt>http(s)://...</dt>
      *   <dd>
@@ -190,9 +199,37 @@ public class JcrUtils {
      */
     public static Repository getRepository(String uri)
             throws RepositoryException {
-        Map<String, String> parameters = new HashMap<String, String>();
-        parameters.put(JcrUtils.REPOSITORY_URI, uri);
-        return getRepository(parameters);
+        try {
+            Map<String, String> parameters = new HashMap<String, String>();
+            URI u = new URI(uri);
+            String query = u.getRawQuery();
+            if (query != null) {
+                for (String entry : query.split("&")) {
+                    int i = entry.indexOf('=');
+                    if (i != -1) {
+                        parameters.put(
+                                decode(entry.substring(0, i), "UTF-8"),
+                                decode(entry.substring(i + 1), "UTF-8"));
+                    } else {
+                        parameters.put(
+                                decode(entry, "UTF-8"),
+                                Boolean.TRUE.toString());
+                    }
+                }
+                parameters.put(
+                        JcrUtils.REPOSITORY_URI,
+                        new URI(u.getScheme(), u.getRawAuthority(),
+                                u.getRawPath(), null, u.getRawFragment()
+                                ).toASCIIString());
+            } else {
+                parameters.put(JcrUtils.REPOSITORY_URI, uri);
+            }
+            return getRepository(parameters);
+        } catch (UnsupportedEncodingException e) {
+            throw new RepositoryException("Unable to decode URI: " + uri, e);
+        } catch (URISyntaxException e) {
+            throw new RepositoryException("Invalid repository URI: " + uri, e);
+        }
     }
 
     /**



Mime
View raw message