1 23 24 package org.dbforms.taglib; 25 26 import java.util.Hashtable ; 27 import java.util.StringTokenizer ; 28 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.jsp.JspException ; 31 32 33 34 39 public class StyleTag extends TagSupportWithScriptHandler 40 implements javax.servlet.jsp.tagext.TryCatchFinally { 41 private Hashtable params; 42 private String paramList; 43 private String part; 44 45 private String template; 47 48 private String templateBase; 50 private String templateBaseDir; 51 52 57 public void setPageContext(final javax.servlet.jsp.PageContext pageContext) { 58 super.setPageContext(pageContext); 59 60 templateBase = pageContext.getServletContext() 61 .getInitParameter("templateBase"); 62 63 if (templateBase == null) { 64 templateBase = "templates"; 65 } 66 } 67 68 69 74 public void setParamList(String paramList) { 75 this.paramList = paramList; 76 this.params = parseParams(paramList); 77 } 78 79 80 85 public String getParamList() { 86 return paramList; 87 } 88 89 90 95 public void setPart(String part) { 96 this.part = part; 97 } 98 99 100 105 public String getPart() { 106 return part; 107 } 108 109 110 115 public void setTemplate(String template) { 116 this.template = template; 117 this.templateBaseDir = templateBase + "/" + template + "/"; 118 119 } 122 123 124 129 public String getTemplate() { 130 return template; 131 } 132 133 134 141 public int doAfterBody() throws JspException { 142 return SKIP_BODY; } 144 145 146 153 public void doCatch(Throwable t) throws Throwable { 154 throw t; 155 } 156 157 158 165 public int doEndTag() throws JspException { 166 try { 167 if (bodyContent != null) { 168 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 169 } 170 171 HttpServletRequest request = (HttpServletRequest ) pageContext 172 .getRequest(); 173 174 if (params != null) { 175 request.setAttribute("styleparams", params); 176 } 177 178 request.setAttribute("baseDir", templateBaseDir); 179 180 pageContext.include(templateBaseDir + template + "_" + part + ".jsp"); 181 } catch (Exception ioe) { 182 throw new JspException ("Problem 2 including template end - " 183 + ioe.toString()); 184 } 185 186 return EVAL_PAGE; 187 } 188 189 190 193 public void doFinally() { 194 params = null; 195 templateBase = null; 196 templateBaseDir = null; 197 template = null; 198 paramList = null; 199 part = null; 200 } 201 202 203 206 public int doStartTag() throws JspException { 207 225 return EVAL_BODY_BUFFERED; 226 } 227 228 229 239 private Hashtable parseParams(String s) { 240 Hashtable result = new Hashtable (); 241 242 StringTokenizer st = new StringTokenizer (s, ","); 244 245 while (st.hasMoreTokens()) { 246 String token = st.nextToken(); 248 int equalSignIndex = token.indexOf('='); 249 250 String key = token.substring(0, equalSignIndex) 252 .trim(); 253 254 String value = token.substring(equalSignIndex + 1) 256 .trim(); 257 258 if ((value.charAt(0) == '\'') 259 && (value.charAt(value.length() - 1) == '\'')) { 261 value = value.substring(1, value.length() - 1); 262 } 263 264 result.put(key, value); 265 } 266 267 return result; 268 } 269 } 270 | Popular Tags |