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/WmlLink.java $
025: //$Author: Dan $
026: //$Revision: 8 $
027: //$Modtime: 6/11/03 4:52p $
028: /////////////////////////
029:
030: import com.salmonllc.jsp.*;
031: import com.salmonllc.properties.Props;
032: import com.salmonllc.sql.*;
033: import com.salmonllc.util.MessageLog;
034: import com.salmonllc.util.Util;
035:
036: /**
037: * This container will construct an anchor tag with a Wml link (HREF) reference.
038: */
039: public class WmlLink extends JspContainer {
040: private String _href;
041: private DataStoreEvaluator _dsEval;
042: private String _class;
043: private boolean _generateLink = true;
044: private boolean _genBracket = false;
045: private String _bracketFont;
046: private String _title;
047:
048: /**
049: * WmlLink constructor comment.
050: * @param name The name of the link
051: * @param href The url for the link
052: * @param p The page the link will go in.
053: */
054:
055: public WmlLink(String name, String href,
056: com.salmonllc.html.HtmlPage p) {
057: super (name, p);
058: _href = href;
059: }
060:
061: /**
062: *Does the binding for the component. This method is called by the framework and should not be called directly
063: */
064:
065: public void doBinding() throws Exception {
066: String dataSource = getDataSource();
067: String dsName = null;
068: String dsExp = null;
069:
070: if (dataSource == null)
071: return;
072:
073: int pos = dataSource.indexOf(":");
074: if (pos == -1)
075: dsName = dataSource;
076: else {
077: dsName = dataSource.substring(0, pos);
078: dsExp = dataSource.substring(pos + 1);
079: }
080:
081: DataStoreBuffer ds = ((JspController) getPage())
082: .getDataSource(dsName);
083: if (ds == null)
084: return;
085:
086: if (!ds.getAutoBind())
087: return;
088:
089: setHrefExpression(ds, ((JspController) getPage())
090: .convertExpressionOperators(dsExp));
091: }
092:
093: /**
094: *Generates the Html for the component. This method is called by the framework and should not be called directly
095: */
096: public void generateHTML(TagWriter t, String box, int rowNo)
097: throws java.io.IOException {
098: StringBuffer sb = new StringBuffer();
099:
100: if (!_visible)
101: return;
102: StringBuffer href = null;
103: try {
104: if (_dsEval != null) {
105: if (rowNo > -1) {
106: _href = _dsEval.evaluateRowFormat(rowNo);
107: } else {
108: _href = _dsEval.evaluateRowFormat();
109: }
110: }
111: } catch (Exception e) {
112: }
113: // sr 12-08-2000 was getting a null pointer exception
114: if (!Util.isNull(_href)) {
115: href = new StringBuffer(_href);
116: int hrefLength = href.length();
117: for (int i = 0; i < hrefLength; i++) {
118: if (href.charAt(i) == ' ') {
119: href.setCharAt(i, '+');
120: }
121: }
122: }
123: String row = "";
124: String bracketStartFont = "";
125: String bracketEndFont = "";
126: if (rowNo != -1)
127: row = "_" + row + new Integer(rowNo).toString();
128: if (_genBracket) {
129: com.salmonllc.properties.Props props = getPage()
130: .getPageProperties();
131: if (_bracketFont != null) {
132: bracketStartFont = props.getProperty(_bracketFont
133: + Props.TAG_START);
134: bracketEndFont = props.getProperty(_bracketFont
135: + Props.TAG_END);
136: } else {
137: bracketStartFont = props
138: .getProperty(com.salmonllc.html.HtmlText.FONT_DEFAULT
139: + Props.TAG_START);
140: bracketEndFont = props
141: .getProperty(com.salmonllc.html.HtmlText.FONT_DEFAULT
142: + Props.TAG_END);
143: }
144:
145: sb.append(bracketStartFont + " [" + bracketEndFont);
146: }
147: sb.append("<a");
148: sb.append(" id=\"" + getName() + row + "\"");
149: sb.append(" href=\"" + encodeURL(href) + "\"");
150: if (_title != null)
151: sb.append(" title=\"" + _title + "\"");
152: if (_class != null)
153: sb.append(" class=\"" + _class + "\"");
154: sb.append(">");
155:
156: if (_generateLink)
157: t.print(sb.toString(), TagWriter.TYPE_BEGIN_TAG);
158: t.print(box, TagWriter.TYPE_CONTENT);
159: if (_generateLink) {
160: t.print("</a>", TagWriter.TYPE_END_TAG);
161: if (_genBracket)
162: t.print(bracketStartFont + "]" + bracketEndFont);
163: }
164:
165: }
166:
167: /**
168: * This method gets whether or not the anchor tag will be generated for the link. Pass true to have the a tag generated and false not to. Setting the value to false, will cause the items inside the container to be displayed but nothing will happen when the user clicks on them.
169: */
170: public boolean getGenerateLink() {
171: return _generateLink;
172: }
173:
174: /**
175: * Returns the href for the link
176: */
177: public String getHref() {
178: return _href;
179: }
180:
181: /**
182: * This method gets the DataStoreEvaluator being used for href expressions.
183: * @return DataStoreEvaluator
184: * @see DataStoreEvaluator
185: */
186: public DataStoreEvaluator getHrefExpression() {
187: return _dsEval;
188: }
189:
190: /**
191: * Use this method to get the style that will be used to display the link
192: */
193: public String getClassName() {
194: return _class;
195: }
196:
197: /**
198: * Use this method to get the title for the link
199: */
200: public String getTitle() {
201: return _title;
202: }
203:
204: /**
205: * This method sets whether or not the anchor tag will be generated with brackets([]) around the Tag. Pass true to have the tag generated with and false not to.
206: */
207: public void setBracket(boolean bracket) {
208: _genBracket = bracket;
209: }
210:
211: /**
212: * This method sets the font for the brackets around the link.
213: */
214: public void setBracketFont(String font) {
215: _bracketFont = font;
216: }
217:
218: /**
219: * This method sets whether or not the anchor tag will be generated for the link. Pass true to have the a tag generated and false not to. Setting the value to false, will cause the items inside the container to be displayed but nothing will happen when the user clicks on them.
220: */
221: public void setGenerateLink(boolean gen) {
222: _generateLink = gen;
223: }
224:
225: /**
226: * Sets the href for the link
227: * @param href java.lang.String
228: */
229: public void setHref(String href) {
230: _href = href;
231: }
232:
233: /**
234: * This method sets a datastore expression that will be used to compute the href for the link.
235: * @param ds com.salmonllc.sql.DataStoreBuffer
236: * @param expression The expression to evaluate
237: */
238: public void setHrefExpression(DataStoreBuffer ds,
239: DataStoreExpression expression) throws Exception {
240: try {
241: _dsEval = new DataStoreEvaluator(ds, expression);
242: } catch (Exception e) {
243: MessageLog
244: .writeErrorMessage(
245: "setHrefExpression(DataStoreBuffer ds, DataStoreExpression expression )",
246: e, this );
247: throw e;
248: }
249: }
250:
251: /**
252: * This method sets a datastore expression that will be used to compute the href for the link.
253: * @param ds com.salmonllc.sql.DataStoreBuffer
254: * @param expression java.lang.String
255: */
256: public void setHrefExpression(DataStoreBuffer ds, String expression)
257: throws Exception {
258: try {
259: _dsEval = new DataStoreEvaluator(ds, expression);
260: } catch (Exception e) {
261: MessageLog
262: .writeErrorMessage(
263: "setHrefExpression(DataStoreBuffer ds, String expression )",
264: e, this );
265: throw e;
266: }
267: }
268:
269: /**
270: * This method sets the class for the link.
271: */
272: public void setClassName(String className) {
273: _class = className;
274: }
275:
276: /**
277: * This method sets the title for the link.
278: */
279: public void setTitle(String title) {
280: _title = title;
281: }
282: }
|