1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.web

File ViewAttachRevAction.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

8
26
3
1
95
59
8
0.31
8.67
3
2.67

Classes

Class Line # Actions
ViewAttachRevAction 36 26 0% 8 37
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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   
 
36    public class ViewAttachRevAction extends XWikiAction
37    {
38    /**
39    * Default constructor.
40    */
 
41  0 toggle public ViewAttachRevAction()
42    {
43  0 this.waitForXWikiInitialization = false;
44  0 this.handleRedirectObject = true;
45    }
46   
 
47  0 toggle @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 the filename of the attachment.
87    */
 
88  0 toggle private String getFileName()
89    {
90    // Extract the Attachment file name from the parsed request URL that was done before this Action is called
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    }