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; }
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; }
@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; }
buf.append(aUrl[i] + URL_SEPARATOR); ListItem item = new ListItem(buf.toString(), aUrl[i], parentBuf); if (!fileTree.containsKey(buf.toString())) { res.add(item);
buf.append(aUrl[i] + URL_SEPARATOR); ListItem item = new ListItem(buf.toString(), aUrl[i], parentBuf); if (!fileTree.containsKey(buf.toString())) { res.add(item);
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); } } }