001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.common.utils.web;
009:
010: //base classes
011: import java.io.UnsupportedEncodingException;
012:
013: //project specific classes
014: import org.jfolder.common.UnexpectedSystemException;
015:
016: //other classes
017:
018: public class ParameterHolder {
019:
020: //
021: private String name = null;
022: private String fileName = null;
023: private String parameterString = null;
024: private byte parameterBuffer[] = null;
025:
026: //private boolean valueIsString = true;
027:
028: protected ParameterHolder() {
029: }
030:
031: public String getName() {
032: return this .name;
033: }
034:
035: protected void setName(String inName) {
036: this .name = inName;
037: }
038:
039: public String getFileName() {
040: return this .fileName;
041: }
042:
043: protected void setFileName(String inFileName) {
044: this .fileName = inFileName;
045: }
046:
047: public String getLocalFileName() {
048: String outValue = null;
049:
050: if (this .fileName != null) {
051: String fullFileName = this .fileName;
052: int forwardIndex = fullFileName.lastIndexOf('/');
053: int backIndex = fullFileName.lastIndexOf('\\');
054:
055: int lastIndex = 0;
056: if (forwardIndex > backIndex) {
057: lastIndex = forwardIndex;
058: } else {
059: lastIndex = backIndex;
060: }
061:
062: String fileName = fullFileName;
063: if (lastIndex > -1) {
064: fileName = fullFileName.substring(lastIndex + 1);
065: }
066:
067: outValue = fileName;
068: }
069:
070: return outValue;
071: }
072:
073: public String getValueAsString() {
074: //TO DO: internationalize this and other parameter meta data and content
075: try {
076: String outValue = null;
077:
078: if (this .parameterBuffer != null) {
079: outValue = new String(this .parameterBuffer,
080: "ISO-8859-1");
081: } else {
082: outValue = this .parameterString;
083: }
084:
085: return outValue;
086: } catch (UnsupportedEncodingException uee) {
087: throw new UnexpectedSystemException(uee);
088: }
089: }
090:
091: public byte[] getValueAsBytes() {
092: //TO DO: should this be cloned to avoid change by reference
093: return this .parameterBuffer;
094: }
095:
096: //TO DO: add getting/setting multiple string values
097: protected void setValue(String inValue) {
098: this .parameterString = inValue;
099: //this.valueIsString = true;
100: }
101:
102: protected void setValue(byte inBuffer[]) {
103: this .parameterBuffer = inBuffer;
104: //this.valueIsString = false;
105: }
106:
107: public boolean isValueString() {
108: return !(this .fileName != null);
109: }
110:
111: public boolean isValueUpload() {
112: return !isValueString();
113: }
114: }
|