use of com.xpn.xwiki.objects.ListProperty in project xwiki-platform by xwiki.
the class StaticListClassTest method testDisplayEditWithSuggest.
/**
* Tests the suggest code generated when "use suggest" is set.
*/
@Test
public void testDisplayEditWithSuggest() throws Exception {
ListProperty listProperty = new ListProperty();
listProperty.setValue(VALUES_WITH_HTML_SPECIAL_CHARS);
// Use special XML characters, even if they are not valid inside an XML name, just to test the XML escaping.
String propertyName = "b&a<r";
String prefix = "w>v";
BaseObject object = new BaseObject();
object.addField(propertyName, listProperty);
StaticListClass staticListClass = new StaticListClass();
BaseClass ownerClass = new BaseClass();
ownerClass.setDocumentReference(new DocumentReference("xwiki", "ClassSpace", "ClassName"));
staticListClass.setName(propertyName);
staticListClass.setObject(ownerClass);
staticListClass.setSize(7);
StringBuilder values = new StringBuilder();
for (String value : VALUES_WITH_HTML_SPECIAL_CHARS) {
if (values.length() > 0) {
values.append('|');
}
values.append(value).append('=').append(StringUtils.reverse(value));
}
staticListClass.setValues(values.toString());
staticListClass.setDisplayType("input");
staticListClass.setPicker(true);
doReturn("/xwiki/bin/view/Main/WebHome").when(this.oldcore.getSpyXWiki()).getURL("Main.WebHome", "view", this.oldcore.getXWikiContext());
String output = staticListClass.displayEdit(propertyName, prefix, object, this.oldcore.getXWikiContext());
System.err.println(output);
assertTrue(output.contains("new ajaxSuggest(this, {script:"/xwiki/bin/view/Main/WebHome?xpage=suggest&" + "classname=ClassSpace.ClassName&fieldname=b&a<r&firCol=-&" + "secCol=-&", varname:"input"} )"));
}
use of com.xpn.xwiki.objects.ListProperty in project xwiki-platform by xwiki.
the class StaticListClassTest method testDisplayHidden.
/**
* Tests the hidden display type.
*/
@Test
public void testDisplayHidden() {
ListProperty listProperty = new ListProperty();
listProperty.setValue(VALUES_WITH_HTML_SPECIAL_CHARS);
// Use special XML characters, even if they are not valid inside an XML name, just to test the XML escaping.
String propertyName = "f<o&o";
BaseObject object = new BaseObject();
object.addField(propertyName, listProperty);
assertEquals("<input id='f<o&o' value='a<b>c|1"2'3|x{y&z' " + "name='f<o&o' type='hidden'/>", new StaticListClass().displayHidden(propertyName, "", object, null));
}
use of com.xpn.xwiki.objects.ListProperty in project xwiki-platform by xwiki.
the class StaticListClassTest method testDisplayEdit.
/**
* Tests the HTML output produced in edit mode.
*
* @param displayType the display type (input, radio, select, etc.)
* @param selectedValues the selected values
* @param expectedHTML the expected HTML output
*/
private void testDisplayEdit(String displayType, List<String> selectedValues, String expectedHTML) {
ListProperty listProperty = new ListProperty();
listProperty.setValue(selectedValues);
// Use special XML characters, even if they are not valid inside an XML name, just to test the XML escaping.
String propertyName = "b&a<r";
String prefix = "w>v";
BaseObject object = new BaseObject();
object.addField(propertyName, listProperty);
StaticListClass staticListClass = new StaticListClass();
staticListClass.setSize(7);
StringBuilder values = new StringBuilder();
for (String value : VALUES_WITH_HTML_SPECIAL_CHARS) {
if (values.length() > 0) {
values.append('|');
}
values.append(value).append('=').append(StringUtils.reverse(value));
}
staticListClass.setValues(values.toString());
staticListClass.setDisplayType(displayType);
assertEquals(expectedHTML, staticListClass.displayEdit(propertyName, prefix, object, null));
}
use of com.xpn.xwiki.objects.ListProperty in project xwiki-platform by xwiki.
the class DBListClass method displayView.
@Override
public void displayView(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
List<String> selectlist;
String separator = getSeparator();
BaseProperty prop = (BaseProperty) object.safeget(name);
Map<String, ListItem> map = getMap(context);
// Skip unset values.
if (prop == null) {
return;
}
if (prop instanceof ListProperty) {
selectlist = ((ListProperty) prop).getList();
List<String> newlist = new ArrayList<>();
for (String entry : selectlist) {
newlist.add(getDisplayValue(entry, name, map, context));
}
buffer.append(StringUtils.join(newlist, separator));
} else {
buffer.append(getDisplayValue(prop.getValue(), name, map, context));
}
}
use of com.xpn.xwiki.objects.ListProperty in project xwiki-platform by xwiki.
the class DBTreeListClass method displayTreeSelectEdit.
protected void displayTreeSelectEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
select select = new select(prefix + name, 1);
select.setAttributeFilter(new XMLAttributeValueFilter());
select.setMultiple(isMultiSelect());
select.setSize(getSize());
select.setName(prefix + name);
select.setID(prefix + name);
select.setDisabled(isDisabled());
Map<String, ListItem> map = getMap(context);
Map<String, List<ListItem>> treemap = getTreeMap(context);
List<String> selectlist;
BaseProperty prop = (BaseProperty) object.safeget(name);
if (prop == null) {
selectlist = new ArrayList<String>();
} else if (prop instanceof ListProperty) {
selectlist = ((ListProperty) prop).getList();
} else {
selectlist = new ArrayList<String>();
selectlist.add(String.valueOf(prop.getValue()));
}
// Add options from Set
addToSelect(select, selectlist, map, treemap, "", "", context);
buffer.append(select.toString());
}
Aggregations