2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.jackrabbit
;
18 import java
.util
.HashMap
;
20 import java
.util
.Properties
;
22 import javax
.jcr
.Repository
;
23 import javax
.jcr
.RepositoryException
;
24 import javax
.jcr
.RepositoryFactory
;
26 import org
.apache
.commons
.logging
.Log
;
27 import org
.apache
.commons
.logging
.LogFactory
;
28 import org
.apache
.jackrabbit
.commons
.JcrUtils
;
29 import org
.apache
.jackrabbit
.jcr2dav
.Jcr2davRepositoryFactory
;
30 import org
.argeo
.ArgeoException
;
31 import org
.argeo
.jcr
.ArgeoJcrConstants
;
32 import org
.argeo
.jcr
.DefaultRepositoryFactory
;
35 * Repository factory which can create new repositories and access remote
36 * Jackrabbit repositories
38 public class JackrabbitRepositoryFactory
extends DefaultRepositoryFactory
39 implements RepositoryFactory
, ArgeoJcrConstants
{
40 private final static Log log
= LogFactory
41 .getLog(JackrabbitRepositoryFactory
.class);
43 @SuppressWarnings({ "rawtypes", "unchecked" })
44 public Repository
getRepository(Map parameters
) throws RepositoryException
{
45 // check if can be found by alias
46 Repository repository
= super.getRepository(parameters
);
47 if (repository
!= null)
52 if (parameters
.containsKey(JCR_REPOSITORY_URI
))
53 uri
= parameters
.get(JCR_REPOSITORY_URI
).toString();
54 else if (parameters
.containsKey(JcrUtils
.REPOSITORY_URI
))
55 uri
= parameters
.get(JcrUtils
.REPOSITORY_URI
).toString();
58 if (uri
.startsWith("http"))// http, https
59 repository
= createRemoteRepository(uri
);
60 else if (uri
.startsWith("vm")) {
63 + " should have been managed by generic JCR repository factory");
64 repository
= getRepositoryByAlias(getAliasFromURI(uri
));
68 // publish under alias
69 if (parameters
.containsKey(JCR_REPOSITORY_ALIAS
)) {
70 Properties properties
= new Properties();
71 properties
.putAll(parameters
);
72 String alias
= parameters
.get(JCR_REPOSITORY_ALIAS
).toString();
73 publish(alias
, repository
, properties
);
74 log
.info("Registered JCR repository under alias '" + alias
75 + "' with properties " + properties
);
81 protected Repository
createRemoteRepository(String uri
)
82 throws RepositoryException
{
83 Map
<String
, String
> params
= new HashMap
<String
, String
>();
84 params
.put(JcrUtils
.REPOSITORY_URI
, uri
);
85 Repository repository
= new Jcr2davRepositoryFactory()
86 .getRepository(params
);
87 if (repository
== null)
88 throw new ArgeoException("Remote Davex repository " + uri
90 log
.info("Initialized remote Jackrabbit repository from uri " + uri
);
95 * Called after the repository has been initialised. Does nothing by
98 @SuppressWarnings("rawtypes")
99 protected void postInitialization(Repository repository
, Map parameters
) {