1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.services.wcm.core;
18
19 import javax.jcr.Node;
20 import javax.jcr.RepositoryException;
21 import javax.jcr.Session;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.exoplatform.services.jcr.core.ManageableRepository;
25
26
27
28
29
30
31
32 public class NodeIdentifier {
33
34 private String repository;
35 private String workspace;
36 private String uuid;
37
38 public NodeIdentifier(final String repository, final String workspace, final String uuid) {
39 this.repository = repository;
40 this.workspace = workspace;
41 this.uuid = uuid;
42 }
43
44 public String getRepository() { return repository; }
45 public void setRepository(final String repository) { this.repository = repository; }
46
47 public String getWorkspace() { return workspace; }
48 public void setWorkspace(final String workspace) { this.workspace = workspace; }
49
50 public String getUUID() { return uuid; }
51 public void setUUID(final String uuid) { this.uuid = uuid; }
52
53 public final static NodeIdentifier parse(final String expr) {
54 String[] temp = expr.split("::");
55 if (temp.length == 3 && StringUtils.isNumeric(temp[2])) {
56 return new NodeIdentifier(temp[0], temp[1], temp[2]);
57 }
58 return null;
59 }
60
61 public final static NodeIdentifier make(final Node node) throws RepositoryException {
62 Session session = node.getSession();
63 String repository = ((ManageableRepository)session.getRepository()).getConfiguration().getName();
64 String workspace = session.getWorkspace().getName();
65 String uuid = node.getUUID();
66 return new NodeIdentifier(repository, workspace, uuid);
67 }
68
69 public final static String serialize(final NodeIdentifier identifier) {
70 StringBuffer buffer = new StringBuffer();
71 buffer.append(identifier.getRepository()).append("::")
72 .append(identifier.getWorkspace()).append("::")
73 .append(identifier.getUUID());
74 return buffer.toString();
75 }
76 }