1 package org
.argeo
.cms
.internal
.kernel
;
4 import java
.io
.InputStream
;
5 import java
.util
.Arrays
;
6 import java
.util
.Dictionary
;
7 import java
.util
.Hashtable
;
8 import java
.util
.Properties
;
10 import javax
.jcr
.Repository
;
12 import org
.apache
.commons
.io
.IOUtils
;
13 import org
.apache
.commons
.logging
.Log
;
14 import org
.apache
.commons
.logging
.LogFactory
;
15 import org
.apache
.jackrabbit
.core
.RepositoryImpl
;
16 import org
.apache
.jackrabbit
.core
.config
.RepositoryConfig
;
17 import org
.apache
.jackrabbit
.core
.config
.RepositoryConfigurationParser
;
18 import org
.argeo
.ArgeoException
;
19 import org
.argeo
.jackrabbit
.JackrabbitWrapper
;
20 import org
.argeo
.jcr
.ArgeoJcrConstants
;
21 import org
.osgi
.framework
.BundleContext
;
22 import org
.osgi
.framework
.ServiceRegistration
;
23 import org
.xml
.sax
.InputSource
;
26 class JackrabbitNode
extends JackrabbitWrapper
{
27 private static Log log
= LogFactory
.getLog(JackrabbitNode
.class);
29 private ServiceRegistration
<Repository
> repositoryReg
;
31 public JackrabbitNode(BundleContext bundleContext
) {
32 setBundleContext(bundleContext
);
34 setCndFiles(Arrays
.asList(KernelConstants
.DEFAULT_CNDS
));
38 public void publish() {
39 Hashtable
<String
, String
> regProps
= new Hashtable
<String
, String
>();
40 regProps
.put(ArgeoJcrConstants
.JCR_REPOSITORY_ALIAS
,
41 ArgeoJcrConstants
.ALIAS_NODE
);
42 repositoryReg
= getBundleContext().registerService(Repository
.class,
46 public void destroy() {
47 repositoryReg
.unregister();
48 ((RepositoryImpl
) getRepository()).shutdown();
51 Dictionary
<String
, ?
> getDefaults() {
52 return KernelUtils
.asDictionary(getClass().getClassLoader(),
53 "/org/argeo/cms/internal/kernel/jackrabbit-node.properties");
56 InputSource
getConfigurationXml(JackrabbitNodeTypes type
) {
57 ClassLoader cl
= getClass().getClassLoader();
59 .getResourceAsStream("/org/argeo/cms/internal/kernel/repository-h2.xml");
60 return new InputSource(in
);
63 Properties
getDefaultConfigurationProperties() {
64 Properties configurationProperties
= new Properties();
65 configurationProperties
.setProperty(KernelConstants
.REPO_DBUSER
, "sa");
66 configurationProperties
67 .setProperty(KernelConstants
.REPO_DBPASSWORD
, "");
68 configurationProperties
.setProperty(KernelConstants
.REPO_MAX_POOL_SIZE
,
70 configurationProperties
.setProperty(
71 KernelConstants
.REPO_DEFAULT_WORKSPACE
, "main");
72 return configurationProperties
;
75 private void createNode() {
76 Thread
.currentThread().setContextClassLoader(
77 getClass().getClassLoader());
79 File osgiInstanceDir
= KernelUtils
80 .getOsgiInstanceDir(getBundleContext());
81 File homeDir
= new File(osgiInstanceDir
, "node");
84 String dburl
= "jdbc:h2:" + homeDir
.getPath() + "/h2/repository";
85 Properties configurationProperties
= getDefaultConfigurationProperties();
86 configurationProperties
.setProperty(KernelConstants
.REPO_DBURL
, dburl
);
87 configurationProperties
.put(
88 RepositoryConfigurationParser
.REPOSITORY_HOME_VARIABLE
,
89 homeDir
.getAbsolutePath());
90 // InputSource configurationXml = getConfigurationXml(null);
92 // jackrabbitContainer.setHomeDirectory(homeDir);
93 // jackrabbitContainer.setConfigurationProperties(configurationProperties);
94 // jackrabbitContainer.setConfigurationXml(configurationXml);
96 // jackrabbitContainer.init();
98 RepositoryImpl repository
= createJackrabbitRepository(
99 configurationProperties
, getConfigurationXml(null));
101 setRepository(repository
);
104 private RepositoryImpl
createJackrabbitRepository(Properties vars
,
105 InputSource config
) {
106 File homeDirectory
= null;
107 long begin
= System
.currentTimeMillis();
108 InputStream configurationIn
= null;
109 RepositoryImpl repository
;
111 RepositoryConfig repositoryConfig
= RepositoryConfig
.create(config
,
115 // Actual repository creation
117 repository
= RepositoryImpl
.create(repositoryConfig
);
119 double duration
= ((double) (System
.currentTimeMillis() - begin
)) / 1000;
120 if (log
.isTraceEnabled())
121 log
.trace("Created Jackrabbit repository in " + duration
122 + " s, home: " + homeDirectory
);
125 } catch (Exception e
) {
126 throw new ArgeoException("Cannot create Jackrabbit repository "
129 IOUtils
.closeQuietly(configurationIn
);