Search in sources :

Example 36 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class ListClass method displayRadioEdit.

protected void displayRadioEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    List<String> list = getList(context);
    Map<String, ListItem> map = getMap(context);
    BaseProperty prop = (BaseProperty) object.safeget(name);
    List<String> selectlist = toList(prop);
    // Add the selected values that are not in the predefined list.
    for (String item : selectlist) {
        // single selection is on) so we don't have to generate a radio/checkbox for the empty value.
        if (!StringUtils.isEmpty(item) && !list.contains(item)) {
            list.add(item);
        }
    }
    // Add options from Set
    int count = 0;
    for (Object rawvalue : list) {
        String value = getElementValue(rawvalue);
        String display = XMLUtils.escape(getDisplayValue(rawvalue, name, map, context));
        input radio = new input((getDisplayType().equals(DISPLAYTYPE_RADIO) && !isMultiSelect()) ? input.radio : input.checkbox, prefix + name, value);
        radio.setAttributeFilter(new XMLAttributeValueFilter());
        radio.setID("xwiki-form-" + name + "-" + object.getNumber() + "-" + count);
        radio.setDisabled(isDisabled());
        if (selectlist.contains(value)) {
            radio.setChecked(true);
        }
        radio.addElement(display);
        buffer.append("<label class=\"xwiki-form-listclass\" for=\"xwiki-form-" + XMLUtils.escape(name) + "-" + object.getNumber() + "-" + count++ + "\">");
        buffer.append(radio.toString());
        buffer.append("</label>");
    }
    // We need a hidden input with an empty value to be able to clear the selected values when no value is selected
    // from the above radio/checkbox buttons.
    org.apache.ecs.xhtml.input hidden = new input(input.hidden, prefix + name, "");
    hidden.setAttributeFilter(new XMLAttributeValueFilter());
    hidden.setDisabled(isDisabled());
    buffer.append(hidden);
}
Also used : org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 37 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class NumberClass method displayEdit.

@Override
public void displayEdit(StringBuffer buffer, String name, String prefix, BaseCollection object, XWikiContext context) {
    input input = new input();
    input.setAttributeFilter(new XMLAttributeValueFilter());
    BaseProperty prop = (BaseProperty) object.safeget(name);
    if (prop != null) {
        input.setValue(prop.toText());
    }
    input.setType("text");
    input.setName(prefix + name);
    input.setID(prefix + name);
    input.setSize(getSize());
    input.setDisabled(isDisabled());
    buffer.append(input.toString());
}
Also used : org.apache.ecs.xhtml.input(org.apache.ecs.xhtml.input) XMLAttributeValueFilter(com.xpn.xwiki.internal.xml.XMLAttributeValueFilter) BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 38 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class NumberClass method fromString.

@Override
public BaseProperty fromString(String value) {
    BaseProperty property = newProperty();
    String ntype = getNumberType();
    Number nvalue = null;
    try {
        if (ntype.equals("integer")) {
            if ((value != null) && (!value.equals(""))) {
                nvalue = Integer.valueOf(value);
            }
        } else if (ntype.equals("float")) {
            if ((value != null) && (!value.equals(""))) {
                nvalue = Float.valueOf(value);
            }
        } else if (ntype.equals("double")) {
            if ((value != null) && (!value.equals(""))) {
                nvalue = Double.valueOf(value);
            }
        } else {
            if ((value != null) && (!value.equals(""))) {
                nvalue = Long.valueOf(value);
            }
        }
    } catch (NumberFormatException e) {
        LOG.warn("Invalid number entered for property " + getName() + " of class " + getObject().getName() + ": " + value);
        // Returning null makes sure that the old value (if one exists) will not be discarded/replaced
        return null;
    }
    property.setValue(nvalue);
    return property;
}
Also used : BaseProperty(com.xpn.xwiki.objects.BaseProperty)

Example 39 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class DateClassTest method fromString.

@Test
public void fromString() {
    DateClass dateClass = new DateClass();
    dateClass.setDateFormat("MMMM yyyy");
    when(localizationContext.getCurrentLocale()).thenReturn(new Locale("ro"));
    BaseProperty property = dateClass.fromString("octombrie 2015");
    Date date = (Date) property.getValue();
    assertEquals("10 2015", new SimpleDateFormat("MM yyyy").format(date));
}
Also used : Locale(java.util.Locale) BaseProperty(com.xpn.xwiki.objects.BaseProperty) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 40 with BaseProperty

use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.

the class NumberClassTest method testFromString.

/**
 * Test the fromString method.
 */
@Test
public void testFromString() {
    // Create a default Number property
    NumberClass nc = new NumberClass();
    BaseClass bc = new BaseClass();
    bc.setName("Some.Class");
    nc.setObject(bc);
    // A String value containing non-numeric caracters can not be respresented as a numeric value, so this sould
    // return null
    assertNull(nc.fromString("asd"));
    // A much too long number cannot be represented as a long value, so this should also return null
    assertNull(nc.fromString("1111111111111111111111111111111111"));
    BaseProperty p;
    // A null value should lead to creating an object with an empty value
    p = nc.fromString(null);
    assertNotNull(p);
    assertNull(p.getValue());
    // An empty String should lead to creating an object with an empty value
    p = nc.fromString("");
    assertNotNull(p);
    assertNull(p.getValue());
    // An integer value should lead to creating an object containing that integer as value
    p = nc.fromString("4");
    assertNotNull(p);
    assertEquals(4, Integer.parseInt(p.getValue().toString()));
}
Also used : BaseProperty(com.xpn.xwiki.objects.BaseProperty) Test(org.junit.Test)

Aggregations

BaseProperty (com.xpn.xwiki.objects.BaseProperty)87 BaseObject (com.xpn.xwiki.objects.BaseObject)26 ArrayList (java.util.ArrayList)16 XWikiException (com.xpn.xwiki.XWikiException)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)12 XMLAttributeValueFilter (com.xpn.xwiki.internal.xml.XMLAttributeValueFilter)12 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)11 XWikiContext (com.xpn.xwiki.XWikiContext)10 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)9 DocumentReference (org.xwiki.model.reference.DocumentReference)9 StringProperty (com.xpn.xwiki.objects.StringProperty)8 ListProperty (com.xpn.xwiki.objects.ListProperty)7 XWiki (com.xpn.xwiki.XWiki)5 BaseCollection (com.xpn.xwiki.objects.BaseCollection)5 LargeStringProperty (com.xpn.xwiki.objects.LargeStringProperty)5 List (java.util.List)5 Test (org.junit.Test)5 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)5 DBStringListProperty (com.xpn.xwiki.objects.DBStringListProperty)4 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)4