1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package nl.hippo.client.webdav.binding.content;
17
18 import java.util.HashSet;
19 import java.util.Iterator;
20 import java.util.Set;
21
22 import nl.hippo.client.api.content.DocumentMetadata;
23 import nl.hippo.client.api.content.DocumentPath;
24 import nl.hippo.client.api.content.Property;
25
26 import org.apache.commons.lang.builder.EqualsBuilder;
27 import org.apache.commons.lang.builder.HashCodeBuilder;
28 import org.apache.commons.lang.builder.ToStringBuilder;
29 import org.apache.commons.lang.builder.ToStringStyle;
30
31 /**
32 * Java binding for a DocumentMetadataImpl XML fragment
33 */
34 public class DocumentMetadataImpl implements DocumentMetadata {
35
36 private static final long serialVersionUID = 1L;
37
38 private HashSet properties;
39 private DocumentPath path;
40
41 DocumentMetadataImpl(HashSet set) {
42 this.properties = set;
43 }
44
45 DocumentMetadataImpl(DocumentMetadataImpl metadata, DocumentPath path) {
46 this.properties = metadata.properties;
47 this.path = path;
48 }
49
50 public DocumentPath getDocumentPath() {
51 return path;
52 }
53
54 public Set getProperties() {
55 return properties;
56 }
57
58 public String getPropertyValue(String propertyName, String namespaceUri) {
59 if (propertyName == null || namespaceUri == null) {
60 throw new IllegalArgumentException("Parameters propertyName and namespaceUri should not be null.");
61 }
62 Iterator it = properties.iterator();
63 while (it.hasNext()) {
64 Property prop = (Property) it.next();
65 if (propertyName.equals(prop.getName()) && namespaceUri.equals(prop.getNamespaceUri())) {
66 return prop.getValue();
67 }
68 }
69 return null;
70 }
71
72 public String getDisplayname() {
73 return getPropertyValue("displayname", Property.DAV_NAMESPACE);
74 }
75
76 public String getCaption() {
77 return getPropertyValue("caption", Property.HIPPO_NAMESPACE);
78 }
79
80
81
82
83
84
85
86
87 public boolean isCollection() {
88 String isCollection = getPropertyValue("iscollection", Property.DAV_NAMESPACE);
89 return Boolean.valueOf(isCollection).booleanValue();
90 }
91
92 public String getType() {
93 return getPropertyValue("type", Property.HIPPO_NAMESPACE);
94 }
95
96 public String getId() {
97 return getPropertyValue("UID", Property.HIPPO_NAMESPACE);
98 }
99
100 public Integer getIndex() {
101 Integer result;
102 try {
103 result = Integer.valueOf(getPropertyValue("index", Property.HIPPO_NAMESPACE));
104 } catch (NumberFormatException e) {
105 result = null;
106 }
107 return result;
108 }
109
110 public String getContentLanguage() {
111 return getPropertyValue("getcontentlanguage", Property.DAV_NAMESPACE);
112 }
113
114 public String getEtag() {
115 return getPropertyValue("getetag", Property.DAV_NAMESPACE);
116 }
117
118 public String getLastmodified() {
119 return getPropertyValue("getlastmodified", Property.DAV_NAMESPACE);
120 }
121
122 public String getCreatedBy() {
123 return getPropertyValue("createdBy", Property.HIPPO_NAMESPACE);
124 }
125
126 public String getCreationDate() {
127 return getPropertyValue("creationdate", Property.DAV_NAMESPACE);
128 }
129
130 public String getPublicationDate() {
131 return getPropertyValue("publicationDate", Property.HIPPO_NAMESPACE);
132 }
133
134 public String getModificationDate() {
135 return getPropertyValue("modificationdate", Property.DAV_NAMESPACE);
136 }
137
138 public String getLastModifiedBy() {
139 return getPropertyValue("lastModifiedBy", Property.HIPPO_NAMESPACE);
140 }
141
142 public String getReferences() {
143 return getPropertyValue("references", Property.HIPPO_NAMESPACE);
144 }
145
146 public String getLinks() {
147 return getPropertyValue("links", Property.HIPPO_NAMESPACE);
148 }
149
150 public String getLastWorkflowUser() {
151 return getPropertyValue("lastWorkflowUser", Property.HIPPO_NAMESPACE);
152 }
153
154 public String getContentType() {
155 return getPropertyValue("getcontenttype", Property.DAV_NAMESPACE);
156 }
157
158 public String getContentLength() {
159 return getPropertyValue("getcontentlength", Property.DAV_NAMESPACE);
160 }
161
162 public String toString() {
163 ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
164
165 if (path != null) {
166 builder.append("DocumentPath", path.getFullPath());
167 }
168
169 if (properties != null) {
170 builder.append("PropCount", properties.size());
171 Iterator it = properties.iterator();
172 while (it.hasNext()) {
173 Property prop = (Property) it.next();
174 builder.append(prop.toString());
175 }
176 }
177 return builder.toString();
178 }
179
180 public boolean equals(Object obj) {
181 if (obj instanceof DocumentMetadataImpl == false) {
182 return false;
183 }
184 if (this == obj) {
185 return true;
186 }
187 DocumentMetadataImpl rhs = (DocumentMetadataImpl) obj;
188 return new EqualsBuilder().append(properties, rhs.properties).append(path, rhs.path).isEquals();
189 }
190
191 public int hashCode() {
192 return new HashCodeBuilder(27, 123).append(properties).append(path).toHashCode();
193 }
194
195 }