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 org.slf4j.Logger; |
23 |
|
import org.slf4j.LoggerFactory; |
24 |
|
|
25 |
|
import com.xpn.xwiki.XWikiContext; |
26 |
|
import com.xpn.xwiki.XWikiException; |
27 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
28 |
|
import com.xpn.xwiki.doc.XWikiLock; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
@version |
34 |
|
|
|
|
| 63.6% |
Uncovered Elements: 32 (88) |
Complexity: 25 |
Complexity Density: 0.43 |
|
35 |
|
public class AdminAction extends XWikiAction |
36 |
|
{ |
37 |
|
|
38 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(AdminAction.class); |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
43 |
8 |
public AdminAction()... |
44 |
|
{ |
45 |
8 |
this.waitForXWikiInitialization = false; |
46 |
|
} |
47 |
|
|
|
|
| 62.4% |
Uncovered Elements: 32 (85) |
Complexity: 24 |
Complexity Density: 0.42 |
|
48 |
146 |
@Override... |
49 |
|
public String render(XWikiContext context) throws XWikiException |
50 |
|
{ |
51 |
146 |
XWikiRequest request = context.getRequest(); |
52 |
146 |
String content = request.getParameter("content"); |
53 |
146 |
XWikiDocument doc = context.getDoc(); |
54 |
146 |
XWikiForm form = context.getForm(); |
55 |
|
|
56 |
146 |
synchronized (doc) { |
57 |
146 |
XWikiDocument tdoc = (XWikiDocument) context.get("tdoc"); |
58 |
146 |
EditForm peform = (EditForm) form; |
59 |
146 |
String parent = peform.getParent(); |
60 |
146 |
if (parent != null) { |
61 |
0 |
doc.setParent(parent); |
62 |
|
} |
63 |
146 |
String creator = peform.getCreator(); |
64 |
146 |
if (creator != null) { |
65 |
0 |
doc.setCreator(creator); |
66 |
|
} |
67 |
146 |
String defaultTemplate = peform.getDefaultTemplate(); |
68 |
146 |
if (defaultTemplate != null) { |
69 |
0 |
doc.setDefaultTemplate(defaultTemplate); |
70 |
|
} |
71 |
146 |
String defaultLanguage = peform.getDefaultLanguage(); |
72 |
146 |
if ((defaultLanguage != null) && !defaultLanguage.equals("")) { |
73 |
0 |
doc.setDefaultLanguage(defaultLanguage); |
74 |
|
} |
75 |
146 |
if (doc.getDefaultLanguage().equals("")) { |
76 |
12 |
doc.setDefaultLanguage(context.getWiki().getLanguagePreference(context)); |
77 |
|
} |
78 |
|
|
79 |
146 |
String language = context.getWiki().getLanguagePreference(context); |
80 |
146 |
String languagefromrequest = context.getRequest().getParameter("language"); |
81 |
146 |
String languagetoedit = |
82 |
146 |
((languagefromrequest == null) || (languagefromrequest.equals(""))) ? language : languagefromrequest; |
83 |
|
|
84 |
146 |
if ((languagetoedit == null) || (languagetoedit.equals("default"))) { |
85 |
0 |
languagetoedit = ""; |
86 |
|
} |
87 |
146 |
if (doc.isNew() || (doc.getDefaultLanguage().equals(languagetoedit))) { |
88 |
146 |
languagetoedit = ""; |
89 |
|
} |
90 |
|
|
91 |
146 |
if (languagetoedit.equals("")) { |
92 |
|
|
93 |
146 |
tdoc = doc; |
94 |
146 |
context.put("tdoc", doc); |
95 |
146 |
if (doc.isNew()) { |
96 |
4 |
doc.setDefaultLanguage(language); |
97 |
4 |
doc.setLanguage(""); |
98 |
|
} |
99 |
|
} else { |
100 |
|
|
101 |
|
|
102 |
0 |
if ((tdoc == doc)) { |
103 |
0 |
tdoc = new XWikiDocument(doc.getDocumentReference()); |
104 |
0 |
tdoc.setLanguage(languagetoedit); |
105 |
0 |
tdoc.setContent(doc.getContent()); |
106 |
0 |
tdoc.setSyntax(doc.getSyntax()); |
107 |
0 |
tdoc.setAuthor(context.getUser()); |
108 |
0 |
tdoc.setStore(doc.getStore()); |
109 |
0 |
context.put("tdoc", tdoc); |
110 |
|
} |
111 |
|
} |
112 |
|
|
113 |
146 |
XWikiDocument tdoc2 = tdoc.clone(); |
114 |
146 |
if (content != null && !content.isEmpty()) { |
115 |
0 |
tdoc2.setContent(content); |
116 |
|
} |
117 |
146 |
context.put("tdoc", tdoc2); |
118 |
146 |
try { |
119 |
146 |
tdoc2.readFromTemplate(peform, context); |
120 |
|
} catch (XWikiException e) { |
121 |
0 |
if (e.getCode() == XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY) { |
122 |
0 |
context.put("exception", e); |
123 |
0 |
return "docalreadyexists"; |
124 |
|
} |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
146 |
try { |
129 |
146 |
XWikiLock lock = tdoc.getLock(context); |
130 |
146 |
if ((lock == null) || (lock.getUserName().equals(context.getUser())) || (peform.isLockForce())) { |
131 |
146 |
tdoc.setLock(context.getUser(), context); |
132 |
|
} |
133 |
|
} catch (Exception e) { |
134 |
|
|
135 |
|
|
136 |
0 |
LOGGER.error("Exception while setting up lock", e); |
137 |
|
} |
138 |
|
} |
139 |
|
|
140 |
146 |
return "admin"; |
141 |
|
} |
142 |
|
} |