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 |
|
import java.util.StringTokenizer; |
28 |
|
|
29 |
|
import org.apache.commons.lang3.StringUtils; |
30 |
|
import org.apache.ecs.xhtml.input; |
31 |
|
import org.slf4j.Logger; |
32 |
|
import org.slf4j.LoggerFactory; |
33 |
|
import org.xwiki.model.EntityType; |
34 |
|
import org.xwiki.query.Query; |
35 |
|
import org.xwiki.query.QueryManager; |
36 |
|
|
37 |
|
import com.xpn.xwiki.XWiki; |
38 |
|
import com.xpn.xwiki.XWikiContext; |
39 |
|
import com.xpn.xwiki.internal.xml.XMLAttributeValueFilter; |
40 |
|
import com.xpn.xwiki.objects.BaseCollection; |
41 |
|
import com.xpn.xwiki.objects.BaseProperty; |
42 |
|
import com.xpn.xwiki.objects.ListProperty; |
43 |
|
import com.xpn.xwiki.objects.meta.PropertyMetaClass; |
44 |
|
import com.xpn.xwiki.web.Utils; |
45 |
|
|
|
|
| 48.4% |
Uncovered Elements: 199 (386) |
Complexity: 92 |
Complexity Density: 0.37 |
|
46 |
|
public class DBListClass extends ListClass |
47 |
|
{ |
48 |
|
private static final String XCLASSNAME = "dblist"; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(DBListClass.class); |
54 |
|
|
55 |
|
protected static final String DEFAULT_QUERY = "select doc.name from XWikiDocument doc where 1 = 0"; |
56 |
|
|
57 |
|
private List<ListItem> cachedDBList; |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
18 |
public DBListClass(String name, String prettyname, PropertyMetaClass wclass)... |
60 |
|
{ |
61 |
18 |
super(name, prettyname, wclass); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
689 |
public DBListClass(PropertyMetaClass wclass)... |
65 |
|
{ |
66 |
689 |
super(XCLASSNAME, "DB List", wclass); |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
689 |
public DBListClass()... |
70 |
|
{ |
71 |
689 |
this(null); |
72 |
|
} |
73 |
|
|
|
|
| 75% |
Uncovered Elements: 5 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
74 |
67 |
public List<ListItem> makeList(List<Object> list)... |
75 |
|
{ |
76 |
67 |
List<ListItem> result = new ArrayList<ListItem>(); |
77 |
67 |
for (Object item : list) { |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
262 |
if (item != null) { |
83 |
262 |
if (item instanceof String) { |
84 |
21 |
result.add(new ListItem((String) item)); |
85 |
|
} else { |
86 |
241 |
Object[] res = (Object[]) item; |
87 |
241 |
if (res.length == 1) { |
88 |
0 |
result.add(new ListItem(toStringButEmptyIfNull(res[0]))); |
89 |
241 |
} else if (res.length == 2) { |
90 |
241 |
result.add(new ListItem(toStringButEmptyIfNull(res[0]), toStringButEmptyIfNull(res[1]))); |
91 |
|
} else { |
92 |
0 |
result.add(new ListItem(toStringButEmptyIfNull(res[0]), toStringButEmptyIfNull(res[1]), |
93 |
|
toStringButEmptyIfNull(res[2]))); |
94 |
|
} |
95 |
|
} |
96 |
|
} |
97 |
|
} |
98 |
67 |
return result; |
99 |
|
} |
100 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
101 |
482 |
private String toStringButEmptyIfNull(Object object)... |
102 |
|
{ |
103 |
482 |
if (object == null) { |
104 |
0 |
return ""; |
105 |
|
} else { |
106 |
482 |
return object.toString(); |
107 |
|
} |
108 |
|
} |
109 |
|
|
|
|
| 78.9% |
Uncovered Elements: 4 (19) |
Complexity: 4 |
Complexity Density: 0.27 |
|
110 |
125 |
public List<ListItem> getDBList(XWikiContext context)... |
111 |
|
{ |
112 |
125 |
List<ListItem> list = getCachedDBList(context); |
113 |
125 |
if (list == null) { |
114 |
67 |
String hqlQuery = getQuery(context); |
115 |
|
|
116 |
67 |
if (hqlQuery == null) { |
117 |
0 |
list = new ArrayList<ListItem>(); |
118 |
|
} else { |
119 |
67 |
try { |
120 |
|
|
121 |
67 |
QueryManager queryManager = Utils.getComponent(QueryManager.class); |
122 |
|
|
123 |
67 |
Query query = queryManager.createQuery(hqlQuery, Query.HQL); |
124 |
|
|
125 |
67 |
String wikiName = getReference().extractReference(EntityType.WIKI).getName(); |
126 |
67 |
query.setWiki(wikiName); |
127 |
|
|
128 |
67 |
list = makeList(query.execute()); |
129 |
|
} catch (Exception e) { |
130 |
0 |
LOGGER.error("Failed to get the list", e); |
131 |
0 |
list = new ArrayList<ListItem>(); |
132 |
|
} |
133 |
|
} |
134 |
67 |
setCachedDBList(list, context); |
135 |
|
} |
136 |
125 |
return list; |
137 |
|
} |
138 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
139 |
38 |
@Override... |
140 |
|
public List<String> getList(XWikiContext context) |
141 |
|
{ |
142 |
38 |
List<ListItem> dblist = getDBList(context); |
143 |
|
|
144 |
38 |
String sort = getSort(); |
145 |
|
|
146 |
38 |
if ("id".equals(sort)) { |
147 |
0 |
Collections.sort(dblist, ListItem.ID_COMPARATOR); |
148 |
38 |
} else if ("value".equals(sort)) { |
149 |
28 |
Collections.sort(dblist, ListItem.VALUE_COMPARATOR); |
150 |
|
} |
151 |
|
|
152 |
38 |
List<String> result = new ArrayList<String>(dblist.size()); |
153 |
38 |
for (ListItem value : dblist) { |
154 |
191 |
result.add(value.getId()); |
155 |
|
} |
156 |
38 |
return result; |
157 |
|
} |
158 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
159 |
85 |
@Override... |
160 |
|
public Map<String, ListItem> getMap(XWikiContext context) |
161 |
|
{ |
162 |
85 |
List<ListItem> list = getDBList(context); |
163 |
85 |
Map<String, ListItem> result = new HashMap<String, ListItem>(); |
164 |
85 |
if ((list == null) || (list.size() == 0)) { |
165 |
41 |
return result; |
166 |
|
} |
167 |
341 |
for (int i = 0; i < list.size(); i++) { |
168 |
297 |
Object res = list.get(i); |
169 |
297 |
if (res instanceof String) { |
170 |
0 |
result.put((String) res, new ListItem((String) res)); |
171 |
|
} else { |
172 |
297 |
ListItem item = (ListItem) res; |
173 |
297 |
result.put(item.getId(), item); |
174 |
|
} |
175 |
|
} |
176 |
44 |
return result; |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
@param@link |
200 |
|
@return |
201 |
|
|
|
|
| 68.1% |
Uncovered Elements: 30 (94) |
Complexity: 26 |
Complexity Density: 0.43 |
|
202 |
66 |
public String getQuery(XWikiContext context)... |
203 |
|
{ |
204 |
|
|
205 |
66 |
String sql = getSql(); |
206 |
|
|
207 |
|
|
208 |
66 |
if (StringUtils.isBlank(sql)) { |
209 |
54 |
if (context.getWiki().getHibernateStore() != null) { |
210 |
|
|
211 |
54 |
String classname = StringUtils.defaultString(getClassname()); |
212 |
54 |
String idField = StringUtils.defaultString(getIdField()); |
213 |
54 |
String valueField = StringUtils.defaultString(getValueField()); |
214 |
|
|
215 |
|
|
216 |
54 |
boolean hasClassname = !StringUtils.isBlank(classname); |
217 |
54 |
boolean hasIdField = !StringUtils.isBlank(idField); |
218 |
54 |
boolean hasValueField = !StringUtils.isBlank(valueField); |
219 |
|
|
220 |
54 |
if (!(hasIdField || hasValueField)) { |
221 |
|
|
222 |
|
|
223 |
21 |
if (hasClassname) { |
224 |
0 |
sql = |
225 |
|
"select distinct doc.fullName from XWikiDocument as doc, BaseObject as obj" |
226 |
|
+ " where doc.fullName=obj.name and obj.className='" + classname + "'"; |
227 |
|
} else { |
228 |
|
|
229 |
|
|
230 |
21 |
sql = DEFAULT_QUERY; |
231 |
|
} |
232 |
21 |
return sql; |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
33 |
if (!hasIdField && hasValueField) { |
237 |
0 |
idField = valueField; |
238 |
0 |
valueField = ""; |
239 |
0 |
hasValueField = false; |
240 |
33 |
} else if (idField.equals(valueField)) { |
241 |
|
|
242 |
0 |
hasValueField = false; |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
33 |
boolean usesObj = hasClassname || idField.startsWith("obj.") || valueField.startsWith("obj."); |
249 |
|
|
250 |
|
|
251 |
|
|
252 |
33 |
boolean usesDoc = idField.startsWith("doc.") || valueField.startsWith("doc."); |
253 |
33 |
if ((!idField.startsWith("obj.") || (hasValueField && !valueField.startsWith("obj."))) && !hasClassname) { |
254 |
0 |
usesDoc = true; |
255 |
|
} |
256 |
|
|
257 |
|
|
258 |
33 |
StringBuffer select = new StringBuffer("select distinct "); |
259 |
|
|
260 |
33 |
List<String> fromStatements = new ArrayList<String>(); |
261 |
33 |
List<String> whereStatements = new ArrayList<String>(); |
262 |
|
|
263 |
|
|
264 |
33 |
if (usesDoc) { |
265 |
0 |
fromStatements.add("XWikiDocument as doc"); |
266 |
0 |
if (usesObj) { |
267 |
0 |
whereStatements.add("doc.fullName=obj.name"); |
268 |
|
} |
269 |
|
} |
270 |
|
|
271 |
33 |
if (usesObj) { |
272 |
33 |
fromStatements.add("BaseObject as obj"); |
273 |
33 |
if (hasClassname) { |
274 |
33 |
whereStatements.add("obj.className='" + classname + "'"); |
275 |
|
} |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
33 |
if (idField.startsWith("doc.") || idField.startsWith("obj.")) { |
280 |
0 |
select.append(idField); |
281 |
33 |
} else if (!hasClassname) { |
282 |
0 |
select.append("doc." + idField); |
283 |
|
} else { |
284 |
33 |
select.append("idprop.value"); |
285 |
33 |
fromStatements.add("StringProperty as idprop"); |
286 |
33 |
whereStatements.add("obj.id=idprop.id.id and idprop.id.name='" + idField + "'"); |
287 |
|
} |
288 |
|
|
289 |
|
|
290 |
33 |
if (hasValueField) { |
291 |
33 |
if (valueField.startsWith("doc.") || valueField.startsWith("obj.")) { |
292 |
0 |
select.append(", ").append(valueField); |
293 |
33 |
} else if (!hasClassname) { |
294 |
0 |
select.append(", doc." + valueField); |
295 |
|
} else { |
296 |
33 |
select.append(", valueprop.value"); |
297 |
33 |
fromStatements.add("StringProperty as valueprop"); |
298 |
33 |
whereStatements.add("obj.id=valueprop.id.id and valueprop.id.name='" + valueField + "'"); |
299 |
|
} |
300 |
|
} |
301 |
|
|
302 |
33 |
select.append(" from "); |
303 |
33 |
select.append(StringUtils.join(fromStatements.iterator(), ", ")); |
304 |
33 |
if (whereStatements.size() > 0) { |
305 |
33 |
select.append(" where "); |
306 |
33 |
select.append(StringUtils.join(whereStatements.iterator(), " and ")); |
307 |
|
} |
308 |
33 |
sql = select.toString(); |
309 |
|
} else { |
310 |
|
|
311 |
|
|
312 |
|
} |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
45 |
try { |
317 |
45 |
sql = context.getWiki().parseContent(sql, context); |
318 |
|
} catch (Exception e) { |
319 |
0 |
LOGGER.error("Failed to parse SQL script [{}]. Continuing with non-rendered script.", sql, e); |
320 |
|
} |
321 |
|
|
322 |
45 |
return sql; |
323 |
|
} |
324 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
325 |
124 |
public String getSql()... |
326 |
|
{ |
327 |
124 |
return getLargeStringValue("sql"); |
328 |
|
} |
329 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
330 |
83 |
public void setSql(String sql)... |
331 |
|
{ |
332 |
83 |
setLargeStringValue("sql", sql); |
333 |
|
} |
334 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
335 |
109 |
public String getClassname()... |
336 |
|
{ |
337 |
109 |
return getStringValue("classname"); |
338 |
|
} |
339 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
340 |
6 |
public void setClassname(String classname)... |
341 |
|
{ |
342 |
6 |
setStringValue("classname", classname); |
343 |
|
} |
344 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
345 |
109 |
public String getIdField()... |
346 |
|
{ |
347 |
109 |
return getStringValue("idField"); |
348 |
|
} |
349 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
350 |
29 |
public void setIdField(String idField)... |
351 |
|
{ |
352 |
29 |
setStringValue("idField", idField); |
353 |
|
} |
354 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
355 |
109 |
public String getValueField()... |
356 |
|
{ |
357 |
109 |
return getStringValue("valueField"); |
358 |
|
} |
359 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
360 |
21 |
public void setValueField(String valueField)... |
361 |
|
{ |
362 |
21 |
setStringValue("valueField", valueField); |
363 |
|
} |
364 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
365 |
125 |
public List<ListItem> getCachedDBList(XWikiContext context)... |
366 |
|
{ |
367 |
125 |
if (isCache()) { |
368 |
0 |
return this.cachedDBList; |
369 |
|
} else { |
370 |
125 |
return (List<ListItem>) context.get(context.getWikiId() + ":" + getFieldFullName()); |
371 |
|
} |
372 |
|
} |
373 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
374 |
67 |
public void setCachedDBList(List<ListItem> cachedDBList, XWikiContext context)... |
375 |
|
{ |
376 |
67 |
if (isCache()) { |
377 |
0 |
this.cachedDBList = cachedDBList; |
378 |
|
} else { |
379 |
67 |
context.put(context.getWikiId() + ":" + getFieldFullName(), cachedDBList); |
380 |
|
} |
381 |
|
} |
382 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
383 |
0 |
@Override... |
384 |
|
public void flushCache() |
385 |
|
{ |
386 |
0 |
this.cachedDBList = null; |
387 |
0 |
super.flushCache(); |
388 |
|
} |
389 |
|
|
390 |
|
|
|
|
| 0% |
Uncovered Elements: 48 (48) |
Complexity: 10 |
Complexity Density: 0.33 |
|
391 |
0 |
public String returnCol(String hqlQuery, boolean first)... |
392 |
|
{ |
393 |
0 |
String firstCol = "-", secondCol = "-"; |
394 |
0 |
if (StringUtils.isEmpty(hqlQuery)) { |
395 |
0 |
return firstCol; |
396 |
|
} |
397 |
|
|
398 |
0 |
int fromIndx = hqlQuery.toLowerCase().indexOf("from"); |
399 |
|
|
400 |
0 |
if (fromIndx > 0) { |
401 |
0 |
String beforeFrom = hqlQuery.substring(0, fromIndx).replaceAll("\\s+", " "); |
402 |
0 |
int commaIndex = beforeFrom.indexOf(","); |
403 |
|
|
404 |
|
|
405 |
0 |
if (commaIndex > 0) { |
406 |
0 |
StringTokenizer st = new StringTokenizer(beforeFrom, " ,()", true); |
407 |
0 |
ArrayList<String> words = new ArrayList<String>(); |
408 |
|
|
409 |
0 |
while (st.hasMoreTokens()) { |
410 |
0 |
words.add(st.nextToken()); |
411 |
|
} |
412 |
|
|
413 |
0 |
int comma = words.indexOf(",") - 1; |
414 |
0 |
while (words.get(comma).toString().compareTo(" ") == 0) { |
415 |
0 |
comma--; |
416 |
|
} |
417 |
0 |
firstCol = words.get(comma).toString().trim(); |
418 |
|
|
419 |
0 |
comma = words.indexOf(",") + 1; |
420 |
0 |
while (words.get(comma).toString().compareTo(" ") == 0) { |
421 |
0 |
comma++; |
422 |
|
} |
423 |
|
|
424 |
0 |
if (words.get(comma).toString().compareTo("(") == 0) { |
425 |
0 |
int i = comma + 1; |
426 |
0 |
while (words.get(i).toString().compareTo(")") != 0) { |
427 |
0 |
secondCol += words.get(i).toString(); |
428 |
0 |
i++; |
429 |
|
} |
430 |
0 |
secondCol += ")"; |
431 |
|
} else { |
432 |
0 |
secondCol = words.get(comma).toString().trim(); |
433 |
|
} |
434 |
|
} |
435 |
|
|
436 |
|
else { |
437 |
0 |
firstCol = StringUtils.substringAfterLast(beforeFrom.trim(), " "); |
438 |
|
} |
439 |
|
} |
440 |
0 |
if (first == true) { |
441 |
0 |
return firstCol; |
442 |
|
} else { |
443 |
0 |
return secondCol; |
444 |
|
} |
445 |
|
} |
446 |
|
|
447 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 4 |
Complexity Density: 0.21 |
|
448 |
0 |
public String getValue(String val, String sql, XWikiContext context)... |
449 |
|
{ |
450 |
0 |
String lowerCaseSQL = sql.toLowerCase(); |
451 |
|
|
452 |
|
|
453 |
|
|
454 |
0 |
int orderByPos = lowerCaseSQL.lastIndexOf("order by "); |
455 |
0 |
if (orderByPos >= 0) { |
456 |
0 |
sql = sql.substring(0, orderByPos); |
457 |
|
} |
458 |
0 |
String firstCol = returnCol(sql, true); |
459 |
0 |
String secondCol = returnCol(sql, false); |
460 |
|
|
461 |
0 |
String newsql = sql.substring(0, sql.indexOf(firstCol)); |
462 |
0 |
newsql += secondCol + " "; |
463 |
|
|
464 |
0 |
newsql += sql.substring(lowerCaseSQL.indexOf("from ")); |
465 |
0 |
newsql += "and " + firstCol + "='" + val + "'"; |
466 |
|
|
467 |
0 |
Object[] list = null; |
468 |
0 |
XWiki xwiki = context.getWiki(); |
469 |
0 |
String res = ""; |
470 |
0 |
try { |
471 |
0 |
list = xwiki.search(newsql, context).toArray(); |
472 |
0 |
if (list.length > 0) { |
473 |
0 |
res = list[0].toString(); |
474 |
|
} |
475 |
|
} catch (Exception e) { |
476 |
0 |
e.printStackTrace(); |
477 |
|
} |
478 |
0 |
return res; |
479 |
|
} |
480 |
|
|
481 |
|
|
|
|
| 12.2% |
Uncovered Elements: 72 (82) |
Complexity: 14 |
Complexity Density: 0.23 |
|
482 |
28 |
@Override... |
483 |
|
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) |
484 |
|
{ |
485 |
|
|
486 |
28 |
if (getDisplayType().equals(DISPLAYTYPE_INPUT)) { |
487 |
0 |
input input = new input(); |
488 |
0 |
input.setAttributeFilter(new XMLAttributeValueFilter()); |
489 |
0 |
input.setType("text"); |
490 |
0 |
input.setSize(getSize()); |
491 |
0 |
boolean changeInputName = false; |
492 |
0 |
boolean setInpVal = true; |
493 |
|
|
494 |
0 |
BaseProperty prop = (BaseProperty) object.safeget(name); |
495 |
0 |
String value = ""; |
496 |
0 |
String databaseValue = ""; |
497 |
0 |
if (prop != null) { |
498 |
0 |
value = this.toFormString(prop); |
499 |
0 |
databaseValue = prop.toText(); |
500 |
|
} |
501 |
|
|
502 |
0 |
if (isPicker()) { |
503 |
0 |
input.setClass("suggested"); |
504 |
0 |
String path = ""; |
505 |
0 |
XWiki xwiki = context.getWiki(); |
506 |
0 |
path = xwiki.getURL("Main.WebHome", "view", context); |
507 |
0 |
String classname = this.getObject().getName(); |
508 |
0 |
String fieldname = this.getName(); |
509 |
0 |
String hibquery = this.getSql(); |
510 |
0 |
String secondCol = "-", firstCol = "-"; |
511 |
|
|
512 |
0 |
if (hibquery != null && !hibquery.equals("")) { |
513 |
0 |
firstCol = returnCol(hibquery, true); |
514 |
0 |
secondCol = returnCol(hibquery, false); |
515 |
|
|
516 |
0 |
if (secondCol.compareTo("-") != 0) { |
517 |
0 |
changeInputName = true; |
518 |
0 |
input hidden = new input(); |
519 |
0 |
hidden.setAttributeFilter(new XMLAttributeValueFilter()); |
520 |
0 |
hidden.setID(prefix + name); |
521 |
0 |
hidden.setName(prefix + name); |
522 |
0 |
hidden.setType("hidden"); |
523 |
0 |
hidden.setDisabled(isDisabled()); |
524 |
0 |
if (StringUtils.isNotEmpty(value)) { |
525 |
0 |
hidden.setValue(value); |
526 |
|
} |
527 |
0 |
buffer.append(hidden.toString()); |
528 |
|
|
529 |
0 |
input.setValue(getValue(databaseValue, hibquery, context)); |
530 |
0 |
setInpVal = false; |
531 |
|
} |
532 |
|
} |
533 |
|
|
534 |
0 |
String script = |
535 |
|
"\"" + path + "?xpage=suggest&classname=" + classname + "&fieldname=" + fieldname + "&firCol=" |
536 |
|
+ firstCol + "&secCol=" + secondCol + "&\""; |
537 |
0 |
String varname = "\"input\""; |
538 |
0 |
String seps = "\"" + this.getSeparators() + "\""; |
539 |
0 |
if (isMultiSelect()) { |
540 |
0 |
input.setOnFocus("new ajaxSuggest(this, {script:" + script + ", varname:" + varname + ", seps:" |
541 |
|
+ seps + "} )"); |
542 |
|
} else { |
543 |
0 |
input.setOnFocus("new ajaxSuggest(this, {script:" + script + ", varname:" + varname + "} )"); |
544 |
|
} |
545 |
|
} |
546 |
|
|
547 |
0 |
if (changeInputName == true) { |
548 |
0 |
input.setName(prefix + name + "_suggest"); |
549 |
0 |
input.setID(prefix + name + "_suggest"); |
550 |
|
} else { |
551 |
0 |
input.setName(prefix + name); |
552 |
0 |
input.setID(prefix + name); |
553 |
|
} |
554 |
0 |
if (setInpVal == true) { |
555 |
0 |
input.setValue(value); |
556 |
|
} |
557 |
|
|
558 |
0 |
input.setDisabled(isDisabled()); |
559 |
0 |
buffer.append(input.toString()); |
560 |
28 |
} else if (getDisplayType().equals(DISPLAYTYPE_RADIO) || getDisplayType().equals(DISPLAYTYPE_CHECKBOX)) { |
561 |
0 |
displayRadioEdit(buffer, name, prefix, object, context); |
562 |
|
} else { |
563 |
28 |
displaySelectEdit(buffer, name, prefix, object, context); |
564 |
|
} |
565 |
|
|
566 |
28 |
if (!getDisplayType().equals("input")) { |
567 |
28 |
org.apache.ecs.xhtml.input hidden = new input(input.hidden, prefix + name, ""); |
568 |
28 |
hidden.setAttributeFilter(new XMLAttributeValueFilter()); |
569 |
28 |
buffer.append(hidden); |
570 |
|
} |
571 |
|
} |
572 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
573 |
47 |
@Override... |
574 |
|
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) |
575 |
|
{ |
576 |
47 |
List<String> selectlist; |
577 |
47 |
String separator = getSeparator(); |
578 |
47 |
BaseProperty prop = (BaseProperty) object.safeget(name); |
579 |
47 |
Map<String, ListItem> map = getMap(context); |
580 |
|
|
581 |
|
|
582 |
47 |
if (prop == null) { |
583 |
0 |
return; |
584 |
|
} |
585 |
|
|
586 |
47 |
if (prop instanceof ListProperty) { |
587 |
39 |
selectlist = ((ListProperty) prop).getList(); |
588 |
39 |
List<String> newlist = new ArrayList<String>(); |
589 |
39 |
for (String entry : selectlist) { |
590 |
42 |
newlist.add(getDisplayValue(entry, name, map, context)); |
591 |
|
} |
592 |
39 |
buffer.append(StringUtils.join(newlist, separator)); |
593 |
|
} else { |
594 |
8 |
buffer.append(getDisplayValue(prop.getValue(), name, map, context)); |
595 |
|
} |
596 |
|
} |
597 |
|
} |