1 32 33 package scioworks.imap.presentation.imapWeb; 34 35 import java.util.Vector ; 36 37 import scioworks.imap.spec.beans.*; 38 39 40 public class FileUploadSessionData implements java.io.Serializable { 41 42 public static String SESSION_KEY = "FileUploadSessionData"; 43 44 private Vector fFileList; 45 private int fFileMaxCount; 46 private int fTotalSize; 47 48 public FileUploadSessionData(int fileMaxCount, int totalSize) { 49 fFileMaxCount = fileMaxCount; 50 fTotalSize = totalSize; 51 fFileList = new Vector (fFileMaxCount); 52 53 } 54 55 private int getCurrentSize() { 56 int size = 0; 57 for (int i=0; i<fFileList.size(); i++) { 58 size = size + ((FileRecord)fFileList.elementAt(i)).getSize(); 59 } 60 return size; 61 } 62 63 public boolean isExceedFileCount() { 64 if ((fFileList.size()+1) > fFileMaxCount) { 65 return true; 66 } else { 67 return false; 68 } 69 } 70 71 private boolean isExceedLimit(int size) { 72 if ( ((fFileList.size()+1) > fFileMaxCount) || 73 ((getCurrentSize()+size) > fTotalSize) ) { 74 return true; 75 } else { 76 return false; 77 } 78 } 79 80 public Vector getFileList() { 81 return new Vector (fFileList); 82 } 83 84 public boolean addFile(String tmpFilename, String filename, int size, 85 String contentType) { 86 if (!isExceedLimit(size)) { 87 88 fFileList.addElement(FileRecordFactory.getFileRecord("scioworks.imap.business.beans.FileRecordImpl",tmpFilename,filename,size,contentType)); 89 90 return true; 92 } else { 93 return false; 95 } 96 } 97 98 public boolean removeFile(int index) { 99 if (index >= fFileList.size()) { 100 return false; 101 } else { 102 fFileList.remove(index); 103 return true; 104 } 105 } 106 107 public int getFileCount() { 108 return fFileList.size(); 109 } 110 111 public String getTmpFilename(int index) { 112 return ((FileRecord)fFileList.elementAt(index)).getTmpFilename(); 113 } 114 115 public String getFilename(int index) { 116 return ((FileRecord)fFileList.elementAt(index)).getFilename(); 117 } 118 119 public int getFilesize(int index) { 120 return ((FileRecord)fFileList.elementAt(index)).getSize(); 121 } 122 123 public String toString() { 124 StringBuffer buf = new StringBuffer (); 125 FileRecord fr = null; 126 for (int i=0; i<fFileList.size(); i++) { 127 fr = (FileRecord)fFileList.elementAt(i); 128 buf.append( fr.toString() ); 129 } 130 return buf.toString(); 131 } 132 } | Popular Tags |