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: /JADE/SourceCode/com/salmonllc/jsp/JspRaw.java $
024: //$Author: Dan $
025: //$Revision: 8 $
026: //$Modtime: 10/30/02 2:38p $
027: /////////////////////////
028:
029: import com.salmonllc.sql.DataStoreBuffer;
030: import com.salmonllc.sql.DataStoreEvaluator;
031: import com.salmonllc.sql.DataStoreExpression;
032:
033: import java.io.BufferedReader;
034: import java.io.InputStream;
035: import java.io.InputStreamReader;
036:
037: /**
038: * This type can be used to add raw html to your page.
039: */
040: public class JspRaw extends JspContainer {
041: private String _html;
042: private DataStoreEvaluator _dsEval = null;
043: private InputStream _in = null;
044: private String _fileName;
045:
046: /**
047: * Constructs a raw html object for the page
048: * @param html - HTML to place in the page.
049: * @param p - page to place the HTML in.
050: */
051: public JspRaw(String html, com.salmonllc.html.HtmlPage p) {
052: super ("", p);
053: _html = html;
054: }
055:
056: /**
057: * Constructs a raw html object for the page
058: * @param name - The name of the component in the page
059: * @param html - HTML to place in the page.
060: * @param p - page to place the HTML in.
061: */
062:
063: public JspRaw(String name, String html,
064: com.salmonllc.html.HtmlPage p) {
065: super (name, p);
066: _html = html;
067: }
068:
069: public void generateHTML(java.io.PrintWriter p, int rowNo)
070: throws java.io.IOException {
071: try {
072: if (_dsEval != null) {
073: Object res;
074:
075: if (rowNo > -1)
076: res = _dsEval.evaluateRow(rowNo);
077: else
078: res = _dsEval.evaluateRow();
079:
080: if (res == null)
081: _html = null;
082: else
083: _html = res.toString();
084: }
085: } catch (Exception e) {
086: }
087: if (!getVisible())
088: return;
089:
090: if (_in != null) {
091: BufferedReader buf = new BufferedReader(
092: new InputStreamReader(_in, "ISO8859_1"));
093: char[] c = new char[1024];
094: int bytesRead = 0;
095: while (true) {
096: bytesRead = buf.read(c, 0, 1024);
097: if (bytesRead <= 0)
098: break;
099: p.write(c, 0, bytesRead);
100: }
101: buf.close();
102: return;
103: }
104:
105: if (_html == null)
106: return;
107:
108: p.print(_html);
109: }
110:
111: /**
112: * Use this method get the name file on the server file system to be streamed back to the browser.
113: */
114: public String getFileName() {
115: return _fileName;
116:
117: }
118:
119: /**
120: * This method returns the html in the component.
121: */
122: public String getHtml() {
123: return _html;
124: }
125:
126: /**
127: * This method sets the input stream that the component will draw it's html from.
128: */
129: public InputStream getInputStream() {
130: return _in;
131: }
132:
133: /**
134: * Use this method to bind this component to an expression in a DataStore
135: * @param ds The DataStore to bind to.
136: * @param expression The expression to bind to.
137: * @see DataStoreEvaluator
138: */
139: public void setExpression(DataStoreBuffer ds,
140: DataStoreExpression expression) throws Exception {
141: _dsEval = new DataStoreEvaluator(ds, expression);
142: }
143:
144: /**
145: * Use this method to bind this component to an expression in a DataStore
146: * @param ds The DataStore to bind to.
147: * @param expression The expression to bind to.
148: * @see DataStoreEvaluator
149: */
150: public void setExpression(DataStoreBuffer ds, String expression)
151: throws Exception {
152: _dsEval = new DataStoreEvaluator(ds, expression);
153: }
154:
155: /**
156: * Use this method to specify the name file on the server file system to be streamed back to the browser.
157: */
158: public void setFileName(String fileName) {
159: try {
160: setInputStream(new java.io.FileInputStream(fileName));
161: _fileName = fileName;
162: } catch (Exception e) {
163: }
164:
165: }
166:
167: /**
168: * This method sets the html that the componnt will generate.
169: */
170: public void setHtml(String html) {
171: _html = html;
172: }
173:
174: /**
175: * This method sets the input stream that the component will draw it's html from.
176: */
177: public void setInputStream(InputStream in) {
178: _in = in;
179: }
180:
181: /**
182: * This method gets the DataStoreEvaluator being used for expressions.
183: * @return DataStoreEvaluator
184: * @see DataStoreEvaluator
185: */
186: public DataStoreEvaluator getExpression() {
187: return _dsEval;
188: }
189: }
|