]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.server.jcr/src/org/argeo/jcr/ArgeoJcrUtils.java
Adapt to package names changes in Spring Security
[lgpl/argeo-commons.git] / org.argeo.server.jcr / src / org / argeo / jcr / ArgeoJcrUtils.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.jcr;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import javax.jcr.Repository;
22 import javax.jcr.RepositoryException;
23 import javax.jcr.RepositoryFactory;
24
25 import org.argeo.ArgeoException;
26
27 /** Utilities related to Argeo model in JCR */
28 public class ArgeoJcrUtils implements ArgeoJcrConstants {
29 /**
30 * Wraps the call to the repository factory based on parameter
31 * {@link ArgeoJcrConstants#JCR_REPOSITORY_ALIAS} in order to simplify it
32 * and protect against future API changes.
33 */
34 public static Repository getRepositoryByAlias(
35 RepositoryFactory repositoryFactory, String alias) {
36 try {
37 Map<String, String> parameters = new HashMap<String, String>();
38 parameters.put(JCR_REPOSITORY_ALIAS, alias);
39 return repositoryFactory.getRepository(parameters);
40 } catch (RepositoryException e) {
41 throw new ArgeoException(
42 "Unexpected exception when trying to retrieve repository with alias "
43 + alias, e);
44 }
45 }
46
47 /**
48 * Wraps the call to the repository factory based on parameter
49 * {@link ArgeoJcrConstants#JCR_REPOSITORY_URI} in order to simplify it and
50 * protect against future API changes.
51 */
52 public static Repository getRepositoryByUri(
53 RepositoryFactory repositoryFactory, String uri) {
54 return getRepositoryByUri(repositoryFactory, uri, null);
55 }
56
57 /**
58 * Wraps the call to the repository factory based on parameter
59 * {@link ArgeoJcrConstants#JCR_REPOSITORY_URI} in order to simplify it and
60 * protect against future API changes.
61 */
62 public static Repository getRepositoryByUri(
63 RepositoryFactory repositoryFactory, String uri, String alias) {
64 try {
65 Map<String, String> parameters = new HashMap<String, String>();
66 parameters.put(JCR_REPOSITORY_URI, uri);
67 if (alias != null)
68 parameters.put(JCR_REPOSITORY_ALIAS, alias);
69 return repositoryFactory.getRepository(parameters);
70 } catch (RepositoryException e) {
71 throw new ArgeoException(
72 "Unexpected exception when trying to retrieve repository with uri "
73 + uri, e);
74 }
75 }
76
77 private ArgeoJcrUtils() {
78 }
79
80 }