1 16 package com.blandware.atleap.webapp.taglib.core.html; 17 18 import com.blandware.atleap.webapp.taglib.core.ParamParent; 19 import com.blandware.atleap.webapp.util.core.RequestUtil; 20 import com.blandware.atleap.webapp.util.core.WebappUtil; 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 import org.apache.struts.Globals; 24 import org.apache.struts.taglib.TagUtils; 25 import org.apache.struts.taglib.html.Constants; 26 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpServletResponse ; 29 import javax.servlet.http.HttpSession ; 30 import javax.servlet.jsp.JspException ; 31 import javax.servlet.jsp.JspTagException ; 32 import javax.servlet.jsp.PageContext ; 33 import javax.servlet.jsp.tagext.JspFragment ; 34 import javax.servlet.jsp.tagext.SimpleTagSupport ; 35 import java.io.IOException ; 36 import java.net.MalformedURLException ; 37 import java.util.HashMap ; 38 import java.util.Map ; 39 40 109 public class RewriteUrlTag extends SimpleTagSupport implements ParamParent { 110 111 protected transient final Log log = LogFactory.getLog(RewriteUrlTag.class); 112 113 116 protected String action; 117 118 121 protected String forward; 122 123 126 protected String href; 127 128 131 protected String anchor; 132 133 136 protected Boolean transaction = Boolean.FALSE; 137 138 141 protected Boolean addLocaleSuffix = Boolean.TRUE; 142 143 146 protected String var; 147 148 151 protected String scope; 152 153 156 protected Map parameters = new HashMap (); 157 158 167 public String getAction() { 168 return action; 169 } 170 171 176 public void setAction(String action) { 177 this.action = action; 178 } 179 180 189 public String getForward() { 190 return forward; 191 } 192 193 198 public void setForward(String forward) { 199 this.forward = forward; 200 } 201 202 211 public String getHref() { 212 return href; 213 } 214 215 220 public void setHref(String href) { 221 this.href = href; 222 } 223 224 233 public String getAnchor() { 234 return anchor; 235 } 236 237 242 public void setAnchor(String anchor) { 243 this.anchor = anchor; 244 } 245 246 255 public Boolean getTransaction() { 256 return transaction; 257 } 258 259 264 public void setTransaction(Boolean transaction) { 265 this.transaction = transaction; 266 } 267 268 277 public Boolean getAddLocaleSuffix() { 278 return addLocaleSuffix; 279 } 280 281 286 public void setAddLocaleSuffix(Boolean addLocaleSuffix) { 287 this.addLocaleSuffix = addLocaleSuffix; 288 } 289 290 299 public String getVar() { 300 return var; 301 } 302 303 308 public void setVar(String var) { 309 this.var = var; 310 } 311 312 321 public String getScope() { 322 return scope; 323 } 324 325 330 public void setScope(String scope) { 331 this.scope = scope; 332 } 333 334 340 public void doTag() throws JspException , IOException { 341 342 PageContext pageContext = (PageContext ) getJspContext(); 343 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 344 HttpServletResponse response = (HttpServletResponse ) pageContext.getResponse(); 345 346 if ( transaction == null ) { 347 transaction = Boolean.FALSE; 348 } 349 350 if ( addLocaleSuffix == null ) { 351 addLocaleSuffix = Boolean.TRUE; 352 } 353 354 JspFragment body = getJspBody(); 356 if ( body != null ) { 357 body.invoke(null); 358 } 359 360 if ( transaction.booleanValue() ) { 362 HttpSession session = pageContext.getSession(); 363 String token = null; 364 if ( session != null ) { 365 token = (String ) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY); 366 } 367 368 if ( token != null ) { 369 parameters.put(Constants.TOKEN_KEY, token); 370 } 371 } 372 373 String result = null; 374 TagUtils tagUtils = TagUtils.getInstance(); 375 try { 376 result = WebappUtil.computeURL(action, forward, href, anchor, parameters, request, response, true, false, addLocaleSuffix.booleanValue()); 377 } catch ( MalformedURLException e ) { 378 tagUtils.saveException(pageContext, e); 379 throw new JspTagException (e); 380 } 381 382 383 if ( var != null ) { 384 int varScope = PageContext.PAGE_SCOPE; 385 if ( scope != null ) { 386 varScope = tagUtils.getScope(scope); 387 } 388 pageContext.setAttribute(var, result, varScope); 389 } else { 390 tagUtils.write(pageContext, result); 391 } 392 } 393 394 397 public void addParameter(String name, Object value) { 398 parameters.put(name, RequestUtil.mergeValues(parameters.get(name), value)); 399 } 400 401 } 402 | Popular Tags |