]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java
Fix issues with security dependencies
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.jackrabbit / src / main / java / org / argeo / server / jackrabbit / JackrabbitContainer.java
1 package org.argeo.server.jackrabbit;
2
3 import java.io.File;
4 import java.io.InputStream;
5
6 import javax.jcr.Credentials;
7 import javax.jcr.LoginException;
8 import javax.jcr.NoSuchWorkspaceException;
9 import javax.jcr.Repository;
10 import javax.jcr.RepositoryException;
11 import javax.jcr.Session;
12
13 import org.apache.commons.io.IOUtils;
14 import org.apache.jackrabbit.core.RepositoryImpl;
15 import org.apache.jackrabbit.core.config.RepositoryConfig;
16 import org.springframework.beans.factory.DisposableBean;
17 import org.springframework.beans.factory.InitializingBean;
18 import org.springframework.core.io.Resource;
19
20 public class JackrabbitContainer implements InitializingBean, DisposableBean,
21 Repository {
22 private Resource configuration;
23 private File homeDirectory;
24
25 private RepositoryImpl repository;
26
27 public void afterPropertiesSet() throws Exception {
28 RepositoryConfig config;
29 InputStream in = configuration.getInputStream();
30 try {
31 config = RepositoryConfig.create(in, homeDirectory
32 .getCanonicalPath());
33 } catch (Exception e) {
34 throw new RuntimeException("Cannot read configuration", e);
35 } finally {
36 IOUtils.closeQuietly(in);
37 }
38
39 repository = RepositoryImpl.create(config);
40 }
41
42 public void destroy() throws Exception {
43 if (repository != null)
44 repository.shutdown();
45 }
46
47 // JCR REPOSITORY (delegated)
48 public String getDescriptor(String key) {
49 return repository.getDescriptor(key);
50 }
51
52 public String[] getDescriptorKeys() {
53 return repository.getDescriptorKeys();
54 }
55
56 public Session login() throws LoginException, RepositoryException {
57 return repository.login();
58 }
59
60 public Session login(Credentials credentials, String workspaceName)
61 throws LoginException, NoSuchWorkspaceException,
62 RepositoryException {
63 return repository.login(credentials, workspaceName);
64 }
65
66 public Session login(Credentials credentials) throws LoginException,
67 RepositoryException {
68 return repository.login(credentials);
69 }
70
71 public Session login(String workspaceName) throws LoginException,
72 NoSuchWorkspaceException, RepositoryException {
73 return repository.login(workspaceName);
74 }
75
76 // BEANS METHODS
77 public void setHomeDirectory(File homeDirectory) {
78 this.homeDirectory = homeDirectory;
79 }
80
81 public void setConfiguration(Resource configuration) {
82 this.configuration = configuration;
83 }
84
85 }