1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.api; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.InputStream; |
24 |
|
import java.io.UnsupportedEncodingException; |
25 |
|
import java.util.Date; |
26 |
|
import java.util.List; |
27 |
|
|
28 |
|
import org.apache.commons.io.IOUtils; |
29 |
|
import org.slf4j.Logger; |
30 |
|
import org.slf4j.LoggerFactory; |
31 |
|
import org.suigeneris.jrcs.rcs.Version; |
32 |
|
|
33 |
|
import com.xpn.xwiki.XWikiContext; |
34 |
|
import com.xpn.xwiki.XWikiException; |
35 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
36 |
|
|
|
|
| 56.5% |
Uncovered Elements: 27 (62) |
Complexity: 27 |
Complexity Density: 0.75 |
|
37 |
|
public class Attachment extends Api |
38 |
|
{ |
39 |
|
|
40 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(Attachment.class); |
41 |
|
|
42 |
|
private Document doc; |
43 |
|
|
44 |
|
private XWikiAttachment attachment; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
46 |
3816 |
public Attachment(Document doc, XWikiAttachment attachment, XWikiContext context)... |
47 |
|
{ |
48 |
3816 |
super(context); |
49 |
3816 |
this.doc = doc; |
50 |
3816 |
this.attachment = attachment; |
51 |
|
} |
52 |
|
|
53 |
|
|
54 |
|
@return |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
75 |
public Document getDocument()... |
57 |
|
{ |
58 |
75 |
return this.doc; |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
@return |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
public long getId()... |
65 |
|
{ |
66 |
0 |
return this.attachment.getId(); |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
@return |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0 |
public long getDocId()... |
73 |
|
{ |
74 |
0 |
return this.doc.getId(); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
@return |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
85 |
public int getFilesize()... |
81 |
|
{ |
82 |
85 |
return this.attachment.getFilesize(); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
@return |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
661 |
public String getFilename()... |
89 |
|
{ |
90 |
661 |
return this.attachment.getFilename(); |
91 |
|
} |
92 |
|
|
93 |
|
|
94 |
|
@return |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
81 |
public String getAuthor()... |
97 |
|
{ |
98 |
81 |
return this.attachment.getAuthor(); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
@return |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
76 |
public String getVersion()... |
105 |
|
{ |
106 |
76 |
return this.attachment.getVersion(); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
@return |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
0 |
public Version getRCSVersion()... |
113 |
|
{ |
114 |
0 |
return this.attachment.getRCSVersion(); |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
@return |
119 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
0 |
public String getComment()... |
121 |
|
{ |
122 |
0 |
return this.attachment.getComment(); |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
@return |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
75 |
public Date getDate()... |
129 |
|
{ |
130 |
75 |
return this.attachment.getDate(); |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
@return |
135 |
|
@throws |
136 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
60 |
public byte[] getContent() throws XWikiException... |
138 |
|
{ |
139 |
60 |
return getContentAsBytes(); |
140 |
|
} |
141 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
142 |
60 |
public byte[] getContentAsBytes() throws XWikiException... |
143 |
|
{ |
144 |
60 |
try { |
145 |
60 |
return IOUtils.toByteArray(this.attachment.getContentInputStream(getXWikiContext())); |
146 |
|
} catch (IOException ex) { |
147 |
|
|
148 |
0 |
return new byte[0]; |
149 |
|
} |
150 |
|
} |
151 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
152 |
4 |
public InputStream getContentInputStream()... |
153 |
|
{ |
154 |
4 |
try { |
155 |
4 |
return this.attachment.getContentInputStream(getXWikiContext()); |
156 |
|
} catch (XWikiException e) { |
157 |
0 |
LOGGER.error("Failed to get attachment input stream", e); |
158 |
|
|
159 |
0 |
return null; |
160 |
|
} |
161 |
|
} |
162 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
0 |
public String getContentAsString() throws XWikiException... |
164 |
|
{ |
165 |
|
|
166 |
0 |
return new String(getContentAsBytes()); |
167 |
|
} |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
169 |
0 |
public String getContentAsString(String charset) throws XWikiException... |
170 |
|
{ |
171 |
|
|
172 |
0 |
byte[] contentBytes = getContentAsBytes(); |
173 |
0 |
try { |
174 |
0 |
return new String(contentBytes, charset); |
175 |
|
} catch (UnsupportedEncodingException ex) { |
176 |
0 |
return new String(contentBytes); |
177 |
|
} |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
@link |
184 |
|
|
185 |
|
|
186 |
|
@link |
187 |
|
|
188 |
|
@return |
189 |
|
@throws |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
191 |
1 |
public Version[] getVersions() throws XWikiException... |
192 |
|
{ |
193 |
1 |
this.attachment.loadArchive(getXWikiContext()); |
194 |
1 |
return this.attachment.getVersions(); |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
@return |
204 |
|
@throws |
205 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
0 |
public List<Version> getVersionList() throws XWikiException... |
207 |
|
{ |
208 |
0 |
return this.attachment.getVersionList(); |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
@return |
213 |
|
@see |
214 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
215 |
0 |
public XWikiAttachment getAttachment()... |
216 |
|
{ |
217 |
0 |
if (hasProgrammingRights()) { |
218 |
0 |
return this.attachment; |
219 |
|
} else { |
220 |
0 |
return null; |
221 |
|
} |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
@return |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
127 |
public String getMimeType()... |
228 |
|
{ |
229 |
127 |
return this.attachment.getMimeType(getXWikiContext()); |
230 |
|
} |
231 |
|
|
232 |
|
|
233 |
|
@return |
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
298 |
public boolean isImage()... |
236 |
|
{ |
237 |
298 |
return this.attachment.isImage(getXWikiContext()); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
@param |
244 |
|
@return |
245 |
|
@throws |
246 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
247 |
8 |
public Attachment getAttachmentRevision(String rev) throws XWikiException... |
248 |
|
{ |
249 |
8 |
XWikiAttachment att = this.attachment.getAttachmentRevision(rev, getXWikiContext()); |
250 |
8 |
return att == null ? null : new Attachment(getDocument(), att, this.context); |
251 |
|
} |
252 |
|
} |