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.ArrayList; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import org.apache.commons.lang3.StringUtils; |
29 |
|
import org.apache.ecs.xhtml.input; |
30 |
|
import org.apache.ecs.xhtml.option; |
31 |
|
import org.apache.ecs.xhtml.select; |
32 |
|
import org.dom4j.Element; |
33 |
|
import org.xwiki.model.reference.EntityReference; |
34 |
|
import org.xwiki.xml.XMLUtils; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWikiContext; |
37 |
|
import com.xpn.xwiki.XWikiException; |
38 |
|
import com.xpn.xwiki.doc.merge.MergeConfiguration; |
39 |
|
import com.xpn.xwiki.doc.merge.MergeResult; |
40 |
|
import com.xpn.xwiki.internal.xml.XMLAttributeValueFilter; |
41 |
|
import com.xpn.xwiki.objects.BaseCollection; |
42 |
|
import com.xpn.xwiki.objects.BaseProperty; |
43 |
|
import com.xpn.xwiki.objects.StringProperty; |
44 |
|
import com.xpn.xwiki.objects.meta.PropertyMetaClass; |
45 |
|
import com.xpn.xwiki.web.XWikiRequest; |
46 |
|
|
|
|
| 79.8% |
Uncovered Elements: 19 (94) |
Complexity: 24 |
Complexity Density: 0.36 |
|
47 |
|
public class LevelsClass extends ListClass |
48 |
|
{ |
49 |
|
private static final String XCLASSNAME = "levelslist"; |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
51 |
484 |
public LevelsClass(PropertyMetaClass wclass)... |
52 |
|
{ |
53 |
484 |
super(XCLASSNAME, "Levels List", wclass); |
54 |
484 |
setSize(6); |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
484 |
public LevelsClass()... |
58 |
|
{ |
59 |
484 |
this(null); |
60 |
|
} |
61 |
|
|
|
|
| 53.8% |
Uncovered Elements: 6 (13) |
Complexity: 5 |
Complexity Density: 0.45 |
|
62 |
2 |
@Override... |
63 |
|
public List<String> getList(XWikiContext context) |
64 |
|
{ |
65 |
2 |
List<String> list; |
66 |
2 |
try { |
67 |
2 |
list = context.getWiki().getRightService().listAllLevels(context); |
68 |
|
} catch (XWikiException e) { |
69 |
|
|
70 |
0 |
list = new ArrayList<String>(); |
71 |
|
} |
72 |
|
|
73 |
2 |
XWikiRequest req = context.getRequest(); |
74 |
2 |
if (("editrights".equals(req.get("xpage")) || "rights".equals(req.get("editor"))) |
75 |
|
&& (!"1".equals(req.get("global")))) { |
76 |
0 |
list.remove("admin"); |
77 |
0 |
list.remove("programming"); |
78 |
0 |
list.remove("delete"); |
79 |
0 |
list.remove("register"); |
80 |
|
} |
81 |
2 |
return list; |
82 |
|
} |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
0 |
@Override... |
85 |
|
public Map<String, ListItem> getMap(XWikiContext context) |
86 |
|
{ |
87 |
0 |
return new HashMap<String, ListItem>(); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
90 |
358 |
@Override... |
91 |
|
public BaseProperty newProperty() |
92 |
|
{ |
93 |
358 |
BaseProperty property = new StringProperty(); |
94 |
358 |
property.setName(getName()); |
95 |
358 |
return property; |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
98 |
355 |
@Override... |
99 |
|
public BaseProperty fromString(String value) |
100 |
|
{ |
101 |
355 |
BaseProperty prop = newProperty(); |
102 |
355 |
prop.setValue(value); |
103 |
355 |
return prop; |
104 |
|
} |
105 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
106 |
1 |
@Override... |
107 |
|
public BaseProperty fromStringArray(String[] strings) |
108 |
|
{ |
109 |
1 |
List<String> list = new ArrayList<String>(); |
110 |
2 |
for (int i = 0; i < strings.length; i++) { |
111 |
1 |
if (!strings[i].trim().equals("")) { |
112 |
1 |
list.add(strings[i]); |
113 |
|
} |
114 |
|
} |
115 |
1 |
BaseProperty prop = newProperty(); |
116 |
1 |
fromList(prop, list); |
117 |
1 |
return prop; |
118 |
|
} |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
11 |
public String getText(String value, XWikiContext context)... |
121 |
|
{ |
122 |
11 |
return value; |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
244 |
public static List<String> getListFromString(String value)... |
126 |
|
{ |
127 |
244 |
return getListFromString(value, ",", false); |
128 |
|
} |
129 |
|
|
|
|
| 93.5% |
Uncovered Elements: 2 (31) |
Complexity: 3 |
Complexity Density: 0.11 |
|
130 |
1 |
@Override... |
131 |
|
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) |
132 |
|
{ |
133 |
1 |
select select = new select(prefix + name, 1); |
134 |
1 |
select.setAttributeFilter(new XMLAttributeValueFilter()); |
135 |
1 |
select.setMultiple(isMultiSelect()); |
136 |
1 |
select.setSize(getSize()); |
137 |
1 |
select.setName(prefix + name); |
138 |
1 |
select.setID(prefix + name); |
139 |
1 |
select.setDisabled(isDisabled()); |
140 |
|
|
141 |
1 |
List<String> list = getList(context); |
142 |
|
|
143 |
1 |
BaseProperty prop = (BaseProperty) object.safeget(name); |
144 |
1 |
List<String> selectlist = toList(prop); |
145 |
|
|
146 |
|
|
147 |
1 |
for (String value : list) { |
148 |
11 |
String display = getText(value, context); |
149 |
11 |
option option = new option(display, value); |
150 |
11 |
option.setAttributeFilter(new XMLAttributeValueFilter()); |
151 |
11 |
option.addElement(XMLUtils.escape(display)); |
152 |
|
|
153 |
11 |
if (!list.contains(value)) { |
154 |
0 |
list.add(value); |
155 |
|
} |
156 |
11 |
if (selectlist.contains(value)) { |
157 |
1 |
option.setSelected(true); |
158 |
|
} |
159 |
11 |
select.addElement(option); |
160 |
|
} |
161 |
|
|
162 |
1 |
buffer.append(select.toString()); |
163 |
1 |
input in = new input(); |
164 |
1 |
in.setAttributeFilter(new XMLAttributeValueFilter()); |
165 |
1 |
in.setType("hidden"); |
166 |
1 |
in.setName(prefix + name); |
167 |
1 |
in.setDisabled(isDisabled()); |
168 |
1 |
buffer.append(in.toString()); |
169 |
|
} |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
171 |
0 |
@Override... |
172 |
|
public BaseProperty newPropertyfromXML(Element ppcel) |
173 |
|
{ |
174 |
0 |
String value = ppcel.getText(); |
175 |
0 |
return fromString(value); |
176 |
|
} |
177 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
178 |
1 |
@Override... |
179 |
|
public List<String> toList(BaseProperty<?> property) |
180 |
|
{ |
181 |
1 |
List<String> selectlist; |
182 |
|
|
183 |
1 |
if (property == null) { |
184 |
0 |
selectlist = Collections.emptyList(); |
185 |
|
} else { |
186 |
1 |
selectlist = getListFromString((String) property.getValue()); |
187 |
|
} |
188 |
|
|
189 |
1 |
return selectlist; |
190 |
|
} |
191 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
192 |
1 |
@Override... |
193 |
|
public void fromList(BaseProperty<?> property, List<String> list) |
194 |
|
{ |
195 |
1 |
property.setValue(list != null ? StringUtils.join(list, ',') : null); |
196 |
|
} |
197 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
0 |
@Override... |
199 |
|
public <T extends EntityReference> void mergeProperty(BaseProperty<T> currentProperty, |
200 |
|
BaseProperty<T> previousProperty, BaseProperty<T> newProperty, MergeConfiguration configuration, |
201 |
|
XWikiContext xcontext, MergeResult mergeResult) |
202 |
|
{ |
203 |
|
|
204 |
0 |
mergeNotOrderedListProperty(currentProperty, previousProperty, newProperty, configuration, xcontext, |
205 |
|
mergeResult); |
206 |
|
} |
207 |
|
} |