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);
}
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());
}
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;
}
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));
}
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()));
}
Aggregations