View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/TemplateParamTag.java,v 1.15 2006/01/13 13:38:51 hkollmann Exp $
3    * $Revision: 1.15 $
4    * $Date: 2006/01/13 13:38:51 $
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;
31  
32  
33  
34  /***
35   * Renders an dbforms style tag
36   *
37   * @author Joe Peer
38   */
39  public class TemplateParamTag extends AbstractScriptHandlerTag
40     implements javax.servlet.jsp.tagext.TryCatchFinally {
41     private Hashtable sp;
42     private String    baseDir;
43     private String    defaultValue; // properties set by JSP container
44     private String    dir; // properties set by JSP container
45     private String    name; // properties set by JSP container
46  
47     /***
48      * DOCUMENT ME!
49      *
50      * @param defaultValue DOCUMENT ME!
51      */
52     public void setDefaultValue(String defaultValue) {
53        this.defaultValue = defaultValue;
54     }
55  
56  
57     /***
58      * DOCUMENT ME!
59      *
60      * @return DOCUMENT ME!
61      */
62     public String getDefaultValue() {
63        return defaultValue;
64     }
65  
66  
67     /***
68      * DOCUMENT ME!
69      *
70      * @param dir DOCUMENT ME!
71      */
72     public void setDir(String 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 getDir() {
87        return dir;
88     }
89  
90  
91     /***
92      * DOCUMENT ME!
93      *
94      * @param name DOCUMENT ME!
95      */
96     public void setName(String name) {
97        this.name = name;
98     }
99  
100 
101    /***
102     * DOCUMENT ME!
103     *
104     * @return DOCUMENT ME!
105     */
106    public String 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 pageContext) {
117       super.setPageContext(pageContext);
118       this.sp = (java.util.Hashtable) pageContext.getRequest()
119                                                  .getAttribute("styleparams");
120       this.baseDir = (String) pageContext.getRequest()
121                                          .getAttribute("baseDir");
122    }
123 
124 
125    /***
126     * DOCUMENT ME!
127     *
128     * @return DOCUMENT ME!
129     *
130     * @throws JspException DOCUMENT ME!
131     */
132    public int doEndTag() throws JspException {
133       try {
134          StringBuffer buf = new StringBuffer();
135 
136          // determinate dir
137          if (dir != null) {
138             buf.append(baseDir);
139             buf.append(dir);
140 
141             if (dir.length() > 0) {
142                buf.append("/");
143             }
144          }
145 
146          // determinate param value
147          if (sp == null) {
148             if (defaultValue != null) {
149                buf.append(defaultValue);
150             }
151          } else {
152             String paramValue = (String) sp.get(name);
153 
154             if (paramValue != null) {
155                buf.append(paramValue);
156             } else {
157                if (defaultValue != null) {
158                   buf.append(defaultValue);
159                }
160             }
161          }
162 
163          pageContext.getOut()
164                     .flush();
165          pageContext.getOut()
166                     .write(buf.toString());
167       } catch (IOException ioe) {
168          throw new JspException("Problem including template end - "
169                                 + ioe.toString());
170       }
171 
172       return EVAL_PAGE;
173    }
174 
175 
176    /***
177     * DOCUMENT ME!
178     */
179    public void doFinally() {
180       name         = null;
181       defaultValue = null;
182       dir          = null;
183       baseDir      = null;
184       sp           = null;
185    }
186 
187 
188    /***
189     * DOCUMENT ME!
190     *
191     * @return DOCUMENT ME!
192     *
193     * @throws JspException DOCUMENT ME!
194     */
195    public int doStartTag() throws JspException {
196       return SKIP_BODY;
197    }
198 }