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.wml;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/wml/WmlPasswordEdit.java $
024: //$Author: Srufle $
025: //$Revision: 7 $
026: //$Modtime: 4/15/03 1:56a $
027: /////////////////////////
028:
029: import java.util.Hashtable;
030:
031: import com.salmonllc.html.events.ValueChangedEvent;
032:
033: /**
034: * This class is used for password style text input in a page.
035: */
036: public class WmlPasswordEdit extends WmlFormComponent {
037: private int _maxLength = 0;
038: private int _size = 10;
039: private String _format;
040: private boolean _emptyok = false;
041: private int _tabindex = -1;
042: private String _title;
043:
044: /**
045: * Constructs a new WMLPasswordEdit component.
046: * @param name The name of the component
047: * @param p The page the component will be placed in.
048: */
049: public WmlPasswordEdit(String name, com.salmonllc.html.HtmlPage p) {
050: super (name, p);
051: }
052:
053: /**
054: *Generates the Html for the component. This method is called by the framework and should not be called directly
055: */
056: public void generateHTML(java.io.PrintWriter p, int rowNo)
057: throws Exception {
058: if (!_visible)
059: return;
060:
061: if (!getEnabled()) {
062: String value = getValue(rowNo, true);
063: String out = "";
064: if (value == null)
065: value = "";
066: int n = value.length();
067: while (n-- > 0)
068: out += "*";
069: n = _size - value.length();
070: while (n-- > 0)
071: out += " ";
072: if ((value.length() == 0) && (_size <= 0))
073: out = " ";
074: p.print(out);
075: return;
076: }
077: String name = getName();
078: if (rowNo > -1)
079: name += "_" + rowNo;
080:
081: String tag = "<input type=\"password\" id=\"" + name
082: + "\" name=\"" + name + "\"";
083:
084: if (_maxLength > 0)
085: tag += " maxlength=\"" + _maxLength + "\"";
086:
087: if (_size > 0) {
088: int size = _size;
089: tag += " size=\"" + size + "\"";
090: }
091:
092: String value = getValue(rowNo, true);
093:
094: if (value != null)
095: tag += " value=\"" + value + "\"";
096:
097: if (_class != null)
098: tag += " class=\"" + _class + "\"";
099:
100: if (_format != null)
101: tag += " format=\"" + _format + "\"";
102:
103: if (_emptyok)
104: tag += " emptyok=\"True\"";
105:
106: if (_tabindex > -1)
107: tag += " tabindex=\"" + _tabindex + "\"";
108:
109: if (_title != null)
110: tag += " title=\"" + _title + "\"";
111:
112: tag += "/>";
113:
114: p.println(tag);
115: }
116:
117: /**
118: * This method gets the maximum length for the text in the component.
119: */
120: public int getMaxLength() {
121: return _maxLength;
122: }
123:
124: /**
125: * This method gets the display size for the component in characters.
126: */
127: public int getSize() {
128: return _size;
129: }
130:
131: /**
132: * This method gets the format mask for the input.
133: */
134: public String getFormat() {
135: return _format;
136: }
137:
138: /**
139: * This method gets the title for the input.
140: */
141: public String getTitle() {
142: return _title;
143: }
144:
145: /**
146: * This method gets the tabindex of the input.
147: */
148: public int getTabIndex() {
149: return _tabindex;
150: }
151:
152: /**
153: * This method gets the emptyok flag of the input.
154: */
155: public boolean getEmptyOk() {
156: return _emptyok;
157: }
158:
159: /**
160: *Processes the submitted parameters. This method is called by the framework and should not be called directly
161: */
162: public boolean processParms(Hashtable parms, int rowNo)
163: throws Exception {
164: if (!getEnabled())
165: return false;
166: Object oldValue = _value;
167:
168: String name = getName();
169: if (rowNo > -1) {
170: // name += "_" + rowNo;
171: if (_dsBuff != null)
172: oldValue = _dsBuff.getAny(rowNo, _dsColNo);
173: } else {
174: if (_dsBuff != null)
175: oldValue = _dsBuff.getAny(_dsColNo);
176: }
177:
178: String val[] = (String[]) parms.get(name);
179:
180: if (val != null) {
181: _value = val[0].trim();
182: if (_value.equals(""))
183: _value = null;
184: } else
185: _value = null;
186:
187: if (!valuesEqual(oldValue, _value)) {
188: String s = null;
189: if (oldValue != null)
190: s = oldValue.toString();
191: ValueChangedEvent e = new ValueChangedEvent(getPage(),
192: this , getName(), getName(), s, _value, rowNo,
193: _dsColNo, _dsBuff);
194: addEvent(e);
195: }
196:
197: return false;
198:
199: }
200:
201: /**
202: * This method sets the maximum length for the text in the component.
203: */
204: public void setMaxLength(int maxLength) {
205: _maxLength = maxLength;
206: }
207:
208: /**
209: * This method sets the display size for the component in characters.
210: */
211: public void setSize(int size) {
212: _size = size;
213: }
214:
215: /**
216: * This method sets the format mask for input.
217: */
218: public void setFormat(String format) {
219: _format = format;
220: }
221:
222: /**
223: * This method sets the emptyok flag for input.
224: */
225: public void setEmptyOk(boolean emptyok) {
226: _emptyok = emptyok;
227: }
228:
229: /**
230: * This method sets the tabindex for input.
231: */
232: public void setTabIndex(int tabindex) {
233: _tabindex = tabindex;
234: }
235:
236: /**
237: * This method sets the title for input.
238: */
239: public void setTitle(String title) {
240: _title = title;
241: }
242:
243: /**
244: * This method gets the postfield form of this component.
245: */
246: public String getPostForm() {
247: if (getVisible() && getEnabled())
248: return "<postfield name=\"" + getName() + "\" value=\"$("
249: + getName() + ")\"/>";
250: return "";
251: }
252:
253: }
|