1 package org.mdarad.framework.util.struts; 2 3 import java.io.FileNotFoundException ; 4 import java.io.IOException ; 5 6 import org.apache.struts.upload.FormFile; 7 import org.dataisland.primitives.datatype.Blob; 8 9 public class PrimitiveToStrutsBeanFormTypeMappings { 10 11 public static Object getEntityPropertyValueFromStrutsBeanPropertyValue(String dataislandPrimitiveName, Object oldPOJOValue, Object newFormValue) { 12 Object output = null; 13 if("blob".equals(dataislandPrimitiveName)) { 14 15 output = getBlobValue((Blob) oldPOJOValue, (FormFile) newFormValue); 16 17 } else if("percentage".equals(dataislandPrimitiveName)) { 18 Float formFloat = (Float ) newFormValue; 19 20 if(formFloat != null) { 21 output = new Float (formFloat.floatValue() / 100); 22 } 23 } else { 24 output = newFormValue; 25 } 26 return output; 27 } 28 29 public static Blob getBlobValue(Blob oldPOJOValue, FormFile newFormValue) { 30 Blob output = null; 31 32 if(newFormValue == null) { 33 output = oldPOJOValue; 34 } else { 35 FormFile formFile = (FormFile) newFormValue; 36 if(formFile != null && formFile.getFileSize() > 0) { 37 try { 38 Blob blob = new Blob(); 39 blob.setContent(formFile.getFileData()); 40 blob.setContentType(formFile.getContentType()); 41 blob.setFileName(formFile.getFileName()); 42 output = blob; 43 } catch (FileNotFoundException e) { 44 e.printStackTrace(); 46 } catch (IOException e) { 47 e.printStackTrace(); 49 } 50 } 51 } 52 return output; 53 } 54 55 public static Object getStrutsBeanPropertyValueFromEntityPropertyValue(String dataislandPrimitiveName, Object currentPOJOValue) { 56 Object output = null; 57 58 if("blob".equals(dataislandPrimitiveName)) { 59 } else if("percentage".equals(dataislandPrimitiveName)) { 61 Float beanFloat = (Float ) currentPOJOValue; 62 63 if(beanFloat != null) { 64 output = new Float (beanFloat.floatValue() * 100); 65 } 66 } else { 67 output = currentPOJOValue; 68 } 69 70 return output; 71 } 72 73 } 74 | Popular Tags |