1 16 package com.blandware.atleap.webapp.taglib.core.html; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.apache.struts.taglib.TagUtils; 21 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.PageContext ; 24 import javax.servlet.jsp.tagext.SimpleTagSupport ; 25 26 64 public class RandomLinkTag extends SimpleTagSupport { 65 66 protected transient final Log log = LogFactory.getLog(RandomLinkTag.class); 67 68 71 protected String value; 72 73 76 protected String var; 77 78 81 protected String scope; 82 83 92 public String getValue() { 93 return value; 94 } 95 96 101 public void setValue(String value) { 102 this.value = value; 103 } 104 105 114 public String getVar() { 115 return var; 116 } 117 118 123 public void setVar(String var) { 124 this.var = var; 125 } 126 127 136 public String getScope() { 137 return scope; 138 } 139 140 145 public void setScope(String scope) { 146 this.scope = scope; 147 } 148 149 154 public void doTag() throws JspException { 155 156 PageContext pageContext = (PageContext ) getJspContext(); 157 158 double randomValue = Math.random(); 159 String rnd = "rnd=" + randomValue; 160 if ( value.indexOf('?') != -1 ) { 161 value += "&" + rnd; 162 } else { 163 value += "?" + rnd; 164 } 165 166 TagUtils tagUtils = TagUtils.getInstance(); 167 if ( var != null ) { 168 int varScope = PageContext.PAGE_SCOPE; 170 if ( scope != null ) { 171 varScope = tagUtils.getScope(scope); 172 } 173 pageContext.setAttribute(var, value, varScope); 174 175 } else { 176 tagUtils.write(pageContext, value); 177 } 178 } 179 } 180 | Popular Tags |