1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.internal.resources.attachments; |
21 |
|
|
22 |
|
import javax.inject.Named; |
23 |
|
import javax.ws.rs.WebApplicationException; |
24 |
|
import javax.ws.rs.core.Response; |
25 |
|
import javax.ws.rs.core.Response.Status; |
26 |
|
|
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.rest.XWikiResource; |
29 |
|
import org.xwiki.rest.XWikiRestException; |
30 |
|
import org.xwiki.rest.resources.attachments.AttachmentVersionResource; |
31 |
|
|
32 |
|
import com.xpn.xwiki.XWikiException; |
33 |
|
import com.xpn.xwiki.api.Document; |
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
|
38 |
|
@Component |
39 |
|
@Named("org.xwiki.rest.internal.resources.attachments.AttachmentVersionResourceImpl") |
|
|
| 68.8% |
Uncovered Elements: 5 (16) |
Complexity: 4 |
Complexity Density: 0.36 |
|
40 |
|
public class AttachmentVersionResourceImpl extends XWikiResource implements AttachmentVersionResource |
41 |
|
{ |
|
|
| 66.7% |
Uncovered Elements: 5 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
42 |
4 |
@Override... |
43 |
|
public Response getAttachment(String wikiName, String spaceName, String pageName, String attachmentName, |
44 |
|
String attachmentVersion) throws XWikiRestException |
45 |
|
{ |
46 |
4 |
try { |
47 |
4 |
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false); |
48 |
4 |
Document doc = documentInfo.getDocument(); |
49 |
|
|
50 |
4 |
com.xpn.xwiki.api.Attachment xwikiAttachment = doc.getAttachment(attachmentName); |
51 |
4 |
if (xwikiAttachment == null) { |
52 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
4 |
final com.xpn.xwiki.api.Attachment xwikiAttachmentVersion = |
57 |
|
xwikiAttachment.getAttachmentRevision(attachmentVersion); |
58 |
4 |
if (xwikiAttachmentVersion == null) { |
59 |
0 |
throw new WebApplicationException(Status.NOT_FOUND); |
60 |
|
} |
61 |
|
|
62 |
4 |
return Response.ok().type(xwikiAttachment.getMimeType()).entity(xwikiAttachmentVersion.getContent()) |
63 |
|
.build(); |
64 |
|
} catch (XWikiException e) { |
65 |
0 |
throw new XWikiRestException(e); |
66 |
|
} |
67 |
|
} |
68 |
|
} |