use of org.apache.chemistry.opencmis.commons.data.PropertyDecimal in project iaf by ibissource.
the class CmisUtils method getPropertyXml.
public static XmlBuilder getPropertyXml(PropertyData<?> property) {
XmlBuilder propertyXml = new XmlBuilder("property");
propertyXml.addAttribute("name", property.getId());
propertyXml.addAttribute("displayName", property.getDisplayName());
propertyXml.addAttribute("localName", property.getLocalName());
propertyXml.addAttribute("queryName", property.getQueryName());
PropertyType propertyType = PropertyType.STRING;
if (property instanceof Property) {
propertyType = ((Property<?>) property).getType();
} else {
if (property instanceof PropertyId) {
propertyType = PropertyType.ID;
} else if (property instanceof PropertyBoolean) {
propertyType = PropertyType.BOOLEAN;
} else if (property instanceof PropertyUri) {
propertyType = PropertyType.URI;
} else if (property instanceof PropertyInteger) {
propertyType = PropertyType.INTEGER;
} else if (property instanceof PropertyHtml) {
propertyType = PropertyType.HTML;
} else if (property instanceof PropertyDecimal) {
propertyType = PropertyType.DECIMAL;
} else if (property instanceof PropertyString) {
propertyType = PropertyType.STRING;
} else if (property instanceof PropertyDateTime) {
propertyType = PropertyType.DATETIME;
}
}
// If it's not a property, what would it be? assume its a string...
propertyXml.addAttribute("type", propertyType.value());
Object value = property.getFirstValue();
if (value == null) {
propertyXml.addAttribute("isNull", "true");
} else {
switch(propertyType) {
case INTEGER:
BigInteger bi = (BigInteger) value;
propertyXml.setValue(String.valueOf(bi));
break;
case BOOLEAN:
Boolean b = (Boolean) value;
propertyXml.setValue(String.valueOf(b));
break;
case DATETIME:
GregorianCalendar gc = (GregorianCalendar) value;
SimpleDateFormat sdf = new SimpleDateFormat(FORMATSTRING_BY_DEFAULT);
propertyXml.setValue(sdf.format(gc.getTime()));
break;
default:
// String/ID/HTML/URI
propertyXml.setValue((String) value);
break;
}
}
return propertyXml;
}
Aggregations