1 16 package com.blandware.atleap.webapp.taglib.core.logic; 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 96 public class RedirectTag extends SimpleTagSupport implements ParamParent { 97 98 protected transient final Log log = LogFactory.getLog(RedirectTag.class); 99 100 103 protected String action; 104 105 108 protected String forward; 109 110 113 protected String href; 114 115 118 protected String anchor; 119 120 123 protected Boolean transaction = Boolean.FALSE; 124 125 128 protected Boolean addLocaleSuffix = Boolean.TRUE; 129 130 133 protected Map parameters = new HashMap (); 134 135 144 public String getAction() { 145 return action; 146 } 147 148 153 public void setAction(String action) { 154 this.action = action; 155 } 156 157 166 public String getForward() { 167 return forward; 168 } 169 170 175 public void setForward(String forward) { 176 this.forward = forward; 177 } 178 179 188 public String getHref() { 189 return href; 190 } 191 192 197 public void setHref(String href) { 198 this.href = href; 199 } 200 201 210 public String getAnchor() { 211 return anchor; 212 } 213 214 219 public void setAnchor(String anchor) { 220 this.anchor = anchor; 221 } 222 223 232 public Boolean getTransaction() { 233 return transaction; 234 } 235 236 241 public void setTransaction(Boolean transaction) { 242 this.transaction = transaction; 243 } 244 245 254 public Boolean getAddLocaleSuffix() { 255 return addLocaleSuffix; 256 } 257 258 263 public void setAddLocaleSuffix(Boolean addLocaleSuffix) { 264 this.addLocaleSuffix = addLocaleSuffix; 265 } 266 267 273 public void doTag() throws JspException , IOException { 274 275 PageContext pageContext = (PageContext ) getJspContext(); 276 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 277 HttpServletResponse response = (HttpServletResponse ) pageContext.getResponse(); 278 279 if ( transaction == null ) { 280 transaction = Boolean.FALSE; 281 } 282 283 if ( addLocaleSuffix == null ) { 284 addLocaleSuffix = Boolean.TRUE; 285 } 286 287 JspFragment body = getJspBody(); 289 if ( body != null ) { 290 body.invoke(null); 291 } 292 293 if ( transaction.booleanValue() ) { 295 HttpSession session = pageContext.getSession(); 296 String token = null; 297 if ( session != null ) { 298 token = (String ) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY); 299 } 300 301 if ( token != null ) { 302 parameters.put(Constants.TOKEN_KEY, token); 303 } 304 } 305 306 String result = null; 307 try { 308 result = WebappUtil.computeURL(action, forward, href, anchor, parameters, request, response, true, true, addLocaleSuffix.booleanValue()); 309 } catch ( MalformedURLException e ) { 310 TagUtils.getInstance().saveException(pageContext, e); 311 throw new JspTagException (e); 312 } 313 314 response.sendRedirect(result); 316 } 317 318 321 public void addParameter(String name, Object value) { 322 parameters.put(name, RequestUtil.mergeValues(parameters.get(name), value)); 323 } 324 325 } 326 | Popular Tags |