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:
021: package com.salmonllc.wml;
022:
023: /////////////////////////
024: //$Archive: /SOFIA/SourceCode/com/salmonllc/wml/WmlOption.java $
025: //$Author: Dan $
026: //$Revision: 6 $
027: //$Modtime: 6/11/03 4:52p $
028: /////////////////////////
029:
030: import java.io.PrintWriter;
031:
032: import com.salmonllc.jsp.JspContainer;
033: import com.salmonllc.jsp.JspController;
034: import com.salmonllc.sql.*;
035: import com.salmonllc.util.MessageLog;
036: import com.salmonllc.util.Util;
037:
038: /**
039: * This container will construct an option in a wml select.
040: */
041: public class WmlOption extends JspContainer {
042: private String _href;
043: private DataStoreEvaluator _dsEval;
044: private String _class;
045: private String _value;
046: private String _title;
047: private String _box;
048:
049: /**
050: * WmlLink constructor comment.
051: * @param name The name of the option
052: * @param href The url for the option to go to
053: * @param p The page the option will go in.
054: */
055:
056: public WmlOption(String name, String value, String title,
057: String href, com.salmonllc.html.HtmlPage p) {
058: super (name, p);
059: _href = href;
060: _value = value;
061: _title = title;
062: }
063:
064: /**
065: *Does the binding for the component. This method is called by the framework and should not be called directly
066: */
067: public void doBinding() throws Exception {
068: String dataSource = getDataSource();
069: String dsName = null;
070: String dsExp = null;
071:
072: if (dataSource == null)
073: return;
074:
075: int pos = dataSource.indexOf(":");
076: if (pos == -1)
077: dsName = dataSource;
078: else {
079: dsName = dataSource.substring(0, pos);
080: dsExp = dataSource.substring(pos + 1);
081: }
082:
083: DataStoreBuffer ds = ((JspController) getPage())
084: .getDataSource(dsName);
085: if (ds == null)
086: return;
087:
088: if (!ds.getAutoBind())
089: return;
090:
091: setHrefExpression(ds, ((JspController) getPage())
092: .convertExpressionOperators(dsExp));
093: }
094:
095: /**
096: *Generates the Html for the component. This method is called by the framework and should not be called directly
097: */
098: public void generateHTML(PrintWriter t, int rowNo)
099: throws java.io.IOException {
100: StringBuffer sb = new StringBuffer();
101:
102: if (!_visible)
103: return;
104: StringBuffer href = null;
105: try {
106: if (_dsEval != null) {
107: if (rowNo > -1) {
108: _href = _dsEval.evaluateRowFormat(rowNo);
109: } else {
110: _href = _dsEval.evaluateRowFormat();
111: }
112: }
113: } catch (Exception e) {
114: }
115: // sr 12-08-2000 was getting a null pointer exception
116: if (!Util.isNull(_href)) {
117: href = new StringBuffer(_href);
118: int hrefLength = href.length();
119: for (int i = 0; i < hrefLength; i++) {
120: if (href.charAt(i) == ' ') {
121: href.setCharAt(i, '+');
122: }
123: }
124: }
125: String row = "";
126: if (rowNo != -1)
127: row = "_" + rowNo;
128: sb.append("<option");
129: sb.append(" id=\"" + getName() + row + "\"");
130: if (_value != null)
131: sb.append(" value=\"" + _value + "\"");
132: if (_title != null)
133: sb.append(" title=\"" + _title + "\"");
134: if (_class != null)
135: sb.append(" class=\"" + _class + "\"");
136: if (_href != null)
137: sb.append(" onpick=\"" + encodeURL(_href) + "\"");
138: sb.append(">");
139: t.print(sb.toString());
140: t.print(_box);
141: t.print("</option>");
142:
143: }
144:
145: /**
146: *Sets the body content of the Option. This method is called by the framework and should not be called directly
147: */
148: public void setBodyContent(String box) {
149: _box = box;
150: }
151:
152: /**
153: *Gets the body content of the Option. This method is called by the framework and should not be called directly
154: */
155: public String getBodyContent() {
156: return _box;
157: }
158:
159: /**
160: * Returns the href for the option
161: */
162: public String getHref() {
163: return _href;
164: }
165:
166: /**
167: * This method gets the DataStoreEvaluator being used for href expressions.
168: * @return DataStoreEvaluator
169: * @see DataStoreEvaluator
170: */
171: public DataStoreEvaluator getHrefExpression() {
172: return _dsEval;
173: }
174:
175: /**
176: * Use this method to get the class attribute of the option
177: */
178: public String getClassName() {
179: return _class;
180: }
181:
182: /**
183: * Use this method to get the value of the option
184: */
185: public String getValue() {
186: return _value;
187: }
188:
189: /**
190: * This method sets the title.
191: */
192: public void setTitle(String title) {
193: _title = title;
194: }
195:
196: /**
197: * This method sets the value.
198: */
199: public void setValue(String value) {
200: _value = value;
201: }
202:
203: /**
204: * Sets the href for the option
205: * @param href java.lang.String
206: */
207: public void setHref(String href) {
208: _href = href;
209: }
210:
211: /**
212: * This method sets a datastore expression that will be used to compute the href for the link.
213: * @param ds com.salmonllc.sql.DataStoreBuffer
214: * @param expression The expression to evaluate
215: */
216: public void setHrefExpression(DataStoreBuffer ds,
217: DataStoreExpression expression) throws Exception {
218: try {
219: _dsEval = new DataStoreEvaluator(ds, expression);
220: } catch (Exception e) {
221: MessageLog
222: .writeErrorMessage(
223: "setHrefExpression(DataStoreBuffer ds, DataStoreExpression expression )",
224: e, this );
225: throw e;
226: }
227: }
228:
229: /**
230: * This method sets a datastore expression that will be used to compute the href for the link.
231: * @param ds com.salmonllc.sql.DataStoreBuffer
232: * @param expression java.lang.String
233: */
234: public void setHrefExpression(DataStoreBuffer ds, String expression)
235: throws Exception {
236: try {
237: _dsEval = new DataStoreEvaluator(ds, expression);
238: } catch (Exception e) {
239: MessageLog
240: .writeErrorMessage(
241: "setHrefExpression(DataStoreBuffer ds, String expression )",
242: e, this );
243: throw e;
244: }
245: }
246:
247: /**
248: * This method sets the class for the option.
249: */
250: public void setClassName(String className) {
251: _class = className;
252: }
253:
254: }
|