1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.web

File InlineAction.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
64% 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 19
0.6833333468.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    * @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  4 toggle @Override
39    public String render(XWikiContext context) throws XWikiException
40    {
41  4 XWikiDocument doc = context.getDoc();
42   
43  4 synchronized (doc) {
44  4 XWikiForm form = context.getForm();
45   
46  4 XWikiDocument cdoc = (XWikiDocument) context.get("cdoc");
47  4 if (cdoc == null) {
48  0 cdoc = doc;
49    }
50   
51  4 EditForm peform = (EditForm) form;
52   
53  4 XWikiDocument doc2 = doc.clone();
54  4 context.put("doc", doc2);
55   
56  4 String parent = peform.getParent();
57  4 if (parent != null) {
58  4 doc2.setParent(parent);
59    }
60  4 String creator = peform.getCreator();
61  4 if (creator != null) {
62  0 doc2.setCreator(creator);
63    }
64  4 String defaultLanguage = peform.getDefaultLanguage();
65  4 if ((defaultLanguage != null) && !defaultLanguage.equals("")) {
66  0 doc2.setDefaultLanguage(defaultLanguage);
67    }
68  4 if (doc2.getDefaultLanguage().equals("")) {
69  4 doc2.setDefaultLanguage(context.getWiki().getLanguagePreference(context));
70    }
71  4 try {
72  4 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  4 if (doc == cdoc) {
80  4 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  4 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  4 if (doc2.isNew()) {
94  4 doc2.setCreatorReference(context.getUserReference());
95  4 doc2.setAuthorReference(context.getUserReference());
96  4 doc2.setContentAuthorReference(context.getUserReference());
97    }
98   
99    /* Setup a lock */
100  4 try {
101  4 XWikiLock lock = doc.getLock(context);
102  4 if ((lock == null) || (lock.getUserName().equals(context.getUser())) || (peform.isLockForce())) {
103  4 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  4 context.put("display", "edit");
115   
116  4 return "inline";
117    }
118    }