1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.web

File AdminAction.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
56% of files have more coverage

Code metrics

28
58
2
1
142
96
25
0.43
29
2
12.5

Classes

Class Line # Actions
AdminAction 35 58 0% 25 20
0.7727272577.3%
 

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 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    * Administration xwiki action.
32    *
33    * @version $Id: 2a7931f9db0a784aa47e432e7f1a115560b83bd5 $
34    */
 
35    public class AdminAction extends XWikiAction
36    {
37    /** The logger. */
38    private static final Logger LOGGER = LoggerFactory.getLogger(AdminAction.class);
39   
40    /**
41    * Default constructor.
42    */
 
43  14 toggle public AdminAction()
44    {
45  14 this.waitForXWikiInitialization = false;
46    }
47   
 
48  380 toggle @Override
49    public String render(XWikiContext context) throws XWikiException
50    {
51  380 XWikiRequest request = context.getRequest();
52  380 String content = request.getParameter("content");
53  380 XWikiDocument doc = context.getDoc();
54  380 XWikiForm form = context.getForm();
55   
56  380 synchronized (doc) {
57  380 XWikiDocument tdoc = (XWikiDocument) context.get("tdoc");
58  380 EditForm peform = (EditForm) form;
59  380 String parent = peform.getParent();
60  380 if (parent != null) {
61  0 doc.setParent(parent);
62    }
63  380 String creator = peform.getCreator();
64  380 if (creator != null) {
65  0 doc.setCreator(creator);
66    }
67  380 String defaultTemplate = peform.getDefaultTemplate();
68  380 if (defaultTemplate != null) {
69  0 doc.setDefaultTemplate(defaultTemplate);
70    }
71  380 String defaultLanguage = peform.getDefaultLanguage();
72  380 if ((defaultLanguage != null) && !defaultLanguage.equals("")) {
73  0 doc.setDefaultLanguage(defaultLanguage);
74    }
75  380 if (doc.getDefaultLanguage().equals("")) {
76  47 doc.setDefaultLanguage(context.getWiki().getLanguagePreference(context));
77    }
78   
79  380 String language = context.getWiki().getLanguagePreference(context);
80  380 String languagefromrequest = context.getRequest().getParameter("language");
81  380 String languagetoedit =
82  380 ((languagefromrequest == null) || (languagefromrequest.equals(""))) ? language : languagefromrequest;
83   
84  380 if ((languagetoedit == null) || (languagetoedit.equals("default"))) {
85  0 languagetoedit = "";
86    }
87  380 if (doc.isNew() || (doc.getDefaultLanguage().equals(languagetoedit))) {
88  370 languagetoedit = "";
89    }
90   
91  380 if (languagetoedit.equals("")) {
92    // In this case the created document is going to be the default document
93  370 tdoc = doc;
94  370 context.put("tdoc", doc);
95  370 if (doc.isNew()) {
96  9 doc.setDefaultLanguage(language);
97  9 doc.setLanguage("");
98    }
99    } else {
100    // If the translated doc object is the same as the doc object
101    // this means the translated doc did not exists so we need to create it
102  10 if ((tdoc == doc)) {
103  10 tdoc = new XWikiDocument(doc.getDocumentReference());
104  10 tdoc.setLanguage(languagetoedit);
105  10 tdoc.setContent(doc.getContent());
106  10 tdoc.setSyntax(doc.getSyntax());
107  10 tdoc.setAuthor(context.getUser());
108  10 tdoc.setStore(doc.getStore());
109  10 context.put("tdoc", tdoc);
110    }
111    }
112   
113  380 XWikiDocument tdoc2 = tdoc.clone();
114  380 if (content != null && !content.isEmpty()) {
115  0 tdoc2.setContent(content);
116    }
117  380 context.put("tdoc", tdoc2);
118  380 try {
119  380 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    /* Setup a lock */
128  380 try {
129  380 XWikiLock lock = tdoc.getLock(context);
130  380 if ((lock == null) || (lock.getUserName().equals(context.getUser())) || (peform.isLockForce())) {
131  380 tdoc.setLock(context.getUser(), context);
132    }
133    } catch (Exception e) {
134    // Lock should never make XWiki fail
135    // But we should log any related information
136  0 LOGGER.error("Exception while setting up lock", e);
137    }
138    }
139   
140  380 return "admin";
141    }
142    }