1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wiki.chromattic.ext.ntdef;
18
19 import java.util.Date;
20 import java.util.Map;
21
22 import javax.jcr.Node;
23 import javax.jcr.PathNotFoundException;
24 import javax.jcr.RepositoryException;
25 import javax.jcr.Value;
26
27 import org.chromattic.api.annotations.OneToMany;
28 import org.chromattic.api.annotations.Path;
29 import org.chromattic.api.annotations.PrimaryType;
30 import org.chromattic.api.annotations.Properties;
31 import org.chromattic.api.annotations.Property;
32 import org.exoplatform.wiki.mow.core.api.wiki.WikiNodeType;
33 import org.exoplatform.wiki.mow.core.api.MOWService;
34
35 @PrimaryType(name = "nt:frozenNode")
36 public abstract class NTFrozenNode {
37
38 private MOWService mowService;
39
40 @Property(name = "jcr:frozenUuid")
41 public abstract String getFrozenUuid();
42
43 public abstract void setFrozenUuid(String frozenUuid);
44
45 @OneToMany
46 public abstract Map<String, Object> getChildren();
47
48 @Properties
49 public abstract Map<String, Object> getProperties();
50
51
52 public String getAuthor() throws RepositoryException {
53 Value value = getPropertyValue(WikiNodeType.Definition.AUTHOR);
54 if (value != null) {
55 return value.getString();
56 } else {
57 value = getPropertyValue("exo:lastModifier");
58 if (value != null) {
59 return value.getString();
60 } else {
61 return null;
62 }
63 }
64 }
65
66 public Date getUpdatedDate() throws RepositoryException {
67 Value value = getPropertyValue(WikiNodeType.Definition.UPDATED_DATE);
68 if (value != null) {
69 return value.getDate().getTime();
70 } else {
71 value = getPropertyValue(WikiNodeType.Definition.UPDATED);
72 if (value != null) {
73 return value.getDate().getTime();
74 } else {
75 return null;
76 }
77 }
78 }
79
80 public String getComment() throws RepositoryException {
81 Value value = getPropertyValue(WikiNodeType.Definition.COMMENT);
82 if (value != null) {
83 return value.getString();
84 } else {
85 return null;
86 }
87 }
88
89 public String getContentString() throws RepositoryException {
90 StringBuilder st = new StringBuilder(WikiNodeType.Definition.ATTACHMENT_CONTENT);
91 st.append("/").append(WikiNodeType.Definition.DATA);
92 Value value = getPropertyValue(st.toString());
93 if (value != null) {
94 return value.getString();
95 } else {
96 return null;
97 }
98 }
99
100 public void setMOWService(MOWService mowService) {
101 this.mowService = mowService;
102 }
103
104 @Path
105 protected abstract String getPath();
106
107 private Value getPropertyValue(String propertyName) throws RepositoryException {
108 Node pageNode = getJCRNode();
109 if (pageNode.hasProperty(propertyName)) {
110 javax.jcr.Property property = pageNode.getProperty(propertyName);
111 Value value = property.getValue();
112 return value;
113 } else {
114 return null;
115 }
116 }
117
118 public Node getJCRNode() throws RepositoryException {
119 return (Node) mowService.getSession().getJCRSession().getItem(getPath());
120 }
121
122 }