1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects.classes; |
21 |
|
|
22 |
|
import java.util.regex.Pattern; |
23 |
|
|
24 |
|
import org.apache.commons.lang3.StringUtils; |
25 |
|
import org.apache.ecs.xhtml.div; |
26 |
|
import org.apache.ecs.xhtml.input; |
27 |
|
import org.apache.ecs.xhtml.label; |
28 |
|
import org.apache.ecs.xhtml.option; |
29 |
|
import org.apache.ecs.xhtml.select; |
30 |
|
import org.xwiki.xml.XMLUtils; |
31 |
|
|
32 |
|
import com.xpn.xwiki.XWikiContext; |
33 |
|
import com.xpn.xwiki.internal.xml.XMLAttributeValueFilter; |
34 |
|
import com.xpn.xwiki.objects.BaseCollection; |
35 |
|
import com.xpn.xwiki.objects.BaseProperty; |
36 |
|
import com.xpn.xwiki.objects.IntegerProperty; |
37 |
|
import com.xpn.xwiki.objects.meta.PropertyMetaClass; |
38 |
|
|
|
|
| 83.3% |
Uncovered Elements: 44 (263) |
Complexity: 57 |
Complexity Density: 0.32 |
|
39 |
|
public class BooleanClass extends PropertyClass |
40 |
|
{ |
41 |
|
private static final String XCLASSNAME = "boolean"; |
42 |
|
|
43 |
|
|
44 |
|
private static final Pattern TRUE_PATTERN = Pattern.compile("yes|true", Pattern.CASE_INSENSITIVE); |
45 |
|
|
46 |
|
|
47 |
|
private static final Pattern FALSE_PATTERN = Pattern.compile("no|false", Pattern.CASE_INSENSITIVE); |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
13669 |
public BooleanClass(PropertyMetaClass wclass)... |
50 |
|
{ |
51 |
13669 |
super(XCLASSNAME, "Boolean", wclass); |
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
54 |
10037 |
public BooleanClass()... |
55 |
|
{ |
56 |
10037 |
this(null); |
57 |
10037 |
setDisplayFormType("select"); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
5096 |
public void setDisplayType(String type)... |
61 |
|
{ |
62 |
5096 |
setStringValue("displayType", type); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
65 |
1945 |
public String getDisplayType()... |
66 |
|
{ |
67 |
1945 |
String dtype = getStringValue("displayType"); |
68 |
1945 |
if ((dtype == null) || (dtype.equals(""))) { |
69 |
160 |
return "yesno"; |
70 |
|
} |
71 |
1785 |
return dtype; |
72 |
|
} |
73 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
74 |
589 |
public String getDisplayFormType()... |
75 |
|
{ |
76 |
589 |
String dtype = getStringValue("displayFormType"); |
77 |
589 |
if ((dtype == null) || (dtype.equals(""))) { |
78 |
0 |
return "radio"; |
79 |
|
} |
80 |
589 |
return dtype; |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
12784 |
public void setDisplayFormType(String type)... |
84 |
|
{ |
85 |
12784 |
setStringValue("displayFormType", type); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
1975 |
public void setDefaultValue(int dvalue)... |
89 |
|
{ |
90 |
1975 |
setIntValue("defaultValue", dvalue); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
601 |
public int getDefaultValue()... |
94 |
|
{ |
95 |
601 |
return getIntValue("defaultValue", -1); |
96 |
|
} |
97 |
|
|
|
|
| 73.7% |
Uncovered Elements: 5 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
|
98 |
104984 |
@Override... |
99 |
|
public BaseProperty fromString(String value) |
100 |
|
{ |
101 |
104985 |
BaseProperty property = newProperty(); |
102 |
104988 |
Number nvalue = null; |
103 |
104987 |
if (StringUtils.isNotEmpty(value)) { |
104 |
104688 |
if (StringUtils.isNumeric(value)) { |
105 |
104681 |
nvalue = Integer.valueOf(value); |
106 |
1 |
} else if (TRUE_PATTERN.matcher(value).matches()) { |
107 |
1 |
nvalue = 1; |
108 |
0 |
} else if (FALSE_PATTERN.matcher(value).matches()) { |
109 |
0 |
nvalue = 0; |
110 |
|
} |
111 |
|
} |
112 |
|
|
113 |
104991 |
property.setValue(nvalue); |
114 |
104991 |
return property; |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
117 |
105125 |
@Override... |
118 |
|
public BaseProperty newProperty() |
119 |
|
{ |
120 |
105127 |
BaseProperty property = new IntegerProperty(); |
121 |
105129 |
property.setName(getName()); |
122 |
105133 |
return property; |
123 |
|
} |
124 |
|
|
|
|
| 81.8% |
Uncovered Elements: 2 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
125 |
62 |
@Override... |
126 |
|
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) |
127 |
|
{ |
128 |
62 |
IntegerProperty prop = (IntegerProperty) object.safeget(name); |
129 |
62 |
if (prop == null) { |
130 |
0 |
return; |
131 |
|
} |
132 |
|
|
133 |
62 |
Integer iValue = (Integer) prop.getValue(); |
134 |
62 |
if (iValue != null) { |
135 |
61 |
int value = iValue.intValue(); |
136 |
61 |
buffer.append(getDisplayValue(context, value)); |
137 |
|
} |
138 |
|
} |
139 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
140 |
532 |
@Override... |
141 |
|
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) |
142 |
|
{ |
143 |
532 |
String displayFormType = getDisplayFormType(); |
144 |
|
|
145 |
532 |
if (getDisplayType().equals("checkbox")) { |
146 |
0 |
displayFormType = "checkbox"; |
147 |
|
} |
148 |
|
|
149 |
532 |
if (displayFormType.equals("checkbox")) { |
150 |
375 |
displayCheckboxEdit(buffer, name, prefix, object, context); |
151 |
157 |
} else if (displayFormType.equals("select")) { |
152 |
152 |
displaySelectEdit(buffer, name, prefix, object, context); |
153 |
|
} else { |
154 |
5 |
displayRadioEdit(buffer, name, prefix, object, context); |
155 |
|
} |
156 |
|
} |
157 |
|
|
|
|
| 94.7% |
Uncovered Elements: 3 (57) |
Complexity: 10 |
Complexity Density: 0.24 |
|
158 |
152 |
public void displaySelectEdit(StringBuffer buffer, String name, String prefix, BaseCollection object,... |
159 |
|
XWikiContext context) |
160 |
|
{ |
161 |
152 |
select select = new select(prefix + name, 1); |
162 |
152 |
select.setAttributeFilter(new XMLAttributeValueFilter()); |
163 |
152 |
select.setName(prefix + name); |
164 |
152 |
select.setID(prefix + name); |
165 |
152 |
select.setDisabled(isDisabled()); |
166 |
|
|
167 |
152 |
String String0 = getDisplayValue(context, 0); |
168 |
152 |
String String1 = getDisplayValue(context, 1); |
169 |
152 |
int nb1 = 1; |
170 |
152 |
int nb2 = 2; |
171 |
|
|
172 |
152 |
option[] options; |
173 |
|
|
174 |
152 |
if (getDefaultValue() == -1) { |
175 |
139 |
options = new option[] { new option("---", ""), new option(String1, "1"), new option(String0, "0") }; |
176 |
139 |
options[0].addElement("---"); |
177 |
139 |
options[1].addElement(XMLUtils.escape(String1)); |
178 |
139 |
options[2].addElement(XMLUtils.escape(String0)); |
179 |
|
} else { |
180 |
13 |
options = new option[] { new option(String1, "1"), new option(String0, "0") }; |
181 |
13 |
options[0].addElement(XMLUtils.escape(String1)); |
182 |
13 |
options[1].addElement(XMLUtils.escape(String0)); |
183 |
13 |
nb1 = 0; |
184 |
13 |
nb2 = 1; |
185 |
|
} |
186 |
|
|
187 |
152 |
for (option option : options) { |
188 |
443 |
option.setAttributeFilter(new XMLAttributeValueFilter()); |
189 |
|
} |
190 |
|
|
191 |
152 |
try { |
192 |
152 |
IntegerProperty prop = (IntegerProperty) object.safeget(name); |
193 |
152 |
Integer ivalue = (prop == null) ? null : (Integer) prop.getValue(); |
194 |
152 |
if (ivalue != null) { |
195 |
13 |
int value = ivalue.intValue(); |
196 |
13 |
if (value == 1) { |
197 |
7 |
options[nb1].setSelected(true); |
198 |
6 |
} else if (value == 0) { |
199 |
6 |
options[nb2].setSelected(true); |
200 |
|
} |
201 |
|
} else { |
202 |
139 |
int value = getDefaultValue(); |
203 |
139 |
if (value == 1) { |
204 |
4 |
options[nb1].setSelected(true); |
205 |
135 |
} else if (value == 0) { |
206 |
1 |
options[nb2].setSelected(true); |
207 |
134 |
} else if (value == -1) { |
208 |
134 |
options[0].setSelected(true); |
209 |
|
} |
210 |
|
} |
211 |
|
} catch (Exception e) { |
212 |
|
|
213 |
0 |
e.printStackTrace(); |
214 |
|
} |
215 |
152 |
select.addElement(options); |
216 |
152 |
buffer.append(select.toString()); |
217 |
|
} |
218 |
|
|
|
|
| 73.6% |
Uncovered Elements: 19 (72) |
Complexity: 10 |
Complexity Density: 0.18 |
|
219 |
5 |
public void displayRadioEdit(StringBuffer buffer, String name, String prefix, BaseCollection object,... |
220 |
|
XWikiContext context) |
221 |
|
{ |
222 |
5 |
String StringNone = getDisplayValue(context, 2); |
223 |
5 |
String StringTrue = getDisplayValue(context, 1); |
224 |
5 |
String StringFalse = getDisplayValue(context, 0); |
225 |
5 |
div[] inputs; |
226 |
|
|
227 |
5 |
input radioNone = new input(input.radio, prefix + name, ""); |
228 |
5 |
radioNone.setAttributeFilter(new XMLAttributeValueFilter()); |
229 |
5 |
input radioTrue = new input(input.radio, prefix + name, "1"); |
230 |
5 |
radioTrue.setAttributeFilter(new XMLAttributeValueFilter()); |
231 |
5 |
input radioFalse = new input(input.radio, prefix + name, "0"); |
232 |
5 |
radioFalse.setAttributeFilter(new XMLAttributeValueFilter()); |
233 |
5 |
radioNone.setDisabled(isDisabled()); |
234 |
5 |
radioTrue.setDisabled(isDisabled()); |
235 |
5 |
radioFalse.setDisabled(isDisabled()); |
236 |
5 |
label labelNone = new label(); |
237 |
5 |
label labelTrue = new label(); |
238 |
5 |
label labelFalse = new label(); |
239 |
5 |
div divNone = new div(); |
240 |
5 |
div divTrue = new div(); |
241 |
5 |
div divFalse = new div(); |
242 |
5 |
labelNone.addElement(radioNone); |
243 |
5 |
labelNone.addElement(StringNone); |
244 |
5 |
divNone.addElement(labelNone); |
245 |
5 |
labelTrue.addElement(radioTrue); |
246 |
5 |
labelTrue.addElement(StringTrue); |
247 |
5 |
divTrue.addElement(labelTrue); |
248 |
5 |
labelFalse.addElement(radioFalse); |
249 |
5 |
labelFalse.addElement(StringFalse); |
250 |
5 |
divFalse.addElement(labelFalse); |
251 |
|
|
252 |
5 |
radioNone.setID(prefix + name + "_none"); |
253 |
5 |
labelNone.setFor(prefix + name + "_none"); |
254 |
|
|
255 |
5 |
radioTrue.setID(prefix + name); |
256 |
5 |
labelTrue.setFor(prefix + name); |
257 |
|
|
258 |
5 |
radioFalse.setID(prefix + name + "_false"); |
259 |
5 |
labelFalse.setFor(prefix + name + "_false"); |
260 |
|
|
261 |
5 |
if (getDefaultValue() == -1) { |
262 |
0 |
inputs = new div[] { divNone, divTrue, divFalse }; |
263 |
|
} else { |
264 |
5 |
inputs = new div[] { divTrue, divFalse }; |
265 |
|
} |
266 |
|
|
267 |
5 |
try { |
268 |
5 |
IntegerProperty prop = (IntegerProperty) object.safeget(name); |
269 |
5 |
Integer ivalue = (prop == null) ? null : (Integer) prop.getValue(); |
270 |
5 |
if (ivalue != null) { |
271 |
5 |
int value = ivalue.intValue(); |
272 |
5 |
if (value == 1) { |
273 |
3 |
radioTrue.setChecked(true); |
274 |
2 |
} else if (value == 0) { |
275 |
2 |
radioFalse.setChecked(true); |
276 |
|
} |
277 |
|
} else { |
278 |
0 |
int value = getDefaultValue(); |
279 |
0 |
if (value == 1) { |
280 |
0 |
radioTrue.setChecked(true); |
281 |
0 |
} else if (value == 0) { |
282 |
0 |
radioFalse.setChecked(true); |
283 |
0 |
} else if (value == -1) { |
284 |
0 |
radioNone.setChecked(true); |
285 |
|
} |
286 |
|
} |
287 |
|
} catch (Exception e) { |
288 |
|
|
289 |
0 |
e.printStackTrace(); |
290 |
|
} |
291 |
|
|
292 |
5 |
for (div input : inputs) { |
293 |
10 |
buffer.append(input.toString()); |
294 |
|
} |
295 |
|
} |
296 |
|
|
|
|
| 72.7% |
Uncovered Elements: 9 (33) |
Complexity: 7 |
Complexity Density: 0.3 |
|
297 |
375 |
public void displayCheckboxEdit(StringBuffer buffer, String name, String prefix, BaseCollection object,... |
298 |
|
XWikiContext context) |
299 |
|
{ |
300 |
375 |
org.apache.ecs.xhtml.input check = new input(input.checkbox, prefix + name, 1); |
301 |
375 |
check.setAttributeFilter(new XMLAttributeValueFilter()); |
302 |
375 |
check.setID(prefix + name); |
303 |
375 |
check.setDisabled(isDisabled()); |
304 |
|
|
305 |
|
|
306 |
375 |
org.apache.ecs.xhtml.input checkNo = new input(input.hidden, prefix + name, 0); |
307 |
375 |
checkNo.setAttributeFilter(new XMLAttributeValueFilter()); |
308 |
|
|
309 |
375 |
try { |
310 |
375 |
IntegerProperty prop = (IntegerProperty) object.safeget(name); |
311 |
375 |
if (prop != null) { |
312 |
256 |
Integer ivalue = (Integer) prop.getValue(); |
313 |
256 |
if (ivalue != null) { |
314 |
256 |
int value = ivalue.intValue(); |
315 |
256 |
if (value == 1) { |
316 |
4 |
check.setChecked(true); |
317 |
252 |
} else if (value == 0) { |
318 |
252 |
check.setChecked(false); |
319 |
|
} |
320 |
|
} else { |
321 |
0 |
int value = getDefaultValue(); |
322 |
0 |
if (value == 1) { |
323 |
0 |
check.setChecked(true); |
324 |
|
} else { |
325 |
0 |
check.setChecked(false); |
326 |
|
} |
327 |
|
} |
328 |
|
} |
329 |
|
} catch (Exception e) { |
330 |
|
|
331 |
0 |
e.printStackTrace(); |
332 |
|
} |
333 |
375 |
buffer.append(check.toString()); |
334 |
375 |
buffer.append(checkNo.toString()); |
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
|
@param |
348 |
|
@param |
349 |
|
@return |
350 |
|
|
|
|
| 89.5% |
Uncovered Elements: 2 (19) |
Complexity: 5 |
Complexity Density: 0.38 |
|
351 |
380 |
private String getDisplayValue(XWikiContext context, int value)... |
352 |
|
{ |
353 |
380 |
try { |
354 |
|
|
355 |
380 |
String key = getFieldFullName() + "_" + value; |
356 |
380 |
String result = localizePlain(key); |
357 |
380 |
if (result == null) { |
358 |
|
|
359 |
377 |
key = getDisplayType() + "_" + value; |
360 |
377 |
result = localizePlain(key); |
361 |
377 |
if (result == null) { |
362 |
|
|
363 |
24 |
if (value == 2) { |
364 |
8 |
result = "---"; |
365 |
|
} else { |
366 |
16 |
result = "" + value; |
367 |
|
} |
368 |
|
} |
369 |
|
} |
370 |
380 |
return result; |
371 |
|
} catch (Exception e) { |
372 |
0 |
e.printStackTrace(); |
373 |
0 |
return "" + value; |
374 |
|
} |
375 |
|
} |
376 |
|
} |