1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.web; |
21 |
|
|
22 |
|
import javax.script.ScriptContext; |
23 |
|
|
24 |
|
import org.xwiki.model.EntityType; |
25 |
|
import org.xwiki.resource.ResourceReference; |
26 |
|
import org.xwiki.resource.ResourceReferenceManager; |
27 |
|
import org.xwiki.resource.entity.EntityResourceReference; |
28 |
|
|
29 |
|
import com.xpn.xwiki.XWikiContext; |
30 |
|
import com.xpn.xwiki.XWikiException; |
31 |
|
import com.xpn.xwiki.api.Attachment; |
32 |
|
import com.xpn.xwiki.api.Document; |
33 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
34 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
35 |
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 8 |
Complexity Density: 0.31 |
|
36 |
|
public class ViewAttachRevAction extends XWikiAction |
37 |
|
{ |
38 |
|
|
39 |
|
|
40 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
41 |
0 |
public ViewAttachRevAction()... |
42 |
|
{ |
43 |
0 |
this.waitForXWikiInitialization = false; |
44 |
0 |
this.handleRedirectObject = true; |
45 |
|
} |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 6 |
Complexity Density: 0.29 |
|
47 |
0 |
@Override... |
48 |
|
public String render(XWikiContext context) throws XWikiException |
49 |
|
{ |
50 |
0 |
XWikiRequest request = context.getRequest(); |
51 |
0 |
XWikiDocument doc = context.getDoc(); |
52 |
0 |
String filename; |
53 |
0 |
if (context.getMode() == XWikiContext.MODE_PORTLET) { |
54 |
0 |
filename = request.getParameter("filename"); |
55 |
|
} else { |
56 |
0 |
filename = getFileName(); |
57 |
|
} |
58 |
|
|
59 |
0 |
XWikiAttachment attachment; |
60 |
|
|
61 |
0 |
if (context.getWiki().hasAttachmentRecycleBin(context) && request.getParameter("rid") != null) { |
62 |
0 |
int recycleId = Integer.parseInt(request.getParameter("rid")); |
63 |
0 |
attachment = new XWikiAttachment(doc, filename); |
64 |
0 |
attachment = context.getWiki().getAttachmentRecycleBinStore().restoreFromRecycleBin(attachment, recycleId, |
65 |
|
context, true); |
66 |
0 |
} else if (request.getParameter("id") != null) { |
67 |
0 |
int id = Integer.parseInt(request.getParameter("id")); |
68 |
0 |
attachment = doc.getAttachmentList().get(id); |
69 |
|
} else { |
70 |
0 |
attachment = doc.getAttachment(filename); |
71 |
0 |
if (attachment == null) { |
72 |
0 |
context.put("message", "attachmentdoesnotexist"); |
73 |
0 |
return "exception"; |
74 |
|
} |
75 |
|
} |
76 |
|
|
77 |
0 |
ScriptContext scriptContext = getCurrentScriptContext(); |
78 |
0 |
scriptContext.setAttribute("attachment", |
79 |
|
new Attachment((Document) scriptContext.getAttribute("doc"), attachment, context), |
80 |
|
ScriptContext.ENGINE_SCOPE); |
81 |
|
|
82 |
0 |
return "viewattachrev"; |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
@return |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
88 |
0 |
private String getFileName()... |
89 |
|
{ |
90 |
|
|
91 |
0 |
ResourceReference resourceReference = Utils.getComponent(ResourceReferenceManager.class).getResourceReference(); |
92 |
0 |
EntityResourceReference entityResource = (EntityResourceReference) resourceReference; |
93 |
0 |
return entityResource.getEntityReference().extractReference(EntityType.ATTACHMENT).getName(); |
94 |
|
} |
95 |
|
} |