1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
44 private String dir;
45 private String name;
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
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
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 }