This project has retired. For details please refer to its
Attic page.
PropertyUtil xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.inmemory.types;
20
21 import org.apache.chemistry.opencmis.commons.PropertyIds;
22 import org.apache.chemistry.opencmis.commons.data.ContentStream;
23 import org.apache.chemistry.opencmis.commons.data.PropertyData;
24 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
25 import org.apache.chemistry.opencmis.commons.enums.Cardinality;
26 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Content;
27 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Document;
28 import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
29 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
30 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
31 import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;
32
33 public class PropertyUtil {
34
35 public static Object getProperty(StoredObject so, String propertyId, PropertyDefinition<?> pd) {
36 ContentStream content = null;
37 DocumentVersion ver = null;
38 VersionedDocument verDoc = null;
39 Folder folder = null;
40 Document doc = null;
41
42 if (so instanceof Content)
43 content = ((Content) so).getContent(0, 0);
44 if (so instanceof DocumentVersion)
45 ver = (DocumentVersion) so;
46 if (so instanceof VersionedDocument)
47 verDoc = (VersionedDocument) so;
48 if (so instanceof Folder)
49 folder = (Folder) so;
50 if (so instanceof Document)
51 doc = (Document) so;
52
53
54 if (propertyId.equals(PropertyIds.NAME)) {
55 return so.getName();
56 }
57 if (propertyId.equals(PropertyIds.OBJECT_ID)) {
58 return so.getId();
59 }
60 if (propertyId.equals(PropertyIds.OBJECT_TYPE_ID)) {
61 return so.getTypeId();
62 }
63 if (propertyId.equals(PropertyIds.BASE_TYPE_ID)) {
64 return null;
65 }
66 if (propertyId.equals(PropertyIds.CREATED_BY)) {
67 return so.getCreatedBy();
68 }
69 if (propertyId.equals(PropertyIds.CREATION_DATE)) {
70 return so.getCreatedAt();
71 }
72 if (propertyId.equals(PropertyIds.LAST_MODIFIED_BY)) {
73 return so.getModifiedBy();
74 }
75 if (propertyId.equals(PropertyIds.LAST_MODIFICATION_DATE)) {
76 return so.getModifiedAt();
77 }
78 if (propertyId.equals(PropertyIds.CHANGE_TOKEN)) {
79 return so.getChangeToken();
80 }
81
82 if (ver != null) {
83
84
85
86
87
88
89 if (propertyId.equals(PropertyIds.IS_MAJOR_VERSION)) {
90 return ver.isMajor();
91 }
92
93 if (propertyId.equals(PropertyIds.CHECKIN_COMMENT)) {
94 return ver.getCheckinComment();
95 }
96 if (propertyId.equals(PropertyIds.VERSION_LABEL)) {
97 return ver.getVersionLabel();
98 }
99 if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID)) {
100 return ver.isPwc() ? ver.getId() : null;
101 }
102 }
103
104
105 if (verDoc != null) {
106 if (propertyId.equals(PropertyIds.VERSION_SERIES_ID)) {
107 return verDoc.getId();
108 }
109 if (propertyId.equals(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT)) {
110 return verDoc.isCheckedOut();
111 }
112 if (propertyId.equals(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY)) {
113 return verDoc.getCheckedOutBy();
114 }
115 }
116
117
118 if (null != content) {
119
120 if (propertyId.equals(PropertyIds.CONTENT_STREAM_FILE_NAME)) {
121 return content.getFileName();
122 }
123
124 if (propertyId.equals(PropertyIds.CONTENT_STREAM_LENGTH)) {
125 return content.getBigLength();
126 }
127 if (propertyId.equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) {
128 return content.getMimeType();
129 }
130 }
131
132 if (folder != null) {
133
134 if (propertyId.equals(PropertyIds.PARENT_ID)) {
135 return folder.getParent() == null ? null : folder.getParent().getId();
136 }
137
138 if (propertyId.equals(PropertyIds.PATH)) {
139 return folder.getPath();
140 }
141 }
142
143 if (doc != null) {
144 if (propertyId.equals(PropertyIds.IS_IMMUTABLE)) {
145 return false;
146 }
147 }
148
149
150 PropertyData<?> lVal = so.getProperties().get(propertyId);
151 if (null == lVal)
152 return null;
153 else if (pd.getCardinality() == Cardinality.SINGLE) {
154 return lVal.getFirstValue();
155 } else {
156 return lVal.getValues();
157 }
158 }
159
160 }