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.storedobj.impl;
20
21 import java.io.IOException;
22 import java.math.BigInteger;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.chemistry.opencmis.commons.PropertyIds;
27 import org.apache.chemistry.opencmis.commons.data.ContentStream;
28 import org.apache.chemistry.opencmis.commons.data.PropertyData;
29 import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
30 import org.apache.chemistry.opencmis.inmemory.ConfigConstants;
31 import org.apache.chemistry.opencmis.inmemory.ConfigurationSettings;
32 import org.apache.chemistry.opencmis.inmemory.FilterParser;
33 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Document;
34 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38
39
40
41
42
43
44
45
46 public class DocumentImpl extends AbstractMultiFilingImpl implements Document {
47 private ContentStreamDataImpl fContent;
48
49 private static final Log LOG = LogFactory.getLog(AbstractSingleFilingImpl.class.getName());
50 private final Long MAX_CONTENT_SIZE_KB = ConfigurationSettings.getConfigurationValueAsLong(ConfigConstants.MAX_CONTENT_SIZE_KB);
51
52 DocumentImpl(ObjectStoreImpl objStore) {
53 super(objStore);
54 }
55
56 public ContentStream getContent(long offset, long length) {
57 if (null == fContent) {
58 return null;
59 } else if (offset <= 0 && length < 0) {
60 return fContent;
61 } else {
62 return fContent.getCloneWithLimits(offset, length);
63 }
64 }
65
66 public void setContent(ContentStream content, boolean mustPersist) {
67 if (null == content) {
68 fContent = null;
69 } else {
70 fContent = new ContentStreamDataImpl(MAX_CONTENT_SIZE_KB == null ? 0 : MAX_CONTENT_SIZE_KB);
71 String fileName = content.getFileName();
72 if (null == fileName || fileName.length() <= 0) {
73 fileName = getName();
74 }
75 fContent.setFileName(fileName);
76 String mimeType = content.getMimeType();
77 if (null == mimeType || mimeType.length() <= 0) {
78 mimeType = "application/octet-stream";
79 }
80 fContent.setMimeType(mimeType);
81 try {
82 fContent.setContent(content.getStream());
83 } catch (IOException e) {
84 e.printStackTrace();
85 throw new RuntimeException("Failed to get content from InputStream", e);
86 }
87 }
88 }
89
90 @Override
91 public void fillProperties(Map<String, PropertyData<?>> properties, BindingsObjectFactory objFactory,
92 List<String> requestedIds) {
93
94 super.fillProperties(properties, objFactory, requestedIds);
95
96
97
98
99
100 if (FilterParser.isContainedInFilter(PropertyIds.IS_IMMUTABLE, requestedIds)) {
101 properties.put(PropertyIds.IS_IMMUTABLE, objFactory.createPropertyBooleanData(PropertyIds.IS_IMMUTABLE,
102 false));
103 }
104
105
106 if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_FILE_NAME, requestedIds)) {
107 properties.put(PropertyIds.CONTENT_STREAM_FILE_NAME, objFactory.createPropertyStringData(
108 PropertyIds.CONTENT_STREAM_FILE_NAME, null != fContent ? fContent.getFileName() : (String)null) );
109 }
110 if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_ID, requestedIds)) {
111 properties.put(PropertyIds.CONTENT_STREAM_ID, objFactory.createPropertyStringData(
112 PropertyIds.CONTENT_STREAM_ID, (String) null));
113 }
114 if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_LENGTH, requestedIds)) {
115 properties.put(PropertyIds.CONTENT_STREAM_LENGTH, objFactory.createPropertyIntegerData(
116 PropertyIds.CONTENT_STREAM_LENGTH, null != fContent ? fContent.getBigLength() : BigInteger.ZERO));
117 }
118 if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_MIME_TYPE, requestedIds)) {
119 properties.put(PropertyIds.CONTENT_STREAM_MIME_TYPE, objFactory.createPropertyStringData(
120 PropertyIds.CONTENT_STREAM_MIME_TYPE, null != fContent ? fContent.getMimeType() : (String)null) );
121 }
122
123
124
125 if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_ID, requestedIds)) {
126 properties.put(PropertyIds.VERSION_SERIES_ID, objFactory.createPropertyIdData(
127 PropertyIds.VERSION_SERIES_ID, (String)null));
128 }
129 if (FilterParser.isContainedInFilter(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, requestedIds)) {
130 properties.put(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, objFactory.createPropertyBooleanData(
131 PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, false));
132 }
133 if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, requestedIds)) {
134 properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, objFactory.createPropertyStringData(
135 PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, (String)null));
136 }
137 if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, requestedIds)) {
138 properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, objFactory.createPropertyIdData(
139 PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, (String)null));
140 }
141 if (FilterParser.isContainedInFilter(PropertyIds.IS_LATEST_VERSION, requestedIds)) {
142 properties.put(PropertyIds.IS_LATEST_VERSION, objFactory.createPropertyBooleanData(
143 PropertyIds.IS_LATEST_VERSION, true));
144 }
145 if (FilterParser.isContainedInFilter(PropertyIds.IS_MAJOR_VERSION, requestedIds)) {
146 properties.put(PropertyIds.IS_MAJOR_VERSION, objFactory.createPropertyBooleanData(
147 PropertyIds.IS_MAJOR_VERSION, true));
148 }
149 if (FilterParser.isContainedInFilter(PropertyIds.IS_LATEST_MAJOR_VERSION, requestedIds)) {
150 properties.put(PropertyIds.IS_LATEST_MAJOR_VERSION, objFactory.createPropertyBooleanData(
151 PropertyIds.IS_LATEST_MAJOR_VERSION, true));
152 }
153 if (FilterParser.isContainedInFilter(PropertyIds.CHECKIN_COMMENT, requestedIds)) {
154 properties.put(PropertyIds.CHECKIN_COMMENT, objFactory.createPropertyStringData(
155 PropertyIds.CHECKIN_COMMENT, (String )null));
156 }
157 if (FilterParser.isContainedInFilter(PropertyIds.VERSION_LABEL, requestedIds)) {
158 properties.put(PropertyIds.VERSION_LABEL, objFactory.createPropertyStringData(PropertyIds.VERSION_LABEL,
159 (String) null));
160 }
161
162 }
163
164 public boolean hasContent() {
165 return null != fContent;
166 }
167
168 }