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

File AbstractPropChangeAction.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
19
2
1
94
43
6
0.32
9.5
2
3

Classes

Class Line # Actions
AbstractPropChangeAction 36 19 0% 6 27
0.00%
 

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 javax.servlet.http.HttpServletResponse;
23   
24    import com.xpn.xwiki.XWikiContext;
25    import com.xpn.xwiki.XWikiException;
26    import com.xpn.xwiki.doc.XWikiDocument;
27    import com.xpn.xwiki.objects.classes.BaseClass;
28   
29    /**
30    * Base class for manipulating property definitions: disable, enable, delete. The property to alter is specified in the
31    * {@code propname} request parameter, and the class is the one defined in the requested document.
32    *
33    * @version $Id: 7a317415dc4f57a9ef5ae8992f16c826a2b81279 $
34    * @since 2.4M2
35    */
 
36    public abstract class AbstractPropChangeAction extends XWikiAction
37    {
38    /**
39    * Tries to change the specified property, and redirect back to the class editor (or the specified {@code xredirect}
40    * location). If the property does not exist, forward to the exception page.
41    *
42    * @param context the current request context
43    * @return {@code false} if the operation succeeded and the response is finished, {@code true} if the response must
44    * be rendered by {@link #render(XWikiContext)}
45    * @throws XWikiException if saving the document fails
46    */
 
47  0 toggle @Override
48    public boolean action(XWikiContext context) throws XWikiException
49    {
50  0 XWikiResponse response = context.getResponse();
51  0 XWikiDocument doc = context.getDoc();
52  0 PropChangeForm form = (PropChangeForm) context.getForm();
53  0 String propertyName = form.getPropertyName();
54  0 BaseClass xclass = doc.getXClass();
55   
56  0 if (propertyName != null && xclass.get(propertyName) != null) {
57    // CSRF prevention
58  0 if (!csrfTokenCheck(context)) {
59  0 return false;
60    }
61  0 changePropertyDefinition(xclass, propertyName, context);
62    } else {
63  0 return true;
64    }
65   
66  0 if (Utils.isAjaxRequest(context)) {
67  0 response.setStatus(HttpServletResponse.SC_NO_CONTENT);
68  0 response.setContentLength(0);
69    } else {
70  0 String redirect = Utils.getRedirect("edit", "editor=class", context);
71  0 sendRedirect(response, redirect);
72    }
73  0 return false;
74    }
75   
 
76  0 toggle @Override
77    public String render(XWikiContext context) throws XWikiException
78    {
79  0 context.getResponse().setStatus(HttpServletResponse.SC_NOT_FOUND);
80  0 context.put("message", "core.model.xclass.classProperty.error.missingProperty");
81  0 return "exception";
82    }
83   
84    /**
85    * The method which does the actual modification of the property definition.
86    *
87    * @param xclass the affected class
88    * @param propertyName the property to change
89    * @param context the current request context
90    * @throws XWikiException if a storage error occurs
91    */
92    public abstract void changePropertyDefinition(BaseClass xclass, String propertyName, XWikiContext context)
93    throws XWikiException;
94    }