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.util.Calendar; |
23 |
|
import java.util.Date; |
24 |
|
|
25 |
|
import org.slf4j.Logger; |
26 |
|
import org.slf4j.LoggerFactory; |
27 |
|
|
28 |
|
import com.xpn.xwiki.XWikiContext; |
29 |
|
import com.xpn.xwiki.XWikiException; |
30 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
31 |
|
import com.xpn.xwiki.util.Programming; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@link |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 19 |
Complexity Density: 0.5 |
|
43 |
|
public class DeletedAttachment extends Api |
44 |
|
{ |
45 |
|
|
46 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(DeletedAttachment.class); |
47 |
|
|
48 |
|
|
49 |
|
private final com.xpn.xwiki.doc.DeletedAttachment deletedAttachment; |
50 |
|
|
51 |
|
|
52 |
|
@link |
53 |
|
@link |
54 |
|
|
55 |
|
@param |
56 |
|
@param |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
58 |
0 |
public DeletedAttachment(com.xpn.xwiki.doc.DeletedAttachment deletedAttachment, XWikiContext context)... |
59 |
|
{ |
60 |
0 |
super(context); |
61 |
0 |
this.deletedAttachment = deletedAttachment; |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@return |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0 |
public long getId()... |
72 |
|
{ |
73 |
0 |
return this.deletedAttachment.getId(); |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
@return |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
public String getFilename()... |
82 |
|
{ |
83 |
0 |
return this.deletedAttachment.getFilename(); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
@return |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0 |
public String getDocName()... |
92 |
|
{ |
93 |
0 |
return this.deletedAttachment.getDocName(); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
@return |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
0 |
public String getDeleter()... |
102 |
|
{ |
103 |
0 |
return this.deletedAttachment.getDeleter(); |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
@return |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0 |
public Date getDate()... |
112 |
|
{ |
113 |
0 |
return this.deletedAttachment.getDate(); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
@return |
120 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
121 |
0 |
public Attachment getAttachment()... |
122 |
|
{ |
123 |
0 |
try { |
124 |
0 |
Document doc = this.context.getWiki().getDocument(getDocName(), this.context).newDocument(this.context); |
125 |
0 |
return new Attachment(doc, this.deletedAttachment.restoreAttachment(null, this.context), this.context); |
126 |
|
} catch (XWikiException ex) { |
127 |
0 |
LOGGER.warn("Failed to parse deleted attachment: " + ex.getMessage(), ex); |
128 |
0 |
return null; |
129 |
|
} |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
@return |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
137 |
0 |
@Programming... |
138 |
|
public com.xpn.xwiki.doc.DeletedAttachment getDeletedAttachment() |
139 |
|
{ |
140 |
0 |
if (hasProgrammingRights()) { |
141 |
0 |
return this.deletedAttachment; |
142 |
|
} else { |
143 |
0 |
return null; |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
@return |
151 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
152 |
0 |
public boolean canRestore()... |
153 |
|
{ |
154 |
|
|
155 |
|
|
156 |
0 |
return false; |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
@return |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.31 |
|
168 |
0 |
public boolean canDelete()... |
169 |
|
{ |
170 |
0 |
try { |
171 |
0 |
XWikiDocument doc = new XWikiDocument(); |
172 |
0 |
doc.setFullName(getDocName(), this.context); |
173 |
0 |
if (!hasAdminRights() |
174 |
|
&& !getXWikiContext().getWiki().getRightService().checkAccess("delete", doc, this.context)) { |
175 |
0 |
return false; |
176 |
|
} |
177 |
0 |
String waitdays; |
178 |
0 |
if (hasAdminRights()) { |
179 |
0 |
waitdays = getXWikiContext().getWiki().Param("xwiki.store.recyclebin.adminWaitDays", "0"); |
180 |
|
} else { |
181 |
0 |
waitdays = getXWikiContext().getWiki().Param("xwiki.store.recyclebin.waitDays", "7"); |
182 |
|
} |
183 |
0 |
int seconds = (int) (Double.parseDouble(waitdays) * 24 * 60 * 60 + 0.5); |
184 |
0 |
Calendar cal = Calendar.getInstance(); |
185 |
0 |
cal.setTime(getDate()); |
186 |
0 |
cal.add(Calendar.SECOND, seconds); |
187 |
0 |
return cal.before(Calendar.getInstance()); |
188 |
|
} catch (Exception ex) { |
189 |
|
|
190 |
0 |
LOGGER.warn("Exception while checking if entry [" + getId() + "] can be removed from the recycle bin", ex); |
191 |
0 |
return false; |
192 |
|
} |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
@throws |
201 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
202 |
0 |
public void delete() throws XWikiException... |
203 |
|
{ |
204 |
0 |
if (this.canDelete()) { |
205 |
0 |
try { |
206 |
0 |
this.context.getWiki().getAttachmentRecycleBinStore().deleteFromRecycleBin(getId(), this.context, true); |
207 |
|
} catch (Exception ex) { |
208 |
0 |
LOGGER.warn("Failed to purge deleted attachment", ex); |
209 |
|
} |
210 |
|
} else { |
211 |
0 |
java.lang.Object[] args = { this.getFilename(), this.getDocName() }; |
212 |
0 |
throw new XWikiException(XWikiException.MODULE_XWIKI_ACCESS, XWikiException.ERROR_XWIKI_ACCESS_DENIED, |
213 |
|
"Cannot permanently delete attachment {0}@{1} from the trash", null, args); |
214 |
|
} |
215 |
|
} |
216 |
|
} |