]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ArgeoJcrUtils.java
90bf0f0f48255bbd3c005486d0d0ece86d1c95a6
[lgpl/argeo-commons.git] / ArgeoJcrUtils.java
1 package org.argeo.jcr;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import javax.jcr.Repository;
7 import javax.jcr.RepositoryException;
8 import javax.jcr.RepositoryFactory;
9
10 import org.argeo.ArgeoException;
11
12 /** Utilities related to Argeo model in JCR */
13 public class ArgeoJcrUtils implements ArgeoJcrConstants {
14 /**
15 * Wraps the call to the repository factory based on parameter
16 * {@link ArgeoJcrConstants#JCR_REPOSITORY_ALIAS} in order to simplify it
17 * and protect against future API changes.
18 */
19 public static Repository getRepositoryByAlias(
20 RepositoryFactory repositoryFactory, String alias) {
21 try {
22 Map<String, String> parameters = new HashMap<String, String>();
23 parameters.put(JCR_REPOSITORY_ALIAS, alias);
24 return repositoryFactory.getRepository(parameters);
25 } catch (RepositoryException e) {
26 throw new ArgeoException(
27 "Unexpected exception when trying to retrieve repository with alias "
28 + alias, e);
29 }
30 }
31
32 /**
33 * Wraps the call to the repository factory based on parameter
34 * {@link ArgeoJcrConstants#JCR_REPOSITORY_URI} in order to simplify it and
35 * protect against future API changes.
36 */
37 public static Repository getRepositoryByUri(
38 RepositoryFactory repositoryFactory, String uri) {
39 return getRepositoryByUri(repositoryFactory, uri, null);
40 }
41
42 /**
43 * Wraps the call to the repository factory based on parameter
44 * {@link ArgeoJcrConstants#JCR_REPOSITORY_URI} in order to simplify it and
45 * protect against future API changes.
46 */
47 public static Repository getRepositoryByUri(
48 RepositoryFactory repositoryFactory, String uri, String alias) {
49 try {
50 Map<String, String> parameters = new HashMap<String, String>();
51 parameters.put(JCR_REPOSITORY_URI, uri);
52 if (alias != null)
53 parameters.put(JCR_REPOSITORY_ALIAS, alias);
54 return repositoryFactory.getRepository(parameters);
55 } catch (RepositoryException e) {
56 throw new ArgeoException(
57 "Unexpected exception when trying to retrieve repository with uri "
58 + uri, e);
59 }
60 }
61
62 private ArgeoJcrUtils() {
63 }
64
65 }