001: /* -----------------------------------------------------------------------------
002: * Copyright (c) 2001, Low Kin Onn
003: * All rights reserved.
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: *
008: * Redistributions of source code must retain the above copyright notice, this
009: * list of conditions and the following disclaimer.
010: *
011: * Redistributions in binary form must reproduce the above copyright notice,
012: * this list of conditions and the following disclaimer in the documentation
013: * and/or other materials provided with the distribution.
014: *
015: * Neither name of the Scioworks Pte. Ltd. nor the names of its contributors
016: * may beused to endorse or promote products derived from this software without
017: * specific prior written permission.
018: *
019: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
020: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
021: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
022: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
023: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
024: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
025: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
026: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
027: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
028: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: *
030: * -----------------------------------------------------------------------------
031: */
032:
033: package scioworks.imap.presentation.imapWeb;
034:
035: import java.util.Vector;
036:
037: import scioworks.imap.spec.beans.*;
038:
039: public class FileUploadSessionData implements java.io.Serializable {
040:
041: public static String SESSION_KEY = "FileUploadSessionData";
042:
043: private Vector fFileList;
044: private int fFileMaxCount;
045: private int fTotalSize;
046:
047: public FileUploadSessionData(int fileMaxCount, int totalSize) {
048: fFileMaxCount = fileMaxCount;
049: fTotalSize = totalSize;
050: fFileList = new Vector(fFileMaxCount);
051:
052: }
053:
054: private int getCurrentSize() {
055: int size = 0;
056: for (int i = 0; i < fFileList.size(); i++) {
057: size = size
058: + ((FileRecord) fFileList.elementAt(i)).getSize();
059: }
060: return size;
061: }
062:
063: public boolean isExceedFileCount() {
064: if ((fFileList.size() + 1) > fFileMaxCount) {
065: return true;
066: } else {
067: return false;
068: }
069: }
070:
071: private boolean isExceedLimit(int size) {
072: if (((fFileList.size() + 1) > fFileMaxCount)
073: || ((getCurrentSize() + size) > fTotalSize)) {
074: return true;
075: } else {
076: return false;
077: }
078: }
079:
080: public Vector getFileList() {
081: return new Vector(fFileList);
082: }
083:
084: public boolean addFile(String tmpFilename, String filename,
085: int size, String contentType) {
086: if (!isExceedLimit(size)) {
087:
088: fFileList.addElement(FileRecordFactory.getFileRecord(
089: "scioworks.imap.business.beans.FileRecordImpl",
090: tmpFilename, filename, size, contentType));
091:
092: // ok to add
093: return true;
094: } else {
095: // can't add anymore
096: return false;
097: }
098: }
099:
100: public boolean removeFile(int index) {
101: if (index >= fFileList.size()) {
102: return false;
103: } else {
104: fFileList.remove(index);
105: return true;
106: }
107: }
108:
109: public int getFileCount() {
110: return fFileList.size();
111: }
112:
113: public String getTmpFilename(int index) {
114: return ((FileRecord) fFileList.elementAt(index))
115: .getTmpFilename();
116: }
117:
118: public String getFilename(int index) {
119: return ((FileRecord) fFileList.elementAt(index)).getFilename();
120: }
121:
122: public int getFilesize(int index) {
123: return ((FileRecord) fFileList.elementAt(index)).getSize();
124: }
125:
126: public String toString() {
127: StringBuffer buf = new StringBuffer();
128: FileRecord fr = null;
129: for (int i = 0; i < fFileList.size(); i++) {
130: fr = (FileRecord) fFileList.elementAt(i);
131: buf.append(fr.toString());
132: }
133: return buf.toString();
134: }
135: }
|