use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class DateClass method fromString.
@Override
public BaseProperty fromString(String value) {
BaseProperty property = newProperty();
if (StringUtils.isEmpty(value)) {
if (getEmptyIsToday() == 1) {
property.setValue(new Date());
}
return property;
}
try {
SimpleDateFormat sdf = new SimpleDateFormat(getDateFormat(), getCurrentLocale());
property.setValue(sdf.parse(value));
return property;
} catch (ParseException e) {
return null;
}
}
use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class DateClass method newPropertyfromXML.
/**
* {@inheritDoc}
* <p>
* We have to overwrite this method because the value of a date property is not serialized using the date format
* specified in the XClass nor the time stamp but a custom hard-coded date format.. Changing this now will break
* existing XARs..
* </p>
*/
@Override
public BaseProperty newPropertyfromXML(Element element) {
String value = element.getText();
BaseProperty property = newProperty();
if (StringUtils.isEmpty(value)) {
return property;
}
// FIXME: The value of a date property should be serialized using the date timestamp or the date format
// specified in the XClass the date property belongs to.
SimpleDateFormat sdf = DateXarObjectPropertySerializer.DEFAULT_FORMAT;
try {
property.setValue(sdf.parse(value));
} catch (ParseException e) {
// I suppose this is a date format used a long time ago. DateProperty is using the above date format now.
SimpleDateFormat sdfOld = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.US);
LOGGER.warn("Failed to parse date [{}] using format [{}]. Trying again with format [{}].", value, sdf.toString(), sdfOld.toString());
try {
property.setValue(sdfOld.parse(value));
} catch (ParseException exception) {
LOGGER.warn("Failed to parse date [{}] using format [{}]. Defaulting to the current date.", value, sdfOld.toString());
property.setValue(new Date());
}
}
return property;
}
use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class GroupsClass method fromString.
@Override
public BaseProperty fromString(String value) {
BaseProperty prop = newProperty();
prop.setValue(value);
return prop;
}
use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class GroupsClass method fromStringArray.
@Override
public BaseProperty fromStringArray(String[] strings) {
List<String> list = Arrays.asList(strings);
BaseProperty prop = newProperty();
fromList(prop, list);
return prop;
}
use of com.xpn.xwiki.objects.BaseProperty in project xwiki-platform by xwiki.
the class LevelsClass method fromStringArray.
@Override
public BaseProperty fromStringArray(String[] strings) {
List<String> list = new ArrayList<String>();
for (int i = 0; i < strings.length; i++) {
if (!strings[i].trim().equals("")) {
list.add(strings[i]);
}
}
BaseProperty prop = newProperty();
fromList(prop, list);
return prop;
}
Aggregations