| 1 25 29 package org.jresearch.gossip.forms; 30 31 import java.util.ArrayList ; 32 import java.util.List ; 33 34 import javax.servlet.http.HttpServletRequest ; 35 36 import org.apache.struts.action.ActionError; 37 import org.apache.struts.action.ActionErrors; 38 import org.apache.struts.action.ActionMapping; 39 import org.apache.struts.upload.FormFile; 40 import org.apache.struts.upload.MultipartRequestHandler; 41 import org.jresearch.gossip.IConst; 42 import org.jresearch.gossip.configuration.Configurator; 43 import org.jresearch.gossip.exception.ConfiguratorException; 44 45 49 public class FileUploadForm extends MessageForm { 50 51 private FormFile[] file; 52 53 private String [] fdesc; 54 55 private int maxFileCount; 56 57 60 public FileUploadForm() { 61 Configurator config = Configurator.getInstance(); 62 try { 63 this.maxFileCount = config 64 .getInt(IConst.CONFIG.MAX_ATTACHMENT_COUNT); 65 } catch (ConfiguratorException e) { 66 e.printStackTrace(); 67 maxFileCount = 1; 68 } 69 this.file = new FormFile[maxFileCount]; 70 this.fdesc = new String [maxFileCount]; 71 } 72 73 76 public List [] getFileData() { 77 List result[] = { new ArrayList (), new ArrayList () }; 78 for (int i = 0; i < this.file.length; i++) { 79 if (this.file[i] != null && this.file[i].getFileSize() > 0) { 80 result[0].add(this.file[i]); 81 result[1].add(this.fdesc[i]); 82 } 83 } 84 return result; 85 } 86 87 90 public String getDesc(int key) { 91 return this.fdesc[key]; 92 } 93 94 98 public void setDesc(int key, String desc) { 99 this.fdesc[key] = desc; 100 } 101 102 106 public void setFile(int key, FormFile file) { 107 this.file[key] = file; 108 } 109 110 113 public FormFile getFile(int key) { 114 return this.file[key]; 115 } 116 117 122 public ActionErrors validate(ActionMapping mapping, 123 HttpServletRequest request) { 124 ActionErrors errors = super.validate(mapping, request); 125 Boolean maxLengthExceeded = (Boolean ) request 127 .getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED); 128 if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) { 129 errors = new ActionErrors(); 130 errors.add("maxLengthExceeded", new ActionError( 131 "error.maxLengthExceeded", "maxLengthExceeded")); 132 } 133 return errors; 134 135 } 136 137 } | Popular Tags |