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

File XWikiValidationStatus.java

 

Coverage histogram

../../../../img/srcFileCovDistChart3.png
80% of files have more coverage

Code metrics

6
31
15
1
145
98
19
0.61
2.07
15
1.27

Classes

Class Line # Actions
XWikiValidationStatus 33 31 0% 19 36
0.3076923230.8%
 

Contributing tests

This file is covered by 1 test. .

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.validation;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.List;
25   
26    import javax.script.ScriptContext;
27   
28    import org.xwiki.script.ScriptContextManager;
29   
30    import com.xpn.xwiki.XWikiContext;
31    import com.xpn.xwiki.web.Utils;
32   
 
33    public class XWikiValidationStatus
34    {
35   
36    private List errorObjects = new ArrayList();
37   
38    private List propertyErrors = new ArrayList();
39   
40    private List errors = new ArrayList();
41   
42    private List exceptions = new ArrayList();
43   
 
44  1 toggle public XWikiValidationStatus()
45    {
46    }
47   
 
48  0 toggle public static void addErrorToContext(String className, String propName, String propPrettyName,
49    String validationMessage, XWikiContext context)
50    {
51  0 XWikiValidationStatus errors = getValidationStatus(context);
52  0 errors.addError(className, propName, propPrettyName, validationMessage, context);
53   
54    }
55   
 
56  2 toggle private static XWikiValidationStatus getValidationStatus(XWikiContext context)
57    {
58  2 XWikiValidationStatus errors = context.getValidationStatus();
59  2 if (errors == null) {
60  1 errors = new XWikiValidationStatus();
61  1 context.setValidationStatus(errors);
62    }
63  2 return errors;
64    }
65   
 
66  2 toggle public static void addExceptionToContext(String className, String propName, Throwable e, XWikiContext context)
67    {
68  2 XWikiValidationStatus errors = getValidationStatus(context);
69  2 errors.addException(className, propName, e, context);
70    }
71   
 
72  0 toggle public void addError(String className, String propName, String propPrettyName, String validationMessage,
73    XWikiContext context)
74    {
75  0 getErrorObjects().add(className);
76  0 getPropertyErrors().add(propName);
77   
78  0 if ((validationMessage != null) && (!validationMessage.trim().equals(""))) {
79  0 getErrors().add(validationMessage);
80    } else {
81  0 ScriptContextManager scriptManager = Utils.getComponent(ScriptContextManager.class);
82  0 ScriptContext scontext = scriptManager.getCurrentScriptContext();
83   
84  0 if (scontext == null) {
85  0 getErrors().add("Validation error for property " + propPrettyName + " in class " + className);
86    } else {
87  0 scontext.setAttribute("className", className, ScriptContext.ENGINE_SCOPE);
88  0 scontext.setAttribute("propName", propPrettyName, ScriptContext.ENGINE_SCOPE);
89   
90  0 String message = context.getMessageTool().get("validationerror", Collections.singletonList(propName));
91  0 getErrors().add(message);
92    }
93    }
94    }
95   
 
96  2 toggle public void addException(String className, String propName, Throwable e, XWikiContext context)
97    {
98  2 getExceptions().add(e);
99    }
100   
 
101  0 toggle public boolean hasExceptions()
102    {
103  0 return (getExceptions().size() > 0);
104    }
105   
 
106  2 toggle public List getExceptions()
107    {
108  2 return this.exceptions;
109    }
110   
 
111  0 toggle public List getErrorObjects()
112    {
113  0 return this.errorObjects;
114    }
115   
 
116  0 toggle public void setErrorObjects(List errorObjects)
117    {
118  0 this.errorObjects = errorObjects;
119    }
120   
 
121  0 toggle public List getPropertyErrors()
122    {
123  0 return this.propertyErrors;
124    }
125   
 
126  0 toggle public void setPropertyErrors(List propertyErrors)
127    {
128  0 this.propertyErrors = propertyErrors;
129    }
130   
 
131  0 toggle public List getErrors()
132    {
133  0 return this.errors;
134    }
135   
 
136  0 toggle public void setErrors(List errors)
137    {
138  0 this.errors = errors;
139    }
140   
 
141  0 toggle public void setExceptions(List exceptions)
142    {
143  0 this.exceptions = exceptions;
144    }
145    }