1 package org.argeo.slc.client.ui.dist.model;
2
3 import javax.jcr.RepositoryException;
4 import javax.jcr.Session;
5
6 import org.argeo.jcr.JcrUtils;
7 import org.argeo.slc.SlcException;
8
9
10
11
12
13 public class WkspGroupElem extends DistParentElem {
14
15 private Session defaultSession;
16
17 public WkspGroupElem(RepoElem repoElem, String prefix) {
18 super(prefix, repoElem.inHome(), repoElem.isReadOnly());
19 setParent(repoElem);
20
21 try {
22 defaultSession = repoElem.repositoryLogin(null);
23 String[] wkpNames = defaultSession.getWorkspace()
24 .getAccessibleWorkspaceNames();
25 for (String wkpName : wkpNames) {
26 if (prefix.equals(getPrefix(wkpName))
27
28 && repoElem.isWorkspaceVisible(wkpName))
29 addChild(new WorkspaceElem(WkspGroupElem.this, repoElem,
30 wkpName));
31 }
32 } catch (RepositoryException e) {
33 throw new SlcException("Cannot retrieve workspace names", e);
34 }
35 }
36
37
38
39
40
41 private String getPrefix(String workspaceName) {
42 if (workspaceName.lastIndexOf(VERSION_SEP) > 0)
43 return workspaceName.substring(0,
44 workspaceName.lastIndexOf(VERSION_SEP));
45 else
46 return workspaceName;
47 }
48
49 public void dispose() {
50 JcrUtils.logoutQuietly(defaultSession);
51 super.dispose();
52 }
53 }