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 java.util.Locale; |
23 |
|
|
24 |
|
import org.apache.commons.lang3.StringUtils; |
25 |
|
import org.xwiki.localization.LocaleUtils; |
26 |
|
import org.xwiki.model.reference.DocumentReference; |
27 |
|
|
28 |
|
import com.xpn.xwiki.XWiki; |
29 |
|
import com.xpn.xwiki.XWikiContext; |
30 |
|
import com.xpn.xwiki.XWikiException; |
31 |
|
import com.xpn.xwiki.doc.XWikiDeletedDocument; |
32 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
|
|
| 90.6% |
Uncovered Elements: 3 (32) |
Complexity: 7 |
Complexity Density: 0.33 |
|
40 |
|
public class UndeleteAction extends XWikiAction |
41 |
|
{ |
|
|
| 90.3% |
Uncovered Elements: 3 (31) |
Complexity: 7 |
Complexity Density: 0.33 |
|
42 |
7 |
@Override... |
43 |
|
public boolean action(XWikiContext context) throws XWikiException |
44 |
|
{ |
45 |
|
|
46 |
7 |
if (!csrfTokenCheck(context)) { |
47 |
1 |
return false; |
48 |
|
} |
49 |
|
|
50 |
6 |
XWiki xwiki = context.getWiki(); |
51 |
6 |
XWikiRequest request = context.getRequest(); |
52 |
6 |
XWikiResponse response = context.getResponse(); |
53 |
6 |
XWikiDocument doc = context.getDoc(); |
54 |
6 |
String deletedDocumentLanguage = null; |
55 |
|
|
56 |
6 |
if (xwiki.hasRecycleBin(context)) { |
57 |
5 |
String sindex = request.getParameter("id"); |
58 |
5 |
long index = Long.parseLong(sindex); |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
5 |
XWikiDeletedDocument deletedDocument = |
63 |
|
xwiki.getDeletedDocument(StringUtils.EMPTY, StringUtils.EMPTY, (int) index, context); |
64 |
5 |
if (deletedDocument != null) { |
65 |
5 |
deletedDocumentLanguage = deletedDocument.getLanguage(); |
66 |
|
|
67 |
|
|
68 |
5 |
DocumentReference translatedDocumentReference = |
69 |
|
new DocumentReference(doc.getDocumentReference(), LocaleUtils.toLocale(deletedDocumentLanguage, |
70 |
|
Locale.ROOT)); |
71 |
5 |
if (!xwiki.exists(translatedDocumentReference, context)) { |
72 |
4 |
xwiki.restoreFromRecycleBin(doc, index, "Restored from recycle bin", context); |
73 |
|
} |
74 |
|
} |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
6 |
String queryString = null; |
79 |
6 |
if (deletedDocumentLanguage != null && xwiki.isMultiLingual(context)) { |
80 |
0 |
queryString = String.format("language=%s", deletedDocumentLanguage); |
81 |
|
} |
82 |
6 |
sendRedirect(response, doc.getURL("view", queryString, context)); |
83 |
|
|
84 |
6 |
return false; |
85 |
|
} |
86 |
|
} |