Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: src/main/java/com/xpn/xwiki/objects/classes/ListClass.java
- ===================================================================
- --- src/main/java/com/xpn/xwiki/objects/classes/ListClass.java (revision 31104)
- +++ src/main/java/com/xpn/xwiki/objects/classes/ListClass.java (working copy)
- @@ -502,7 +502,7 @@
- }
- radio.addElement(getDisplayValue(rawvalue, name, map, context));
- - buffer.append("<label class=\"xwiki-form-listclass\" for=\"xwiki-form-" + name + "-" + count++ + "\">");
- + buffer.append("<label class=\"xwiki-form-listclass\" for=\"xwiki-form-" + name + "-" + count + "id=\"xwiki-form-" + name + "-" + count++ + "\">");
- buffer.append(radio.toString());
- buffer.append("</label>");
- }
- @@ -600,75 +600,122 @@
- public abstract List<String> getList(XWikiContext context);
- + public List<String> getValidatedList(XWikiContext context)
- + {
- + List<String> result = getList(context);
- +
- + String regexp = getValidationRegExp();
- + if ((regexp == null) || (regexp.trim().equals(""))) {
- + return result;
- + }
- +
- + if (isMultiSelect()) {
- + for (Iterator<String> it = result.iterator(); it.hasNext();) {
- + String rawvalue = it.next();
- + if (!context.getUtil().match(regexp, "[" + rawvalue + "]")) {
- + it.remove();
- + }
- + }
- + } else {
- + for (Iterator<String> it = result.iterator(); it.hasNext();) {
- + String rawvalue = it.next();
- + if (!context.getUtil().match(regexp, rawvalue)) {
- + it.remove();
- + }
- + }
- + }
- +
- + return result;
- + }
- +
- public abstract Map<String, ListItem> getMap(XWikiContext context);
- - @Override
- public String displaySearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context)
- {
- + return displaySearch(name, prefix, criteria, true, context);
- + }
- +
- + public String displaySearch(String name, String prefix, XWikiCriteria criteria, boolean multiple,
- + XWikiContext context)
- + {
- if (getDisplayType().equals("input")) {
- return super.displaySearch(name, prefix, criteria, context);
- - } else if (getDisplayType().equals("radio") || getDisplayType().equals("checkbox")) {
- - return displayRadioSearch(name, prefix, criteria, context);
- } else {
- - return displaySelectSearch(name, prefix, criteria, context);
- + List<String> list;
- + if (multiple) {
- + list = getValidatedList(context);
- + } else {
- + list = getList(context);
- + }
- +
- + if (getDisplayType().equals("radio") || getDisplayType().equals("checkbox") || list.size() < 6) {
- + return displayRadioSearch(name, prefix, criteria, multiple, list, context);
- + } else {
- + return displaySelectSearch(name, prefix, criteria, multiple, list, context);
- + }
- }
- }
- - protected String displayRadioSearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context)
- + protected String displayRadioSearch(String name, String prefix, XWikiCriteria criteria, boolean multiple,
- + List<String> list, XWikiContext context)
- {
- StringBuffer buffer = new StringBuffer();
- - List<String> list = getList(context);
- - List<String> selectlist = new ArrayList<String>();
- - /*
- - * BaseProperty prop = (BaseProperty)object.safeget(name); if (prop==null) { selectlist = new ArrayList(); }
- - * else if ((prop instanceof ListProperty)||(prop instanceof DBStringListProperty)) { selectlist = (List)
- - * prop.getValue(); } else { selectlist = new ArrayList(); selectlist.add(prop.getValue()); }
- - */
- + Map<String, ListItem> map = getMap(context);
- + String fieldFullName = getFieldFullName();
- + String[] selectArray = ((String[]) criteria.getParameter(fieldFullName));
- + List<String> selectlist = (selectArray != null) ? Arrays.asList(selectArray) : new ArrayList<String>();
- +
- // Add options from Set
- - for (Iterator<String> it = list.iterator(); it.hasNext();) {
- - String rawvalue = it.next();
- + int count = 0;
- + for (String rawvalue : list) {
- String value = getElementValue(rawvalue);
- - String display = getDisplayValue(rawvalue, name, getMap(context), context);
- input radio =
- - new input(getDisplayType().equals("radio") ? input.radio : input.checkbox, prefix + name, value);
- + new input((getDisplayType().equals("radio") && !multiple) ? input.radio : input.checkbox,
- + prefix + name, value);
- if (selectlist.contains(value)) {
- radio.setChecked(true);
- }
- - radio.addElement(display);
- + radio.addElement(getDisplayValue(rawvalue, name, map, context));
- + buffer.append("<span class=\"xwiki-form-listclass\" id=\"xwiki-form-" + name + "-" + count++ + "\">");
- buffer.append(radio.toString());
- - if (it.hasNext()) {
- - buffer.append("<br/>");
- - }
- + buffer.append("</span>");
- }
- +
- return buffer.toString();
- }
- - protected String displaySelectSearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context)
- + protected String displaySelectSearch(String name, String prefix, XWikiCriteria criteria, boolean multiple,
- + List<String> list, XWikiContext context)
- {
- select select = new select(prefix + name, 1);
- - select.setMultiple(true);
- - select.setSize(5);
- + select.setMultiple(multiple);
- + select.setSize((multiple && getSize() == 1) ? 5 : getSize());
- select.setName(prefix + name);
- select.setID(prefix + name);
- - List<String> list = getList(context);
- + Map<String, ListItem> map = getMap(context);
- +
- + String sort = getSort();
- + if (!"none".equals(sort)) {
- + if ("id".equals(sort)) {
- + Collections.sort(list);
- + }
- + if ("value".equals(sort)) {
- + Collections.sort(list, new MapComparator(map));
- + }
- + }
- +
- String fieldFullName = getFieldFullName();
- String[] selectArray = ((String[]) criteria.getParameter(fieldFullName));
- List<String> selectlist = (selectArray != null) ? Arrays.asList(selectArray) : new ArrayList<String>();
- - /*
- - * BaseProperty prop = (BaseProperty)object.safeget(name); if (prop==null) { selectlist = new ArrayList(); }
- - * else if ((prop instanceof ListProperty)||(prop instanceof DBStringListProperty)) { selectlist = (List)
- - * prop.getValue(); } else { selectlist = new ArrayList(); selectlist.add(prop.getValue()); }
- - */
- -
- // Add options from Set
- for (String rawvalue : list) {
- String value = getElementValue(rawvalue);
- - String display = getDisplayValue(rawvalue, name, getMap(context), context);
- + String display = getDisplayValue(rawvalue, name, map, context);
- option option = new option(display, value);
- option.addElement(display);
- if (selectlist.contains(value)) {
- @@ -684,21 +731,48 @@
- public void makeQuery(Map<String, Object> map, String prefix, XWikiCriteria query, List<String> criteriaList)
- {
- Object values = map.get(prefix);
- - if ((values == null) || (values.equals(""))) {
- + if ((values != null) && (!values.equals(""))) {
- + if (isMultiSelect()) {
- + if (values instanceof String) {
- + // general comparison 'like' - tests at least one value like
- + criteriaList.add("jcr:like(@xp:" + getName() + ",'%" + values.toString() + "%')");
- + } else {
- + String[] valuesarray = (String[]) values;
- + String[] criteriaarray = new String[valuesarray.length];
- + for (int i = 0; i < valuesarray.length; i++) {
- + criteriaarray[i] = "jcr:like(@xp:" + getName() + ",'%" + valuesarray[i] + "%')";
- + }
- + criteriaList.add("(" + StringUtils.join(criteriaarray, " or ") + ")");
- + }
- + } else {
- + if (values instanceof String) {
- + // general comparison '=' - tests at least one value =
- + criteriaList.add("@xp:" + getName() + "='" + values.toString() + "'");
- + } else {
- + String[] valuesarray = (String[]) values;
- + String[] criteriaarray = new String[valuesarray.length];
- + for (int i = 0; i < valuesarray.length; i++) {
- + criteriaarray[i] = "@xp:" + getName() + "='" + valuesarray[i] + "'";
- + }
- + criteriaList.add("(" + StringUtils.join(criteriaarray, " or ") + ")");
- + }
- + }
- +
- return;
- }
- - if (values instanceof String) {
- - // general comparison '=' - tests at least one value =
- - criteriaList.add("@xp:" + getName() + "='" + values.toString() + "'");
- - } else {
- - String[] valuesarray = (String[]) values;
- - String[] criteriaarray = new String[valuesarray.length];
- - for (int i = 0; i < valuesarray.length; i++) {
- - criteriaarray[i] = "@xp:" + getName() + "='" + valuesarray[i] + "'";
- - }
- - criteriaList.add("(" + StringUtils.join(criteriaarray, " or ") + ")");
- + values = map.get(prefix + "lessthan");
- + if ((values != null) && (!values.equals("")) && (values instanceof String)) {
- + criteriaList.add("@xp:" + getName() + "<='" + values.toString() + "'");
- + return;
- }
- +
- + values = map.get(prefix + "morethan");
- + if ((values != null) && (!values.equals("")) && (values instanceof String)) {
- + criteriaList.add("@xp:" + getName() + ">='" + values.toString() + "'");
- + return;
- + }
- +
- return;
- }
- @@ -708,6 +782,19 @@
- String[] data = map.get("");
- if (data != null) {
- query.setParam(getObject().getName() + "_" + getName(), data);
- + return;
- }
- +
- + data = map.get("lessthan");
- + if (data != null && data.length == 1) {
- + query.setParam(getObject().getName() + "_" + getName() + "_lessthan", data[0]);
- + return;
- + }
- +
- + data = map.get("morethan");
- + if (data != null && data.length == 1) {
- + query.setParam(getObject().getName() + "_" + getName() + "_morethan", data[0]);
- + return;
- + }
- }
- }
- Index: src/main/java/com/xpn/xwiki/objects/classes/BooleanClass.java
- ===================================================================
- --- src/main/java/com/xpn/xwiki/objects/classes/BooleanClass.java (revision 31104)
- +++ src/main/java/com/xpn/xwiki/objects/classes/BooleanClass.java (working copy)
- @@ -20,6 +20,7 @@
- */
- package com.xpn.xwiki.objects.classes;
- +import java.util.List;
- import java.util.Map;
- import org.apache.commons.lang.StringUtils;
- @@ -353,46 +354,88 @@
- }
- }
- - @Override
- public String displaySearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context)
- {
- if (getDisplayType().equals("input")) {
- return super.displaySearch(name, prefix, criteria, context);
- - } else if (getDisplayType().equals("radio")) {
- - return displayCheckboxSearch(name, prefix, criteria, context);
- } else {
- - return displaySelectSearch(name, prefix, criteria, context);
- + return displayRadioSearch(name, prefix, criteria, context);
- }
- }
- - public String displaySelectSearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context)
- + public String displayRadioSearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context)
- {
- - select select = new select(prefix + name, 1);
- - select.setMultiple(true);
- - select.setSize(3);
- - String String0 = getDisplayValue(context, 0);
- - String String1 = getDisplayValue(context, 1);
- + StringBuffer buffer = new StringBuffer();
- + String StringNone = getDisplayValue(context, 2);
- + String StringTrue = getDisplayValue(context, 1);
- + String StringFalse = getDisplayValue(context, 0);
- + div[] inputs;
- - option[] options = {new option("---", ""), new option(String1, "1"), new option(String0, "0")};
- - options[0].addElement("---");
- - options[1].addElement(String1);
- - options[2].addElement(String0);
- + input radioNone = new input(input.radio, prefix + name, "");
- + input radioTrue = new input(input.radio, prefix + name, "1");
- + input radioFalse = new input(input.radio, prefix + name, "0");
- + label labelNone = new label();
- + label labelTrue = new label();
- + label labelFalse = new label();
- + div divNone = new div();
- + div divTrue = new div();
- + div divFalse = new div();
- + labelNone.addElement(radioNone);
- + labelNone.addElement(StringNone);
- + divNone.addElement(labelNone);
- + labelTrue.addElement(radioTrue);
- + labelTrue.addElement(StringTrue);
- + divTrue.addElement(labelTrue);
- + labelFalse.addElement(radioFalse);
- + labelFalse.addElement(StringFalse);
- + divFalse.addElement(labelFalse);
- - /*
- - * try { IntegerProperty prop = (IntegerProperty) object.safeget(name); if (prop!=null) { Integer ivalue =
- - * (Integer)prop.getValue(); if (ivalue!=null) { int value = ivalue.intValue(); if (value==1)
- - * options[1].setSelected(true); else if (value==0) options[2].setSelected(true); } else { int value =
- - * getDefaultValue(); if (value==1) options[1].setSelected(true); else if (value==0)
- - * options[2].setSelected(true); } } } catch (Exception e) { // This should not happen e.printStackTrace(); }
- - */
- - select.addElement(options);
- - return select.toString();
- + radioNone.setID(prefix + name + "_none");
- + labelNone.setFor(prefix + name + "_none");
- +
- + radioTrue.setID(prefix + name);
- + labelTrue.setFor(prefix + name);
- +
- + radioFalse.setID(prefix + name + "_false");
- + labelFalse.setFor(prefix + name + "_false");
- +
- + inputs = new div[] {divNone, divTrue, divFalse};
- +
- + String fieldFullName = getFieldFullName();
- + Integer ivalue = (Integer) criteria.getParameter(fieldFullName);
- +
- + if (ivalue != null) {
- + int value = ivalue.intValue();
- + if (value == 1)
- + radioTrue.setChecked(true);
- + else if (value == 0)
- + radioFalse.setChecked(true);
- + else
- + radioNone.setChecked(true);
- + } else {
- + radioNone.setChecked(true);
- + }
- +
- + for (int i = 0; i < inputs.length; i++) {
- + buffer.append(inputs[i].toString());
- + }
- + return buffer.toString();
- }
- + @Override
- + public void makeQuery(Map<String, Object> map, String prefix, XWikiCriteria query, List<String> criteriaList)
- + {
- + Integer value = (Integer) map.get(prefix);
- + if (value != null) {
- + criteriaList.add("@xp:" + getName() + "=" + value.toString());
- + }
- + }
- +
- public String displayCheckboxSearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context)
- {
- StringBuffer buffer = new StringBuffer();
- org.apache.ecs.xhtml.input check = new input(input.checkbox, prefix + name, 1);
- + check.setID(prefix + name);
- org.apache.ecs.xhtml.input checkNo = new input(input.hidden, prefix + name, 0);
- /*
- @@ -411,12 +454,8 @@
- public void fromSearchMap(XWikiQuery query, Map<String, String[]> map)
- {
- String[] data = map.get("");
- - if (data != null) {
- - Object[] data2 = new Object[data.length];
- - for (int i = 0; i < data.length; i++) {
- - data2[i] = fromString(data[i]).getValue();
- - }
- - query.setParam(getObject().getName() + "_" + getName(), data2);
- + if (data != null && data.length > 0) {
- + query.setParam(getObject().getName() + "_" + getName(), fromString(data[0]).getValue());
- }
- }
- }
- Index: src/main/java/com/xpn/xwiki/plugin/query/XWikiCriteria.java
- ===================================================================
- --- src/main/java/com/xpn/xwiki/plugin/query/XWikiCriteria.java (revision 31104)
- +++ src/main/java/com/xpn/xwiki/plugin/query/XWikiCriteria.java (working copy)
- @@ -38,6 +38,31 @@
- return Util.getSubMap(params, field);
- }
- + public void removeParam(String field)
- + {
- + params.remove(field);
- + }
- +
- + public void addSuffix(String field, String suffix)
- + {
- + String sufield = field + "_" + suffix;
- + Object value = params.get(field);
- + if (value != null) {
- + params.remove(field);
- + params.put(sufield, value);
- + }
- + }
- +
- + public void removeSuffix(String field, String suffix)
- + {
- + String sufield = field + "_" + suffix;
- + Object value = params.get(sufield);
- + if (value != null) {
- + params.remove(sufield);
- + params.put(field, value);
- + }
- + }
- +
- public void setParam(String field, Object value)
- {
- params.put(field, value);
Add Comment
Please, Sign In to add comment