1 18 19 package org.apache.struts.taglib.html; 20 21 import java.net.MalformedURLException ; 22 import java.util.HashMap ; 23 import java.util.Map ; 24 25 import javax.servlet.jsp.JspException ; 26 27 import org.apache.struts.taglib.TagUtils; 28 import org.apache.struts.taglib.logic.IterateTag; 29 import org.apache.struts.util.MessageResources; 30 31 36 public class LinkTag extends BaseHandlerTag { 37 38 39 41 42 45 protected String text = null; 46 47 49 public LinkTag() { 50 super(); 51 doDisabled = false; 52 } 53 54 55 57 58 61 protected String anchor = null; 62 63 public String getAnchor() { 64 return (this.anchor); 65 } 66 67 public void setAnchor(String anchor) { 68 this.anchor = anchor; 69 } 70 71 72 81 protected String forward = null; 82 83 public String getForward() { 84 return (this.forward); 85 } 86 87 public void setForward(String forward) { 88 this.forward = forward; 89 } 90 91 92 95 protected String href = null; 96 97 public String getHref() { 98 return (this.href); 99 } 100 101 public void setHref(String href) { 102 this.href = href; 103 } 104 105 106 109 protected String linkName = null; 110 111 public String getLinkName() { 112 return (this.linkName); 113 } 114 115 public void setLinkName(String linkName) { 116 this.linkName = linkName; 117 } 118 119 120 123 protected static MessageResources messages = 124 MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); 125 126 127 130 protected String name = null; 131 132 public String getName() { 133 return (this.name); 134 } 135 136 public void setName(String name) { 137 this.name = name; 138 } 139 140 141 145 protected String page = null; 146 147 public String getPage() { 148 return (this.page); 149 } 150 151 public void setPage(String page) { 152 this.page = page; 153 } 154 155 156 160 protected String action = null; 161 162 public String getAction() { 163 return (this.action); 164 } 165 166 public void setAction(String action) { 167 this.action = action; 168 } 169 170 171 175 protected String module = null; 176 177 public String getModule() { 178 return (this.module); 179 } 180 181 public void setModule(String module) { 182 this.module = module; 183 } 184 185 186 189 protected String paramId = null; 190 191 public String getParamId() { 192 return (this.paramId); 193 } 194 195 public void setParamId(String paramId) { 196 this.paramId = paramId; 197 } 198 199 200 203 protected String paramName = null; 204 205 public String getParamName() { 206 return (this.paramName); 207 } 208 209 public void setParamName(String paramName) { 210 this.paramName = paramName; 211 } 212 213 214 217 protected String paramProperty = null; 218 219 public String getParamProperty() { 220 return (this.paramProperty); 221 } 222 223 public void setParamProperty(String paramProperty) { 224 this.paramProperty = paramProperty; 225 } 226 227 228 231 protected String paramScope = null; 232 233 public String getParamScope() { 234 return (this.paramScope); 235 } 236 237 public void setParamScope(String paramScope) { 238 this.paramScope = paramScope; 239 } 240 241 242 245 protected String property = null; 246 247 public String getProperty() { 248 return (this.property); 249 } 250 251 public void setProperty(String property) { 252 this.property = property; 253 } 254 255 256 259 protected String scope = null; 260 261 public String getScope() { 262 return (this.scope); 263 } 264 265 public void setScope(String scope) { 266 this.scope = scope; 267 } 268 269 270 273 protected String target = null; 274 275 public String getTarget() { 276 return (this.target); 277 } 278 279 public void setTarget(String target) { 280 this.target = target; 281 } 282 283 284 287 protected boolean transaction = false; 288 289 public boolean getTransaction() { 290 return (this.transaction); 291 } 292 293 public void setTransaction(boolean transaction) { 294 this.transaction = transaction; 295 } 296 297 300 protected String indexId = null; 301 302 public String getIndexId() { 303 return (this.indexId); 304 } 305 306 public void setIndexId(String indexId) { 307 this.indexId = indexId; 308 } 309 310 protected boolean useLocalEncoding = false; 311 312 public boolean isUseLocalEncoding() { 313 return useLocalEncoding; 314 } 315 316 public void setUseLocalEncoding(boolean b) { 317 useLocalEncoding = b; 318 } 319 320 322 323 330 public int doStartTag() throws JspException { 331 332 StringBuffer results = new StringBuffer ("<a"); 334 335 prepareAttribute(results, "name", getLinkName()); 337 338 if (getLinkName() == null || getForward() != null || getHref() != null || 340 getPage() != null || getAction() != null) { 341 prepareAttribute(results, "href", calculateURL()); 342 } 343 prepareAttribute(results, "target", getTarget()); 344 prepareAttribute(results, "accesskey", getAccesskey()); 345 prepareAttribute(results, "tabindex", getTabindex()); 346 results.append(prepareStyles()); 347 results.append(prepareEventHandlers()); 348 prepareOtherAttributes(results); 349 results.append(">"); 350 351 TagUtils.getInstance().write(pageContext, results.toString()); 352 353 this.text = null; 355 return (EVAL_BODY_TAG); 356 357 } 358 359 360 361 366 public int doAfterBody() throws JspException { 367 368 if (bodyContent != null) { 369 String value = bodyContent.getString().trim(); 370 if (value.length() > 0) 371 text = value; 372 } 373 return (SKIP_BODY); 374 375 } 376 377 378 383 public int doEndTag() throws JspException { 384 385 StringBuffer results = new StringBuffer (); 387 if (text != null) { 388 results.append(text); 389 } 390 results.append("</a>"); 391 392 TagUtils.getInstance().write(pageContext, results.toString()); 393 394 return (EVAL_PAGE); 395 396 } 397 398 399 402 public void release() { 403 404 super.release(); 405 anchor = null; 406 forward = null; 407 href = null; 408 linkName = null; 409 name = null; 410 page = null; 411 action = null; 412 module = null; 413 paramId = null; 414 paramName = null; 415 paramProperty = null; 416 paramScope = null; 417 property = null; 418 scope = null; 419 target = null; 420 text = null; 421 transaction = false; 422 indexId = null; 423 useLocalEncoding = false; 424 425 } 426 427 428 430 431 437 protected String calculateURL() throws JspException { 438 439 Map params = TagUtils.getInstance().computeParameters 441 (pageContext, paramId, paramName, paramProperty, paramScope, 442 name, property, scope, transaction); 443 444 if( indexed ) { 447 448 int indexValue = getIndexValue(); 449 450 if (params == null) { 452 params = new HashMap (); } 454 if (indexId != null) { 455 params.put(indexId, Integer.toString(indexValue)); 456 } else { 457 params.put("index", Integer.toString(indexValue)); 458 } 459 } 460 461 String url = null; 462 try { 463 url = TagUtils.getInstance().computeURLWithCharEncoding(pageContext, forward, href, 464 page, action, module, params, anchor, false, useLocalEncoding); 465 } catch (MalformedURLException e) { 466 TagUtils.getInstance().saveException(pageContext, e); 467 throw new JspException 468 (messages.getMessage("rewrite.url", e.toString())); 469 } 470 return (url); 471 472 } 473 474 475 } 476 | Popular Tags |