1 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 39 public class TemplateParamTag extends TagSupportWithScriptHandler 40 implements javax.servlet.jsp.tagext.TryCatchFinally { 41 private Hashtable sp; 42 private String baseDir; 43 private String defaultValue; private String dir; private String name; 47 52 public void setDefaultValue(String defaultValue) { 53 this.defaultValue = defaultValue; 54 } 55 56 57 62 public String getDefaultValue() { 63 return defaultValue; 64 } 65 66 67 72 public void setDir(String dir) { 73 if (dir.equals(".")) { 74 this.dir = ""; 75 } else { 76 this.dir = dir; 77 } 78 } 79 80 81 86 public String getDir() { 87 return dir; 88 } 89 90 91 96 public void setName(String name) { 97 this.name = name; 98 } 99 100 101 106 public String getName() { 107 return name; 108 } 109 110 111 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 132 public void doCatch(Throwable t) throws Throwable { 133 throw t; 134 } 135 136 137 144 public int doEndTag() throws JspException { 145 try { 146 StringBuffer buf = new StringBuffer (); 147 148 if (dir != null) { 150 buf.append(baseDir); 151 buf.append(dir); 152 153 if (dir.length() > 0) { 154 buf.append("/"); 155 } 156 } 157 158 if (sp == null) { 160 if (defaultValue != null) { 161 buf.append(defaultValue); 162 } 163 } else { 164 String paramValue = (String ) 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 ("Problem including template end - " 181 + ioe.toString()); 182 } 183 184 return EVAL_PAGE; 185 } 186 187 188 191 public void doFinally() { 192 name = null; 193 defaultValue = null; 194 dir = null; 195 baseDir = null; 196 sp = null; 197 } 198 199 200 207 public int doStartTag() throws JspException { 208 return SKIP_BODY; 209 } 210 } 211 | Popular Tags |