1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
|
|
| 30.8% |
Uncovered Elements: 36 (52) |
Complexity: 19 |
Complexity Density: 0.61 |
|
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 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
44 |
1 |
public XWikiValidationStatus()... |
45 |
|
{ |
46 |
|
} |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
48 |
0 |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
56 |
2 |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
66 |
2 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
72 |
0 |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
2 |
public void addException(String className, String propName, Throwable e, XWikiContext context)... |
97 |
|
{ |
98 |
2 |
getExceptions().add(e); |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
0 |
public boolean hasExceptions()... |
102 |
|
{ |
103 |
0 |
return (getExceptions().size() > 0); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
106 |
2 |
public List getExceptions()... |
107 |
|
{ |
108 |
2 |
return this.exceptions; |
109 |
|
} |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0 |
public List getErrorObjects()... |
112 |
|
{ |
113 |
0 |
return this.errorObjects; |
114 |
|
} |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
0 |
public void setErrorObjects(List errorObjects)... |
117 |
|
{ |
118 |
0 |
this.errorObjects = errorObjects; |
119 |
|
} |
120 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
121 |
0 |
public List getPropertyErrors()... |
122 |
|
{ |
123 |
0 |
return this.propertyErrors; |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0 |
public void setPropertyErrors(List propertyErrors)... |
127 |
|
{ |
128 |
0 |
this.propertyErrors = propertyErrors; |
129 |
|
} |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
131 |
0 |
public List getErrors()... |
132 |
|
{ |
133 |
0 |
return this.errors; |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0 |
public void setErrors(List errors)... |
137 |
|
{ |
138 |
0 |
this.errors = errors; |
139 |
|
} |
140 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
0 |
public void setExceptions(List exceptions)... |
142 |
|
{ |
143 |
0 |
this.exceptions = exceptions; |
144 |
|
} |
145 |
|
} |