if(((String) value).trim().length()>0) {
try {
contentlet.setDateProperty(field.getVelocityVarName(),
DateUtil.convertDate((String)value, dateFormats));
}catch (Exception e) {
throw new DotContentletStateException("Unable to convert string to date " + value);
}
}
else {
contentlet.setDateProperty(field.getVelocityVarName(), null);
}
}else if(field.isRequired() && value==null){
throw new DotContentletStateException("Date fields must either be of type String or Date");
}
}else if(field.getFieldContentlet().startsWith("bool")){
if(value instanceof Boolean){
contentlet.setBoolProperty(field.getVelocityVarName(), (Boolean)value);
}else if(value instanceof String){
try{
String auxValue = (String) value;
Boolean auxBoolean = (auxValue.equalsIgnoreCase("1") || auxValue.equalsIgnoreCase("true") || auxValue.equalsIgnoreCase("t")) ? Boolean.TRUE : Boolean.FALSE;
contentlet.setBoolProperty(field.getVelocityVarName(), auxBoolean);
}catch (Exception e) {
throw new DotContentletStateException("Unable to set string value as a Boolean");
}
}else{
throw new DotContentletStateException("Boolean fields must either be of type String or Boolean");
}
}else if(field.getFieldContentlet().startsWith("float")){
if(value instanceof Number){
contentlet.setFloatProperty(field.getVelocityVarName(),((Number)value).floatValue());
}else if(value instanceof String){
try{
contentlet.setFloatProperty(field.getVelocityVarName(),new Float((String)value));
}catch (Exception e) {
throw new DotContentletStateException("Unable to set string value as a Float");
}
}
}else if(field.getFieldContentlet().startsWith("integer")){
if(value instanceof Number){
contentlet.setLongProperty(field.getVelocityVarName(),((Number)value).longValue());
}else if(value instanceof String){
try{
contentlet.setLongProperty(field.getVelocityVarName(),new Long((String)value));
}catch (Exception e) {
throw new DotContentletStateException("Unable to set string value as a Long");
}
}
// http://jira.dotmarketing.net/browse/DOTCMS-1073
// setBinary
}else if(field.getFieldContentlet().startsWith("binary")){
try{
System.out.println(value.getClass());
contentlet.setBinary(field.getVelocityVarName(), (java.io.File) value);
}catch (Exception e) {
throw new DotContentletStateException("Unable to set binary file Object");
}
}else{
throw new DotContentletStateException("Unable to set value : Unknown field type");
}
}