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 org.apache.ecs.xhtml.input; |
23 |
|
import org.slf4j.Logger; |
24 |
|
import org.slf4j.LoggerFactory; |
25 |
|
|
26 |
|
import com.xpn.xwiki.XWikiContext; |
27 |
|
import com.xpn.xwiki.internal.xml.XMLAttributeValueFilter; |
28 |
|
import com.xpn.xwiki.objects.BaseCollection; |
29 |
|
import com.xpn.xwiki.objects.BaseProperty; |
30 |
|
import com.xpn.xwiki.objects.DoubleProperty; |
31 |
|
import com.xpn.xwiki.objects.FloatProperty; |
32 |
|
import com.xpn.xwiki.objects.IntegerProperty; |
33 |
|
import com.xpn.xwiki.objects.LongProperty; |
34 |
|
import com.xpn.xwiki.objects.meta.PropertyMetaClass; |
35 |
|
|
|
|
| 82.5% |
Uncovered Elements: 14 (80) |
Complexity: 25 |
Complexity Density: 0.51 |
|
36 |
|
public class NumberClass extends PropertyClass |
37 |
|
{ |
38 |
|
private static final String XCLASSNAME = "number"; |
39 |
|
|
40 |
|
|
41 |
|
private static final Logger LOG = LoggerFactory.getLogger(NumberClass.class); |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
43 |
2794 |
public NumberClass(PropertyMetaClass wclass)... |
44 |
|
{ |
45 |
2794 |
super(XCLASSNAME, "Number", wclass); |
46 |
2794 |
setSize(30); |
47 |
2794 |
setNumberType("long"); |
48 |
|
} |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
953 |
public NumberClass()... |
51 |
|
{ |
52 |
953 |
this(null); |
53 |
|
} |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
354 |
public int getSize()... |
56 |
|
{ |
57 |
354 |
return getIntValue("size"); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
3941 |
public void setSize(int size)... |
61 |
|
{ |
62 |
3941 |
setIntValue("size", size); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
146786 |
public String getNumberType()... |
66 |
|
{ |
67 |
146791 |
return getStringValue("numberType"); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
4826 |
public void setNumberType(String ntype)... |
71 |
|
{ |
72 |
4826 |
setStringValue("numberType", ntype); |
73 |
|
} |
74 |
|
|
|
|
| 76.5% |
Uncovered Elements: 4 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
75 |
73405 |
@Override... |
76 |
|
public BaseProperty newProperty() |
77 |
|
{ |
78 |
73407 |
String ntype = getNumberType(); |
79 |
73412 |
BaseProperty property; |
80 |
73412 |
if (ntype.equals("integer")) { |
81 |
73224 |
property = new IntegerProperty(); |
82 |
187 |
} else if (ntype.equals("float")) { |
83 |
0 |
property = new FloatProperty(); |
84 |
187 |
} else if (ntype.equals("double")) { |
85 |
0 |
property = new DoubleProperty(); |
86 |
|
} else { |
87 |
187 |
property = new LongProperty(); |
88 |
|
} |
89 |
73412 |
property.setName(getName()); |
90 |
73412 |
return property; |
91 |
|
} |
92 |
|
|
|
|
| 69.7% |
Uncovered Elements: 10 (33) |
Complexity: 13 |
Complexity Density: 0.68 |
|
93 |
73383 |
@Override... |
94 |
|
public BaseProperty fromString(String value) |
95 |
|
{ |
96 |
73383 |
BaseProperty property = newProperty(); |
97 |
73386 |
String ntype = getNumberType(); |
98 |
73387 |
Number nvalue = null; |
99 |
|
|
100 |
73387 |
try { |
101 |
73387 |
if (ntype.equals("integer")) { |
102 |
73217 |
if ((value != null) && (!value.equals(""))) { |
103 |
72551 |
nvalue = Integer.valueOf(value); |
104 |
|
} |
105 |
171 |
} else if (ntype.equals("float")) { |
106 |
0 |
if ((value != null) && (!value.equals(""))) { |
107 |
0 |
nvalue = Float.valueOf(value); |
108 |
|
} |
109 |
171 |
} else if (ntype.equals("double")) { |
110 |
0 |
if ((value != null) && (!value.equals(""))) { |
111 |
0 |
nvalue = Double.valueOf(value); |
112 |
|
} |
113 |
|
} else { |
114 |
171 |
if ((value != null) && (!value.equals(""))) { |
115 |
164 |
nvalue = Long.valueOf(value); |
116 |
|
} |
117 |
|
} |
118 |
|
} catch (NumberFormatException e) { |
119 |
2 |
LOG.warn("Invalid number entered for property " + getName() + " of class " + getObject().getName() + ": " |
120 |
|
+ value); |
121 |
|
|
122 |
2 |
return null; |
123 |
|
} |
124 |
|
|
125 |
73385 |
property.setValue(nvalue); |
126 |
73386 |
return property; |
127 |
|
} |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
129 |
352 |
@Override... |
130 |
|
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) |
131 |
|
{ |
132 |
352 |
input input = new input(); |
133 |
352 |
input.setAttributeFilter(new XMLAttributeValueFilter()); |
134 |
|
|
135 |
352 |
BaseProperty prop = (BaseProperty) object.safeget(name); |
136 |
352 |
if (prop != null) { |
137 |
290 |
input.setValue(prop.toText()); |
138 |
|
} |
139 |
|
|
140 |
352 |
input.setType("text"); |
141 |
352 |
input.setName(prefix + name); |
142 |
352 |
input.setID(prefix + name); |
143 |
352 |
input.setSize(getSize()); |
144 |
352 |
input.setDisabled(isDisabled()); |
145 |
352 |
buffer.append(input.toString()); |
146 |
|
} |
147 |
|
|
148 |
|
} |