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.io.IOException; |
23 |
|
|
24 |
|
import javax.script.ScriptContext; |
25 |
|
import javax.servlet.http.HttpServletResponse; |
26 |
|
|
27 |
|
import org.apache.commons.lang3.StringUtils; |
28 |
|
|
29 |
|
import com.xpn.xwiki.XWiki; |
30 |
|
import com.xpn.xwiki.XWikiContext; |
31 |
|
import com.xpn.xwiki.XWikiException; |
32 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
33 |
|
import com.xpn.xwiki.objects.BaseObject; |
34 |
|
|
|
|
| 55.4% |
Uncovered Elements: 25 (56) |
Complexity: 11 |
Complexity Density: 0.28 |
|
35 |
|
public class ObjectRemoveAction extends XWikiAction |
36 |
|
{ |
|
|
| 66.7% |
Uncovered Elements: 6 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
37 |
1 |
protected BaseObject getObject(XWikiDocument doc, XWikiContext context)... |
38 |
|
{ |
39 |
1 |
ObjectRemoveForm form = (ObjectRemoveForm) context.getForm(); |
40 |
1 |
BaseObject obj = null; |
41 |
|
|
42 |
1 |
String className = form.getClassName(); |
43 |
1 |
int classId = form.getClassId(); |
44 |
1 |
if (StringUtils.isBlank(className)) { |
45 |
0 |
getCurrentScriptContext().setAttribute("message", |
46 |
|
localizePlainOrKey("platform.core.action.objectRemove.noClassnameSpecified"), |
47 |
|
ScriptContext.ENGINE_SCOPE); |
48 |
1 |
} else if (classId < 0) { |
49 |
0 |
getCurrentScriptContext().setAttribute("message", |
50 |
|
localizePlainOrKey("platform.core.action.objectRemove.noObjectSpecified"), ScriptContext.ENGINE_SCOPE); |
51 |
|
} else { |
52 |
1 |
obj = doc.getObject(className, classId); |
53 |
1 |
if (obj == null) { |
54 |
0 |
getCurrentScriptContext().setAttribute("message", |
55 |
|
localizePlainOrKey("platform.core.action.objectRemove.invalidObject"), ScriptContext.ENGINE_SCOPE); |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
1 |
return obj; |
60 |
|
} |
61 |
|
|
|
|
| 70.8% |
Uncovered Elements: 7 (24) |
Complexity: 4 |
Complexity Density: 0.22 |
|
62 |
1 |
@Override... |
63 |
|
public boolean action(XWikiContext context) throws XWikiException |
64 |
|
{ |
65 |
|
|
66 |
1 |
if (!csrfTokenCheck(context)) { |
67 |
0 |
return false; |
68 |
|
} |
69 |
|
|
70 |
1 |
XWiki xwiki = context.getWiki(); |
71 |
1 |
XWikiResponse response = context.getResponse(); |
72 |
1 |
String username = context.getUser(); |
73 |
1 |
XWikiDocument doc = context.getDoc(); |
74 |
1 |
BaseObject obj = getObject(doc, context); |
75 |
1 |
if (obj == null) { |
76 |
0 |
return true; |
77 |
|
} |
78 |
|
|
79 |
1 |
doc.removeObject(obj); |
80 |
1 |
doc.setAuthor(username); |
81 |
1 |
xwiki.saveDocument(doc, localizePlainOrKey("core.comment.deleteObject"), true, context); |
82 |
|
|
83 |
1 |
if (Utils.isAjaxRequest(context)) { |
84 |
1 |
response.setStatus(HttpServletResponse.SC_NO_CONTENT); |
85 |
1 |
response.setContentLength(0); |
86 |
|
} else { |
87 |
|
|
88 |
0 |
String redirect = Utils.getRedirect("edit", context); |
89 |
0 |
sendRedirect(response, redirect); |
90 |
|
} |
91 |
1 |
return false; |
92 |
|
} |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
94 |
0 |
@Override... |
95 |
|
public String render(XWikiContext context) throws XWikiException |
96 |
|
{ |
97 |
0 |
if (Utils.isAjaxRequest(context)) { |
98 |
0 |
XWikiResponse response = context.getResponse(); |
99 |
0 |
response.setStatus(HttpServletResponse.SC_CONFLICT); |
100 |
0 |
response.setContentType("text/plain"); |
101 |
0 |
try { |
102 |
0 |
response.getWriter().write("failed"); |
103 |
0 |
response.setContentLength(6); |
104 |
|
} catch (IOException e) { |
105 |
|
} |
106 |
0 |
return null; |
107 |
|
} else { |
108 |
0 |
return "error"; |
109 |
|
} |
110 |
|
} |
111 |
|
} |