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

File InlineAction.java

 

Coverage histogram

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

Code metrics

18
41
1
1
118
72
15
0.37
41
1
15

Classes

Class Line # Actions
InlineAction 34 41 0% 15 17
0.7166666471.7%
 

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    * @deprecated use {@link EditAction} with {@code editor=inline} in the query string instead since 3.2
32    */
33    @Deprecated
 
34    public class InlineAction extends XWikiAction
35    {
36    private static final Logger LOGGER = LoggerFactory.getLogger(InlineAction.class);
37   
 
38  9 toggle @Override
39    public String render(XWikiContext context) throws XWikiException
40    {
41  9 XWikiDocument doc = context.getDoc();
42   
43  9 synchronized (doc) {
44  9 XWikiForm form = context.getForm();
45   
46  9 XWikiDocument cdoc = (XWikiDocument) context.get("cdoc");
47  9 if (cdoc == null) {
48  0 cdoc = doc;
49    }
50   
51  9 EditForm peform = (EditForm) form;
52   
53  9 XWikiDocument doc2 = doc.clone();
54  9 context.put("doc", doc2);
55   
56  9 String parent = peform.getParent();
57  9 if (parent != null) {
58  6 doc2.setParent(parent);
59    }
60  9 String creator = peform.getCreator();
61  9 if (creator != null) {
62  0 doc2.setCreator(creator);
63    }
64  9 String defaultLanguage = peform.getDefaultLanguage();
65  9 if ((defaultLanguage != null) && !defaultLanguage.equals("")) {
66  0 doc2.setDefaultLanguage(defaultLanguage);
67    }
68  9 if (doc2.getDefaultLanguage().equals("")) {
69  9 doc2.setDefaultLanguage(context.getWiki().getLanguagePreference(context));
70    }
71  9 try {
72  9 doc2.readFromTemplate(peform, context);
73    } catch (XWikiException e) {
74  0 if (e.getCode() == XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY) {
75  0 return "docalreadyexists";
76    }
77    }
78   
79  9 if (doc == cdoc) {
80  9 context.put("cdoc", doc2);
81    } else {
82  0 XWikiDocument cdoc2 = cdoc.clone();
83  0 cdoc2.readFromTemplate(peform, context);
84  0 context.put("cdoc", cdoc2);
85    }
86   
87  9 doc2.readFromForm((EditForm) form, context);
88   
89    // Set the current user as creator, author and contentAuthor when the edited document is newly created
90    // to avoid using XWikiGuest instead (because those fields were not previously initialized).
91    // This is needed for the script right, as guest doesn't have it and this would block the execution of
92    // scripts in newly created documents even if the user creating the document has the right.
93  9 if (doc2.isNew()) {
94  6 doc2.setCreatorReference(context.getUserReference());
95  6 doc2.setAuthorReference(context.getUserReference());
96  6 doc2.setContentAuthorReference(context.getUserReference());
97    }
98   
99    /* Setup a lock */
100  9 try {
101  9 XWikiLock lock = doc.getLock(context);
102  9 if ((lock == null) || (lock.getUserName().equals(context.getUser())) || (peform.isLockForce())) {
103  9 doc.setLock(context.getUser(), context);
104    }
105    } catch (Exception e) {
106    // Lock should never make XWiki fail
107    // But we should log any related information
108  0 LOGGER.error("Exception while setting up lock", e);
109    }
110    }
111   
112    // Make sure object property fields are displayed in edit mode.
113    // See XWikiDocument#display(String, BaseObject, XWikiContext)
114  9 context.put("display", "edit");
115   
116  9 return "inline";
117    }
118    }