001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.jsp;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/JspParameter.java $
024: //$Author: Srufle $
025: //$Revision: 12 $
026: //$Modtime: 7/15/04 3:35p $
027: /////////////////////////
028:
029: import com.salmonllc.html.*;
030: import com.salmonllc.util.Util;
031:
032: import java.util.*;
033:
034: /**
035: * This class is used in concert with the Parameter tag. It does not have any html representation
036: */
037:
038: public class JspParameter extends HtmlComponent {
039: private String _fValue;
040:
041: public JspParameter(String name, HtmlPage p) {
042: super (name, p);
043: _visible = true;
044: }
045:
046: /**
047: * This method was generates the html sent back to the browser.
048: */
049: public void generateHTML(java.io.PrintWriter p, int rowNo)
050: throws java.lang.Exception {
051: }
052:
053: /**
054: * This method gets the value of the parameter.
055: * @return java.lang.String
056: */
057: public java.lang.String getValue() {
058: return _fValue;
059: }
060:
061: /**
062: * This method gets the value of the parameter as a boolean. If the parm is T,true,Y or Yes it will return true. If the parm is F, False, N, or No it will return false. Otherwise it will return the default value passed.
063: */
064: public boolean getValueAsBoolean(boolean def) {
065: if (_fValue == null)
066: return def;
067: String val = _fValue.toUpperCase();
068:
069: if (val.equals("N") || val.equals("NO") || val.equals("F")
070: || val.equals("FALSE"))
071: return false;
072:
073: if (val.equals("Y") || val.equals("YES") || val.equals("T")
074: || val.equals("TRUE"))
075: return true;
076:
077: return def;
078: }
079:
080: /**
081: * This method gets the value of the parameter as an int value. If the parm is null it returns -1.
082: */
083: public int getValueAsInt() {
084: int ret = Util.stringToInt(_fValue);
085: return ret;
086: }
087:
088: /**
089: * This method gets the value of the parameter as a string array. The parameter should be entered as a comma seperated list.
090: */
091: public String[] getValueAsStringArray() {
092:
093: if (_fValue == null)
094: return new String[0];
095:
096: Vector v = new Vector();
097: StringTokenizer t = new StringTokenizer(_fValue, ",");
098: while (t.hasMoreTokens())
099: v.addElement(t.nextToken().trim());
100:
101: String ret[] = new String[v.size()];
102: v.copyInto(ret);
103: return ret;
104: }
105:
106: /**
107: * This method sets the value of the parameter.
108: * @param newValue java.lang.String
109: */
110: public void setValue(java.lang.String newValue) {
111: _fValue = newValue;
112: }
113: }
|