@Override public BaseProperty fromStringArray(String[] strings) { if (!isMultiSelect()) { return fromString(strings[0]); } BaseProperty prop = newProperty(); if (prop instanceof StringProperty) { return fromString(strings[0]); } List<String> list = new ArrayList<String>(); ((ListProperty) prop).setList(list); if (strings.length == 0) { return prop; } if ((strings.length == 1) && (getDisplayType().equals("input") || isMultiSelect())) { ((ListProperty) prop).setList(getListFromString(strings[0], getSeparators(), false)); return prop; } // If Multiselect and multiple results for (int i = 0; i < strings.length; i++) { String item = strings[i]; if (!item.trim().equals("")) { list.add(item); } } return prop; }
protected String displayRadioSearch(String name, String prefix, XWikiCriteria criteria, 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()); } */ // Add options from Set for (Iterator<String> it = list.iterator(); it.hasNext();) { String rawvalue = it.next(); 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); if (selectlist.contains(value)) { radio.setChecked(true); } radio.addElement(display); buffer.append(radio.toString()); if (it.hasNext()) { buffer.append("<br/>"); } } return buffer.toString(); }
@Override public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) { if (getDisplayType().equals("input")) { input input = new input(); BaseProperty prop = (BaseProperty) object.safeget(name); if (prop != null) { input.setValue(prop.toFormString()); } input.setType("text"); input.setSize(getSize()); input.setName(prefix + name); input.setID(prefix + name); input.setDisabled(isDisabled()); buffer.append(input.toString()); } else if (getDisplayType().equals("radio") || getDisplayType().equals("checkbox")) { displayRadioEdit(buffer, name, prefix, object, context); } else { displaySelectEdit(buffer, name, prefix, object, context); } if (!getDisplayType().equals("input")) { org.apache.ecs.xhtml.input hidden = new input(input.hidden, prefix + name, ""); buffer.append(hidden); } }
@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") || getDisplayType().equals("checkbox")) { return displayRadioSearch(name, prefix, criteria, context); } else { return displaySelectSearch(name, prefix, criteria, context); } }
@Override public BaseProperty fromString(String value) { BaseProperty prop = newProperty(); if (isMultiSelect()) { ((ListProperty) prop).setList(getListFromString(value, getSeparators(), false)); } else { prop.setValue(value); } return prop; }
select.setMultiple(isMultiSelect()); select.setSize(getSize()); select.setName(prefix + name); select.setID(prefix + name); select.setDisabled(isDisabled()); List<String> list = getList(context); Map<String, ListItem> map = getMap(context); String sort = getSort(); if (!"none".equals(sort)) { if ("id".equals(sort)) { String value = getElementValue(rawvalue); String display = getDisplayValue(rawvalue, name, map, context); option option = new option(display, value); option.addElement(display);
protected void displayRadioEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) List<String> list = getList(context); Map<String, ListItem> map = getMap(context); List<String> selectlist; String value = getElementValue(rawvalue); input radio = new input((getDisplayType().equals("radio") && !isMultiSelect()) ? input.radio : input.checkbox, prefix + name, value); radio.setID("xwiki-form-" + name + "-" + count); radio.setDisabled(isDisabled()); radio.addElement(getDisplayValue(rawvalue, name, map, context));
public static List<String> getListFromString(String value) { return getListFromString(value, "|", true); }
protected String displaySelectSearch(String name, String prefix, XWikiCriteria criteria, XWikiContext context) { select select = new select(prefix + name, 1); select.setMultiple(true); select.setSize(5); select.setName(prefix + name); select.setID(prefix + name); List<String> list = getList(context); 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); option option = new option(display, value); option.addElement(display); if (selectlist.contains(value)) { option.setSelected(true); } select.addElement(option); } return select.toString(); }
/** * If the property is a {@link ListClass}, returns the possible values. These are the internal values (keys), and * not the user-friendly or translated values that would be displayed to the user. * * @return the list of possible ({@code String}) values * @see #getMapValues() {@code getMapValues()} returns both the keys and their user-friendly displayed values **/ public List<String> getListValues() { com.xpn.xwiki.objects.classes.PropertyClass pclass = getBasePropertyClass(); if (pclass instanceof ListClass) { return ((ListClass) pclass).getList(this.context); } else { // Although we prefer to return empty lists from API methods, here returning any kind of list doesn't make // sense, since the property does not have a list of possible values at all (like, a number property). return null; } }
@Override public boolean updateProperty(String docname, String className, String propertyname, List value) throws XWikiGWTException { XWikiContext context = null; try { context = getXWikiContext(); if (context.getWiki().getRightService().hasAccessLevel("edit", context.getUser(), docname, context) == true) { XWikiDocument doc = context.getWiki().getDocument(docname, context); BaseClass bclass = context.getWiki().getClass(className, context); ListClass lclass = (ListClass) ((bclass == null) ? null : bclass.get(propertyname)); BaseProperty prop = lclass.fromValue(value); doc.setProperty(className, propertyname, prop); doc.setAuthor(context.getUser()); context.getWiki().saveDocument(doc, localizePlainOrKey("core.comment.updateProperty"), context); return true; } else return false; } catch (Exception e) { throw getXWikiGWTException(e); } }
public void setTextValue(String value) { setList(ListClass.getListFromString(value)); }
ListClass listClass = (ListClass) propertyClass; List allowedValueList = listClass.getList(xwikiContext);
public List<String> getTagsPossibleValues(XWikiContext context) { List<String> list; try { BaseClass tagsClass = context.getWiki().getTagClass(context); String possibleValues = ((StaticListClass) tagsClass.getField(XWikiConstant.TAG_CLASS_PROP_TAGS)).getValues(); return ListClass.getListFromString(possibleValues); } catch (XWikiException e) { LOG.error("Failed to get tag class", e); list = Collections.emptyList(); } return list; }
result.setPropertyAllowedValues(propertyName, listClass.getList(xwikiContext));
ListClass.getListFromString(right.getStringValue(userOrGroupField), RIGHTSLISTFIELD_SEP, false);
ListClass.getListFromString(bobj.getStringValue(RIGHTSFIELD_USERS), RIGHTSLISTFIELD_SEP, false); List<String> groups = ListClass.getListFromString(bobj.getStringValue(RIGHTSFIELD_GROUPS), RIGHTSLISTFIELD_SEP, false); List<String> levels = ListClass.getListFromString(bobj.getStringValue(RIGHTSFIELD_LEVELS), RIGHTSLISTFIELD_SEP, false); boolean allow = (bobj.getIntValue(RIGHTSFIELD_ALLOW) == 1);
/** * Insert in XWiki.XWikiPreferences "documentBundles" field the translation documents of the provided application. * * @param app the application descriptor. * @param comment a comment used when saving XWiki. * @param context the XWiki context. * @throws XWikiException error when : * <ul> * <li>getting wiki preferences document.</li> * <li>or saving wiki preferences document.</li> * </ul> */ public void updateApplicationTranslation(XWikiApplication app, String comment, XWikiContext context) throws XWikiException { XWiki xwiki = context.getWiki(); XWikiDocument prefsDoc = xwiki.getDocument(XWIKIPREFERENCES, context); BaseObject prefsObject = prefsDoc.getObject(XWIKIPREFERENCES); if (prefsObject != null) { String documentBundles = prefsObject.getStringValue(XWIKIPREFERENCES_DOCUMENTBUNDLES); List<String> translationPrefs = ListClass.getListFromString(documentBundles, XWIKIPREFERENCES_DOCUMENTBUNDLES_SEP, true); boolean updateprefs = updateApplicationTranslation(translationPrefs, app); if (updateprefs) { prefsObject.setStringValue(XWIKIPREFERENCES_DOCUMENTBUNDLES, StringUtils.join(translationPrefs.toArray(), XWIKIPREFERENCES_DOCUMENTBUNDLES_SEP)); xwiki.saveDocument(prefsDoc, comment, context); } } }
newProperty.setName(oldProperty.getName()); newProperty.setList(ListClass.getListFromString(oldProperty.getValue(), ",", false));
String documentBundles = prefsObject.getStringValue(XWIKIPREFERENCES_DOCUMENTBUNDLES); List<String> translationPrefs = ListClass.getListFromString(documentBundles, XWIKIPREFERENCES_DOCUMENTBUNDLES_SEP, true);