KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > TemplateParamTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/TemplateParamTag.java,v 1.12 2004/08/18 12:26:09 hkollmann Exp $
3  * $Revision: 1.12 $
4  * $Date: 2004/08/18 12:26:09 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import java.io.*;
27
28 import java.util.*;
29
30 import javax.servlet.jsp.JspException JavaDoc;
31
32
33
34 /**
35  * Renders an dbforms style tag
36  *
37  * @author Joe Peer
38  */

39 public class TemplateParamTag extends TagSupportWithScriptHandler
40    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
41    private Hashtable sp;
42    private String JavaDoc baseDir;
43    private String JavaDoc defaultValue; // properties set by JSP container
44
private String JavaDoc dir; // properties set by JSP container
45
private String JavaDoc name; // properties set by JSP container
46

47    /**
48     * DOCUMENT ME!
49     *
50     * @param defaultValue DOCUMENT ME!
51     */

52    public void setDefaultValue(String JavaDoc defaultValue) {
53       this.defaultValue = defaultValue;
54    }
55
56
57    /**
58     * DOCUMENT ME!
59     *
60     * @return DOCUMENT ME!
61     */

62    public String JavaDoc getDefaultValue() {
63       return defaultValue;
64    }
65
66
67    /**
68     * DOCUMENT ME!
69     *
70     * @param dir DOCUMENT ME!
71     */

72    public void setDir(String JavaDoc dir) {
73       if (dir.equals(".")) {
74          this.dir = "";
75       } else {
76          this.dir = dir;
77       }
78    }
79
80
81    /**
82     * DOCUMENT ME!
83     *
84     * @return DOCUMENT ME!
85     */

86    public String JavaDoc getDir() {
87       return dir;
88    }
89
90
91    /**
92     * DOCUMENT ME!
93     *
94     * @param name DOCUMENT ME!
95     */

96    public void setName(String JavaDoc name) {
97       this.name = name;
98    }
99
100
101    /**
102     * DOCUMENT ME!
103     *
104     * @return DOCUMENT ME!
105     */

106    public String JavaDoc getName() {
107       return name;
108    }
109
110
111    /**
112     * DOCUMENT ME!
113     *
114     * @param pageContext DOCUMENT ME!
115     */

116    public void setPageContext(final javax.servlet.jsp.PageContext JavaDoc pageContext) {
117       super.setPageContext(pageContext);
118       this.sp = (java.util.Hashtable JavaDoc) pageContext.getRequest()
119                                                  .getAttribute("styleparams");
120       this.baseDir = (String JavaDoc) pageContext.getRequest()
121                                          .getAttribute("baseDir");
122    }
123
124
125    /**
126     * DOCUMENT ME!
127     *
128     * @param t DOCUMENT ME!
129     *
130     * @throws Throwable DOCUMENT ME!
131     */

132    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
133       throw t;
134    }
135
136
137    /**
138     * DOCUMENT ME!
139     *
140     * @return DOCUMENT ME!
141     *
142     * @throws JspException DOCUMENT ME!
143     */

144    public int doEndTag() throws JspException JavaDoc {
145       try {
146          StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
147
148          // determinate dir
149
if (dir != null) {
150             buf.append(baseDir);
151             buf.append(dir);
152
153             if (dir.length() > 0) {
154                buf.append("/");
155             }
156          }
157
158          // determinate param value
159
if (sp == null) {
160             if (defaultValue != null) {
161                buf.append(defaultValue);
162             }
163          } else {
164             String JavaDoc paramValue = (String JavaDoc) sp.get(name);
165
166             if (paramValue != null) {
167                buf.append(paramValue);
168             } else {
169                if (defaultValue != null) {
170                   buf.append(defaultValue);
171                }
172             }
173          }
174
175          pageContext.getOut()
176                     .flush();
177          pageContext.getOut()
178                     .write(buf.toString());
179       } catch (IOException ioe) {
180          throw new JspException JavaDoc("Problem including template end - "
181                                 + ioe.toString());
182       }
183
184       return EVAL_PAGE;
185    }
186
187
188    /**
189     * DOCUMENT ME!
190     */

191    public void doFinally() {
192       name = null;
193       defaultValue = null;
194       dir = null;
195       baseDir = null;
196       sp = null;
197    }
198
199
200    /**
201     * DOCUMENT ME!
202     *
203     * @return DOCUMENT ME!
204     *
205     * @throws JspException DOCUMENT ME!
206     */

207    public int doStartTag() throws JspException JavaDoc {
208       return SKIP_BODY;
209    }
210 }
211
Popular Tags