1 package org.nextime.ion.backoffice.form; 2 3 import javax.servlet.http.HttpServletRequest ; 4 5 import org.apache.struts.action.ActionError; 6 import org.apache.struts.action.ActionErrors; 7 import org.apache.struts.action.ActionForm; 8 import org.apache.struts.action.ActionMapping; 9 import org.apache.struts.upload.FormFile; 10 import org.nextime.ion.backoffice.bean.Resources; 11 12 public class UploadResourceForm extends ActionForm { 13 14 private String name; 15 private FormFile file; 16 17 20 public ActionErrors validate( 21 ActionMapping arg0, 22 HttpServletRequest request) { 23 24 try { 26 request.setAttribute("resources",Resources.getResourceXmlBeans(servlet)); 27 } 28 catch( Exception e ) { 29 e.printStackTrace(); 30 } 31 32 ActionErrors errors = new ActionErrors(); 33 if (getName() == null) { 34 ActionError error = 35 new ActionError("error.uploadResource.missingName"); 36 errors.add("name", error); 37 } else { 38 if (getName().trim().equals("")) { 39 ActionError error2 = 40 new ActionError("error.uploadResource.missingName"); 41 errors.add("name", error2); 42 } else { 43 if (getName().indexOf(".") != -1 44 || getName().indexOf("/") != -1 45 || getName().indexOf("\\") != -1 46 || getName().indexOf("%") != -1 47 || getName().indexOf("&") != -1) { 48 ActionError error3 = 49 new ActionError("error.uploadResource.badName"); 50 errors.add("name", error3); 51 52 } 53 } 54 } 55 if (getFile().getFileSize() == 0) { 56 ActionError error = 57 new ActionError("error.uploadResource.missingFile"); 58 errors.add("file", error); 59 } 60 return errors; 61 } 62 63 66 public void reset(ActionMapping arg0, HttpServletRequest arg1) { 67 setName(null); 68 setFile(null); 69 } 70 71 75 public FormFile getFile() { 76 return file; 77 } 78 79 83 public String getName() { 84 return name; 85 } 86 87 91 public void setFile(FormFile file) { 92 this.file = file; 93 } 94 95 99 public void setName(String name) { 100 this.name = name; 101 } 102 103 } 104 | Popular Tags |