protected void addToTreeList(List<ListItem> treelist, Map<String, List<ListItem>> treemap, Map<String, ListItem> map, String parent, XWikiContext context) { List<ListItem> list = treemap.get(parent); if (list != null) { for (ListItem item : list) { ListItem item2 = new ListItem(item.getId(), getDisplayValue(item.getId(), "", map, context), item.getParent()); treelist.add(item2); addToTreeList(treelist, treemap, map, item.getId(), context); } } }
/** * Constructor that initializes all of the {@link #id internal ID}, the {@link #value displayed value}, and the * {@link #parent} fields. * * @param id the value to use for the internal id * @param value the value to use for the displayed value * @param parent the value to use for the item's parent */ public ListItem(String id, String value, String parent) { this.setId(id); this.setValue(value); this.setParent(parent); }
/** * Constructor that initializes both the {@link #id internal ID} and the {@link #value displayed value} with the * same value, leaving the {@link #parent} field empty. * * @param id the value to use for the id and the displayed value */ public ListItem(String id) { this.setId(id); this.setValue(id); }
/** * Sorts the items on their value: the option with the lower value (case insensitive String comparison) will be * placed before the other one. * * @param o1 the first item to be compared. * @param o2 the second item to be compared. * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or * greater than the second. */ public int compare(ListItem o1, ListItem o2) { return BASE_COMPARATOR.compare(o1.getValue(), o2.getValue()); } });
private void indexStaticList(Document luceneDoc, BaseObject baseObject, StaticListClass prop, String propertyName, XWikiContext context) { Map<String, ListItem> possibleValues = prop.getMap(context); String fieldFullName = baseObject.getClassName() + "." + propertyName; for (String value : (List<String>) baseObject.getListValue(propertyName)) { ListItem item = possibleValues.get(value); if (item != null) { // We index the key of the list String fieldName = fieldFullName + ".key"; addFieldToDocument(fieldName, item.getId(), Field.Store.YES, Field.Index.ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); // We index the value fieldName = fieldFullName + ".value"; addFieldToDocument(fieldName, item.getValue(), Field.Store.YES, Field.Index.ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); // If the key and value are not the same, we index both // The key is always indexed outside the if block, so here we just index the value if (!item.getId().equals(item.getValue())) { addFieldToDocument(fieldFullName, item.getValue(), Field.Store.YES, Field.Index.ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); } } addFieldToDocument(fieldFullName, value, Field.Store.YES, Field.Index.ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); } }
@Override public Map<String, ListItem> getMap(XWikiContext context) { List<ListItem> list = getDBList(context); Map<String, ListItem> result = new HashMap<String, ListItem>(); if ((list == null) || (list.size() == 0)) { return result; } for (int i = 0; i < list.size(); i++) { Object res = list.get(i); if (res instanceof String) { result.put((String) res, new ListItem((String) res)); } else { ListItem item = (ListItem) res; result.put(item.getId(), item); } } return result; }
/** * Sorts the items on their ID: the option with the lower ID (case insensitive String comparison) will be placed * before the other one. * * @param o1 the first item to be compared. * @param o2 the second item to be compared. * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or * greater than the second. */ public int compare(ListItem o1, ListItem o2) { return BASE_COMPARATOR.compare(o1.getId(), o2.getId()); } });
public static Map<String, ListItem> getMapFromString(String value) { Map<String, ListItem> map = new HashMap<String, ListItem>(); if (value == null) { return map; } String val = StringUtils.replace(value, "\\|", "%PIPE%"); String[] result = StringUtils.split(val, "|"); for (int i = 0; i < result.length; i++) { String element = StringUtils.replace(result[i], "%PIPE%", "|"); if (element.indexOf('=') != -1) { String[] data = StringUtils.split(element, "="); map.put(data[0], new ListItem(data[0], data[1])); } else { map.put(element, new ListItem(element, element)); } } return map; }
private List<ListItem> getItemPath(String item, List<ListItem> treeList, ArrayList<ListItem> resList) { for (ListItem tmpItem : treeList) { if (item.equals(tmpItem.getId())) { if (tmpItem.getParent().length() > 0) { getItemPath(tmpItem.getParent(), treeList, resList); } resList.add(tmpItem); return resList; } } return null; }
public Map<String, List<ListItem>> getTreeMap(XWikiContext context) { List<ListItem> list = getDBList(context); Map<String, List<ListItem>> map = new HashMap<String, List<ListItem>>(); if ((list == null) || (list.size() == 0)) { return map; } // The root of the tree is considered to be the empty string. // Make sure that entries with invalid parents end up in the tree. // TODO: Detect cycles, as these also don't appear in the tree. List<String> validParents = this.getList(context); for (ListItem item : list) { if (validParents.contains(item.getParent())) { addToList(map, item.getParent(), item); } else { addToList(map, "", item); } } return map; }
@Override public List<String> getList(XWikiContext context) { List<ListItem> dblist = getDBList(context); String sort = getSort(); if ("id".equals(sort)) { Collections.sort(dblist, ListItem.ID_COMPARATOR); } else if ("value".equals(sort)) { Collections.sort(dblist, ListItem.VALUE_COMPARATOR); } List<String> result = new ArrayList<String>(dblist.size()); for (ListItem value : dblist) { result.add(value.getId()); } return result; }
public List<ListItem> makeList(List<Object> list) { List<ListItem> result = new ArrayList<ListItem>(); for (Object item : list) { // Oracle databases treat NULL and empty strings similarly. Thus the list passed // as parameter can have some elements being NULL (for XWiki string properties which // were empty strings). This means we need to check for NULL and ignore NULL entries // from the list. if (item != null) { if (item instanceof String) { result.add(new ListItem((String) item)); } else { Object[] res = (Object[]) item; if (res.length == 1) { result.add(new ListItem(res[0].toString())); } else if (res.length == 2) { result.add(new ListItem(res[0].toString(), res[1].toString())); } else { result.add(new ListItem(res[0].toString(), res[1].toString(), res[2].toString())); } } } } return result; }
/** * Constructor that initializes the {@link #id internal ID} and the {@link #value displayed value}, leaving the * {@link #parent} field empty. * * @param id the value to use for the internal id * @param value the value to use for the displayed value */ public ListItem(String id, String value) { this.setId(id); this.setValue(value); }
protected String renderItemsList(List<List<ListItem>> resList) { StringBuffer buff = new StringBuffer(); for (int i = 0; i < resList.size(); i++) { List<ListItem> items = resList.get(i); for (int j = 0; j < items.size(); j++) { ListItem item = items.get(j); buff.append(item.getValue()); if (j < items.size() - 1) { buff.append(" > "); } } if (i < resList.size() - 1) { buff.append("<br />"); } } return buff.toString(); }
protected void addToSelect(select select, List<String> selectlist, Map<String, ListItem> map, Map<String, List<ListItem>> treemap, String parent, String level, XWikiContext context) { List<ListItem> list = treemap.get(parent); if (list != null) { for (ListItem item : list) { String display = level + getDisplayValue(item.getId(), "", map, context); option option = new option(display, item.getId()); option.addElement(display); if (selectlist.contains(item.getId())) { option.setSelected(true); } select.addElement(option); addToSelect(select, selectlist, map, treemap, item.getId(), level + " ", context); } } }
buf.append(aUrl[i] + URL_SEPARATOR); ListItem item = new ListItem(buf.toString(), aUrl[i], parentBuf); if (!fileTree.containsKey(buf.toString())) { res.add(item);
@Override public List<String> getList(XWikiContext context) { String sort = getSort(); if (StringUtils.isEmpty(sort) || "none".equals(sort)) { return getListFromString(getValues()); } Map<String, ListItem> valuesMap = getMap(context); List<ListItem> values = new ArrayList<ListItem>(valuesMap.size()); values.addAll(valuesMap.values()); if ("id".equals(sort)) { Collections.sort(values, ListItem.ID_COMPARATOR); } else if ("value".equals(sort)) { Collections.sort(values, ListItem.VALUE_COMPARATOR); } List<String> result = new ArrayList<String>(values.size()); for (ListItem value : values) { result.add(value.getId()); } return result; }