1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.objects.classes

File StaticListClass.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

16
54
7
1
148
107
17
0.31
7.71
7
2.43

Classes

Class Line # Actions
StaticListClass 37 54 0% 17 2
0.9740259697.4%
 

Contributing tests

This file is covered by 42 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.objects.classes;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.List;
25    import java.util.Map;
26   
27    import org.apache.commons.lang3.StringUtils;
28    import org.apache.ecs.xhtml.input;
29   
30    import com.xpn.xwiki.XWiki;
31    import com.xpn.xwiki.XWikiContext;
32    import com.xpn.xwiki.internal.xml.XMLAttributeValueFilter;
33    import com.xpn.xwiki.objects.BaseCollection;
34    import com.xpn.xwiki.objects.BaseProperty;
35    import com.xpn.xwiki.objects.meta.PropertyMetaClass;
36   
 
37    public class StaticListClass extends ListClass
38    {
39    private static final String XCLASSNAME = "staticlist";
40   
 
41  20994 toggle public StaticListClass(PropertyMetaClass wclass)
42    {
43  20994 super(XCLASSNAME, "Static List", wclass);
44  20994 setSeparators("|, ");
45    }
46   
 
47  19068 toggle public StaticListClass()
48    {
49  19068 this(null);
50    }
51   
 
52  34982 toggle public String getValues()
53    {
54  34982 return getStringValue("values");
55    }
56   
 
57  7811 toggle public void setValues(String values)
58    {
59  7811 setStringValue("values", values);
60    }
61   
 
62  1693 toggle @Override
63    public List<String> getList(XWikiContext context)
64    {
65  1693 String sort = getSort();
66  1693 if (StringUtils.isEmpty(sort) || "none".equals(sort)) {
67  1691 return getListFromString(getValues());
68    }
69   
70  2 Map<String, ListItem> valuesMap = getMap(context);
71  2 List<ListItem> values = new ArrayList<ListItem>(valuesMap.size());
72  2 values.addAll(valuesMap.values());
73   
74  2 if ("id".equals(sort)) {
75  1 Collections.sort(values, ListItem.ID_COMPARATOR);
76  1 } else if ("value".equals(sort)) {
77  1 Collections.sort(values, ListItem.VALUE_COMPARATOR);
78    }
79   
80  2 List<String> result = new ArrayList<String>(values.size());
81  2 for (ListItem value : values) {
82  8 result.add(value.getId());
83    }
84  2 return result;
85    }
86   
 
87  33291 toggle @Override
88    public Map<String, ListItem> getMap(XWikiContext context)
89    {
90  33291 String values = getValues();
91  33291 return getMapFromString(values);
92    }
93   
 
94  1074 toggle @Override
95    public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context)
96    {
97  1074 if (getDisplayType().equals(DISPLAYTYPE_INPUT)) {
98  110 input input = new input();
99  110 input.setAttributeFilter(new XMLAttributeValueFilter());
100  110 BaseProperty prop = (BaseProperty) object.safeget(name);
101  110 if (prop != null) {
102  110 input.setValue(this.toFormString(prop));
103    }
104  110 input.setType("text");
105  110 input.setSize(getSize());
106  110 input.setName(prefix + name);
107  110 input.setID(prefix + name);
108  110 input.setDisabled(isDisabled());
109   
110  110 if (isPicker()) {
111  4 input.setClass("suggested");
112  4 String path = "";
113  4 XWiki xwiki = context.getWiki();
114  4 path = xwiki.getURL("Main.WebHome", "view", context);
115   
116  4 String classname = this.getObject().getName();
117  4 String fieldname = this.getName();
118  4 String secondCol = "-", firstCol = "-";
119   
120  4 String script =
121    "\"" + path + "?xpage=suggest&classname=" + classname + "&fieldname=" + fieldname + "&firCol="
122    + firstCol + "&secCol=" + secondCol + "&\"";
123  4 String varname = "\"input\"";
124  4 String seps = "\"" + this.getSeparators() + "\"";
125  4 if (isMultiSelect()) {
126  3 input.setOnFocus("new ajaxSuggest(this, {script:" + script + ", varname:" + varname + ", seps:"
127    + seps + "} )");
128    } else {
129  1 input.setOnFocus("new ajaxSuggest(this, {script:" + script + ", varname:" + varname + "} )");
130    }
131    }
132   
133  110 buffer.append(input.toString());
134   
135  964 } else if (getDisplayType().equals(DISPLAYTYPE_RADIO) || getDisplayType().equals(DISPLAYTYPE_CHECKBOX)) {
136  10 displayRadioEdit(buffer, name, prefix, object, context);
137    } else {
138  954 displaySelectEdit(buffer, name, prefix, object, context);
139   
140    // We need a hidden input with an empty value to be able to clear the selected values from the above select
141    // when it has multiple selection enabled and no value selected.
142  954 org.apache.ecs.xhtml.input hidden = new input(input.hidden, prefix + name, "");
143  954 hidden.setAttributeFilter(new XMLAttributeValueFilter());
144  954 hidden.setDisabled(isDisabled());
145  954 buffer.append(hidden);
146    }
147    }
148    }