1 7 package com.inversoft.verge.mvc.view.jsp.html; 8 9 10 import java.io.IOException ; 11 import java.io.Writer ; 12 import java.util.HashMap ; 13 import java.util.Iterator ; 14 import java.util.Map ; 15 16 import javax.servlet.jsp.JspException ; 17 18 import org.apache.log4j.Logger; 19 20 import com.inversoft.verge.mvc.view.HtmlConstants; 21 import com.inversoft.verge.mvc.view.HtmlViewToolkit; 22 import com.inversoft.verge.mvc.view.jsp.JspTools; 23 24 25 36 public class ATag extends ContextBasedTag { 37 38 private static final Logger logger = Logger.getLogger(ATag.class); 39 40 private String href; 41 protected String localHref; 42 private String rel; 43 protected String localRel; 44 private String rev; 45 protected String localRev; 46 private String shape; 47 protected String localShape; 48 private String coords; 49 protected String localCoords; 50 private String onfocus; 51 protected String localOnfocus; 52 private String onblur; 53 protected String localOnblur; 54 private Map params = new HashMap (); 55 56 57 62 public String getHref() { 63 return href; 64 } 65 66 71 public void setHref(String href) { 72 this.href = href; 73 } 74 75 80 public String getRel() { 81 return rel; 82 } 83 84 89 public void setRel(String rel) { 90 this.rel = rel; 91 } 92 93 98 public String getRev() { 99 return rev; 100 } 101 102 107 public void setRev(String rev) { 108 this.rev = rev; 109 } 110 111 116 public String getCoords() { 117 return coords; 118 } 119 120 125 public void setCoords(String coords) { 126 this.coords = coords; 127 } 128 129 134 public String getShape() { 135 return shape; 136 } 137 138 143 public void setShape(String shape) { 144 this.shape = shape; 145 } 146 147 152 public String getOnfocus() { 153 return onfocus; 154 } 155 156 161 public void setOnfocus(String onfocus) { 162 this.onfocus = onfocus; 163 } 164 165 170 public String getOnblur() { 171 return onblur; 172 } 173 174 179 public void setOnblur(String onblur) { 180 this.onblur = onblur; 181 } 182 183 186 public Map getParameterMap() { 187 return params; 188 } 189 190 195 protected void initialize() throws JspException { 196 super.initialize(); 197 198 localHref = href; 199 localRel = rel; 200 localRev = rev; 201 localCoords = coords; 202 localShape = shape; 203 localOnfocus = onfocus; 204 localOnblur = onblur; 205 206 if (!JspTools.JSP_20) { 208 localHref = (String ) JspTools.expand("href", href, String .class, this, 209 pageContext); 210 localRel = (String ) JspTools.expand("rel", rel, String .class, this, 211 pageContext); 212 localRev = (String ) JspTools.expand("rev", rev, String .class, this, 213 pageContext); 214 localCoords = (String ) JspTools.expand("coords", coords, String .class, 215 this, pageContext); 216 localShape = (String ) JspTools.expand("shape", shape, String .class, 217 this, pageContext); 218 localOnfocus = (String ) JspTools.expand("onfocus", onfocus, 219 String .class, this, pageContext); 220 localOnblur = (String ) JspTools.expand("onblur", onblur, String .class, 221 this, pageContext); 222 } 223 224 attributes.put(HtmlConstants.REL, localRel); 225 attributes.put(HtmlConstants.REV, localRev); 226 attributes.put(HtmlConstants.COORDS, localCoords); 227 attributes.put(HtmlConstants.SHAPE, localShape); 228 attributes.put(HtmlConstants.ON_FOCUS, localOnfocus); 229 attributes.put(HtmlConstants.ON_BLUR, localOnblur); 230 } 231 232 237 public int doStartTag() throws JspException { 238 initialize(); 239 logger.debug("Inside doStartBody, returning buffered"); 240 241 return EVAL_BODY_BUFFERED; 242 } 243 244 250 public int doAfterBody() throws JspException { 251 logger.debug("Inside doAfterBody, outputting tag"); 252 253 StringBuffer buf = new StringBuffer (128); 254 Writer writer = bodyContent.getEnclosingWriter(); 255 createATag(buf, getId(), localName, localHref, getParameterMap()); 256 257 try { 258 writer.write(buf.toString()); 259 260 if (bodyContent != null) { 261 bodyContent.writeOut(writer); 262 } 263 264 writer.write("</a>"); 265 } catch (IOException ioe) { 266 throw new JspException (ioe.toString()); 267 } 268 269 return SKIP_BODY; 270 } 271 272 275 public int doEndTag() throws JspException { 276 277 getParameterMap().clear(); 279 280 return EVAL_PAGE; 281 } 282 283 292 protected void createATag(StringBuffer buf, String id, String name, String href, 293 Map parameters) 294 throws JspException { 295 296 if (href != null) { 298 299 if (parameters.size() > 0) { 300 StringBuffer url = new StringBuffer (); 301 url.append(href); 302 if (url.indexOf("?") == -1) { 303 url.append("?"); 304 } else { 305 url.append("&"); 306 } 307 308 Iterator iter = parameters.entrySet().iterator(); 309 Map.Entry entry; 310 while (iter.hasNext()) { 311 entry = (Map.Entry ) iter.next(); 312 url.append(entry.getKey().toString()); 313 url.append("="); 314 url.append(entry.getValue().toString()); 315 316 if (iter.hasNext()) { 317 url.append("&"); 318 } 319 } 320 321 href = url.toString(); 322 } 323 324 StringBuffer tempHref = new StringBuffer (); 326 appendContextPlusURL(tempHref, href); 327 href = tempHref.toString(); 328 } 329 330 HtmlViewToolkit.createAnchorTag(buf, id, name, href, attributes, singleAttrs); 332 } 333 } | Popular Tags |