1 16 package dlog4j.formbean; 17 18 import java.util.Arrays ; 19 import java.util.List ; 20 21 import javax.servlet.http.HttpServletRequest ; 22 23 import org.apache.commons.lang.StringUtils; 24 import org.apache.struts.action.ActionError; 25 import org.apache.struts.action.ActionErrors; 26 import org.apache.struts.action.ActionMapping; 27 import org.apache.struts.upload.FormFile; 28 29 33 public class UploadImageForm extends DlogActionForm { 34 35 FormFile uploadFile = null; 36 String imageUrl = null; 37 String displayText = null; 38 String txtWidth = null; 39 String txtHeight = null; 40 String txtBorder = null; 41 String txtAlign = "left"; 42 43 46 public ActionErrors validate(ActionMapping mapping, HttpServletRequest req) { 47 ActionErrors aes = new ActionErrors(); 48 try { 49 if(!StringUtils.isEmpty(txtWidth)) 50 Integer.parseInt(txtWidth); 51 }catch(Exception e) { 52 aes.add("txtWidth",new ActionError("illegal_input_value")); 53 } 54 try { 55 if(!StringUtils.isEmpty(txtHeight)) 56 Integer.parseInt(txtHeight); 57 }catch(Exception e) { 58 aes.add("txtHeight",new ActionError("illegal_input_value")); 59 } 60 try { 61 if(!StringUtils.isEmpty(txtBorder)) 62 Integer.parseInt(txtBorder); 63 }catch(Exception e) { 64 aes.add("txtBorder",new ActionError("illegal_input_value")); 65 } 66 if(uploadFile!=null){ 67 if(uploadFile.getFileSize()>1000000) 68 aes.add("uploadFile",new ActionError("upload_file_size_exceed")); 69 String fn = uploadFile.getFileName().toLowerCase(); 70 int i=0; 71 for(;i<types.size();i++){ 72 if(fn.endsWith((String )types.get(i))) 73 break; 74 } 75 if(i==types.size()) 76 aes.add("uploadFile",new ActionError("upload_file_extend_noallow")); 77 if(uploadFile.getFileSize()<=0) 78 aes.add("uploadFile",new ActionError("upload_file_illegal")); 79 } 80 return aes; 81 } 82 public final static List types = Arrays.asList(new String []{"gif","jpg","bmp","png"}); 83 public static List getTypes() { 84 return types; 85 } 86 public String getDisplayText() { 87 return displayText; 88 } 89 public void setDisplayText(String displayText) { 90 this.displayText = displayText; 91 } 92 public String getImageUrl() { 93 return imageUrl; 94 } 95 public void setImageUrl(String imageUrl) { 96 this.imageUrl = imageUrl; 97 } 98 public String getTxtAlign() { 99 return txtAlign; 100 } 101 public void setTxtAlign(String txtAlign) { 102 this.txtAlign = txtAlign; 103 } 104 public String getTxtBorder() { 105 return txtBorder; 106 } 107 public void setTxtBorder(String txtBorder) { 108 this.txtBorder = txtBorder; 109 } 110 public String getTxtHeight() { 111 return txtHeight; 112 } 113 public void setTxtHeight(String txtHeight) { 114 this.txtHeight = txtHeight; 115 } 116 public String getTxtWidth() { 117 return txtWidth; 118 } 119 public void setTxtWidth(String txtWidth) { 120 this.txtWidth = txtWidth; 121 } 122 public FormFile getUploadFile() { 123 return uploadFile; 124 } 125 public void setUploadFile(FormFile uploadFile) { 126 this.uploadFile = uploadFile; 127 } 128 } 129 | Popular Tags |