Search in sources :

Example 1 with ListProperty

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, &#123;script:&#34;/xwiki/bin/view/Main/WebHome?xpage=suggest&#38;" + "classname=ClassSpace.ClassName&#38;fieldname=b&#38;a&#60;r&#38;firCol=-&#38;" + "secCol=-&#38;&#34;, varname:&#34;input&#34;} )"));
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 2 with ListProperty

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&#60;o&#38;o' value='a&#60;b&#62;c|1&#34;2&#39;3|x&#123;y&#38;z' " + "name='f&#60;o&#38;o' type='hidden'/>", new StaticListClass().displayHidden(propertyName, "", object, null));
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 3 with ListProperty

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));
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 4 with ListProperty

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));
    }
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) ArrayList(java.util.ArrayList) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 5 with ListProperty

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());
}
Also used : ListProperty(com.xpn.xwiki.objects.ListProperty) org.apache.ecs.xhtml.select(org.apache.ecs.xhtml.select) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Aggregations

ListProperty (com.xpn.xwiki.objects.ListProperty)12 BaseProperty (com.xpn.xwiki.objects.BaseProperty)7 ArrayList (java.util.ArrayList)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)4 StringListProperty (com.xpn.xwiki.objects.StringListProperty)4 Test (org.junit.Test)3 StringProperty (com.xpn.xwiki.objects.StringProperty)2 XWikiException (com.xpn.xwiki.XWikiException)1 XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)1 BaseCollection (com.xpn.xwiki.objects.BaseCollection)1 BaseStringProperty (com.xpn.xwiki.objects.BaseStringProperty)1 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 org.apache.ecs.xhtml.select (org.apache.ecs.xhtml.select)1 Element (org.dom4j.Element)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1 Session (org.hibernate.Session)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1