]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/jackrabbit/JackrabbitRepositoryFactory.java
JCR repository factory recognizes vm:///alias URIs
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.jackrabbit / src / main / java / org / argeo / jackrabbit / JackrabbitRepositoryFactory.java
index 65bdf29393478ae0b1b99371ed441e54288e9762..1f2ec2ae2c16716ad020af4cb576be50bc043b1d 100644 (file)
@@ -1,5 +1,22 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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.argeo.jackrabbit;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -39,9 +56,25 @@ public class JackrabbitRepositoryFactory extends DefaultRepositoryFactory
                else if (parameters.containsKey(JcrUtils.REPOSITORY_URI))
                        uri = parameters.get(JcrUtils.REPOSITORY_URI).toString();
 
-               if (uri == null)
-                       repository = createRemoteRepository(uri);
+               if (uri != null) {
+                       if (uri.startsWith("http"))// http, https
+                               repository = createRemoteRepository(uri);
+                       else if (uri.startsWith("vm")) {
+                               try {
+                                       URI uriObj = new URI(uri);
+                                       String alias = uriObj.getPath();
+                                       if (alias.charAt(0) == '/')
+                                               alias = alias.substring(1);
+                                       if (alias.charAt(alias.length() - 1) == '/')
+                                               alias = alias.substring(0, alias.length() - 1);
+                                       repository = getRepositoryByAlias(alias);
+                               } catch (URISyntaxException e) {
+                                       throw new ArgeoException("Cannot interpret URI " + uri, e);
+                               }
+                       }
+               }
 
+               // publish under alias
                if (parameters.containsKey(JCR_REPOSITORY_ALIAS)) {
                        Properties properties = new Properties();
                        properties.putAll(parameters);
@@ -68,7 +101,7 @@ public class JackrabbitRepositoryFactory extends DefaultRepositoryFactory
        }
 
        /**
-        * Called after the repository has been initialized. Does nothing by
+        * Called after the repository has been initialised. Does nothing by
         * default.
         */
        @SuppressWarnings("rawtypes")