1 package org
.argeo
.cms
.internal
.kernel
;
4 import java
.util
.TreeMap
;
6 import javax
.jcr
.RepositoryException
;
7 import javax
.jcr
.Session
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.apache
.jackrabbit
.core
.RepositoryImpl
;
12 import org
.argeo
.jcr
.JcrUtils
;
14 class JackrabbitLocalRepository
extends LocalRepository
{
15 private final static Log log
= LogFactory
.getLog(JackrabbitLocalRepository
.class);
16 final String SECURITY_WORKSPACE
= "security";
18 private Map
<String
, CmsWorkspaceIndexer
> workspaceMonitors
= new TreeMap
<>();
20 public JackrabbitLocalRepository(RepositoryImpl repository
, String cn
) {
21 super(repository
, cn
);
22 Session session
= KernelUtils
.openAdminSession(repository
);
24 for (String workspaceName
: session
.getWorkspace().getAccessibleWorkspaceNames()) {
25 addMonitor(workspaceName
);
27 } catch (RepositoryException e
) {
28 throw new IllegalStateException(e
);
30 JcrUtils
.logoutQuietly(session
);
34 protected RepositoryImpl
getJackrabbitrepository(String workspaceName
) {
35 return (RepositoryImpl
) getRepository(workspaceName
);
39 protected synchronized void processNewSession(Session session
, String workspaceName
) {
40 String realWorkspaceName
= session
.getWorkspace().getName();
41 addMonitor(realWorkspaceName
);
44 private void addMonitor(String realWorkspaceName
) {
45 if (realWorkspaceName
.equals(SECURITY_WORKSPACE
))
47 if (!workspaceMonitors
.containsKey(realWorkspaceName
)) {
49 CmsWorkspaceIndexer workspaceMonitor
= new CmsWorkspaceIndexer(
50 getJackrabbitrepository(realWorkspaceName
), getCn(), realWorkspaceName
);
51 workspaceMonitors
.put(realWorkspaceName
, workspaceMonitor
);
52 workspaceMonitor
.init();
53 if (log
.isDebugEnabled())
54 log
.debug("Registered " + workspaceMonitor
);
55 } catch (RepositoryException e
) {
56 // TODO Auto-generated catch block
62 public void destroy() {
63 for (String workspaceName
: workspaceMonitors
.keySet()) {
64 workspaceMonitors
.get(workspaceName
).destroy();