This project has retired. For details please refer to its
Attic page.
RenditionImpl 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.client.runtime;
20
21 import java.math.BigInteger;
22
23 import org.apache.chemistry.opencmis.client.api.CmisObject;
24 import org.apache.chemistry.opencmis.client.api.Document;
25 import org.apache.chemistry.opencmis.client.api.OperationContext;
26 import org.apache.chemistry.opencmis.client.api.Rendition;
27 import org.apache.chemistry.opencmis.client.api.Session;
28 import org.apache.chemistry.opencmis.commons.data.ContentStream;
29 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
30 import org.apache.chemistry.opencmis.commons.impl.dataobjects.RenditionDataImpl;
31
32
33
34
35 public class RenditionImpl extends RenditionDataImpl implements Rendition {
36
37 private static final long serialVersionUID = 1L;
38
39 private final Session session;
40 private final String objectId;
41
42
43
44
45 public RenditionImpl(Session session, String objectId, String streamId, String renditionDocumentId, String kind,
46 long length, String mimeType, String title, int height, int width) {
47 super(streamId, mimeType, BigInteger.valueOf(length), kind, title, BigInteger.valueOf(width), BigInteger
48 .valueOf(height), renditionDocumentId);
49 this.session = session;
50 this.objectId = objectId;
51 }
52
53 public long getLength() {
54 return length == null ? -1 : length.longValue();
55 }
56
57 public long getHeight() {
58 return height == null ? -1 : height.longValue();
59 }
60
61 public long getWidth() {
62 return width == null ? -1 : width.longValue();
63 }
64
65 public Document getRenditionDocument() {
66 return getRenditionDocument(session.getDefaultContext());
67 }
68
69 public Document getRenditionDocument(OperationContext context) {
70 if (renditionDocumentId == null) {
71 return null;
72 }
73 CmisObject rendDoc = session.getObject(session.createObjectId(renditionDocumentId), context);
74 if (!(rendDoc instanceof Document)) {
75 return null;
76 }
77
78 return (Document) rendDoc;
79 }
80
81 public ContentStream getContentStream() {
82 if ((objectId == null) || (streamId == null)) {
83 return null;
84 }
85
86 ContentStream contentStream;
87 try {
88 contentStream = session.getBinding().getObjectService()
89 .getContentStream(session.getRepositoryInfo().getId(), objectId, streamId, null, null, null);
90 } catch (CmisConstraintException e) {
91
92 return null;
93 }
94
95 if (contentStream == null) {
96 return null;
97 }
98
99 String filename = contentStream.getFileName();
100 if (filename == null) {
101 filename = getTitle();
102 }
103 BigInteger bigLength = contentStream.getBigLength();
104 if (bigLength == null) {
105 bigLength = getBigLength();
106 }
107 long length = bigLength == null ? -1 : bigLength.longValue();
108
109 return session.getObjectFactory().createContentStream(filename, length,
110 contentStream.getMimeType(), contentStream.getStream());
111 }
112
113 }