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 import org.apache.struts.util.RequestUtils; 22 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.jsp.JspException ; 25 import javax.servlet.jsp.PageContext ; 26 import javax.servlet.jsp.tagext.SimpleTagSupport ; 27 28 62 public class BaseTag extends SimpleTagSupport { 63 64 protected transient final Log log = LogFactory.getLog(BaseTag.class); 65 66 69 protected String server; 70 71 74 protected String target; 75 76 79 protected Boolean fullPath = Boolean.FALSE; 80 81 84 protected String var; 85 86 89 protected String scope; 90 91 100 public String getServer() { 101 return server; 102 } 103 104 109 public void setServer(String server) { 110 this.server = server; 111 } 112 113 122 public String getTarget() { 123 return target; 124 } 125 126 131 public void setTarget(String target) { 132 this.target = target; 133 } 134 135 144 public Boolean getFullPath() { 145 return fullPath; 146 } 147 148 153 public void setFullPath(Boolean fullPath) { 154 this.fullPath = fullPath; 155 } 156 157 166 public String getVar() { 167 return var; 168 } 169 170 175 public void setVar(String var) { 176 this.var = var; 177 } 178 179 188 public String getScope() { 189 return scope; 190 } 191 192 197 public void setScope(String scope) { 198 this.scope = scope; 199 } 200 201 206 public void doTag() throws JspException { 207 208 PageContext pageContext = (PageContext ) getJspContext(); 209 210 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 211 212 if ( fullPath == null ) { 213 fullPath = Boolean.FALSE; 214 } 215 216 217 if ( server == null || server.length() == 0 ) { 218 server = request.getServerName(); 219 } 220 221 String uri = request.getContextPath(); 222 if ( fullPath.booleanValue() ) { 223 uri = request.getRequestURI(); 224 } else { 225 uri += "/"; 226 } 227 228 StringBuffer tag = new StringBuffer ("<base HREF=\""); 229 StringBuffer hrefValue = RequestUtils.createServerUriStringBuffer(request.getScheme(), server, request.getServerPort(), uri); 230 tag.append(hrefValue); 231 tag.append("\""); 232 if ( target != null && target.length() > 0 ) { 233 tag.append(" target=\"").append(target).append("\""); 234 } 235 236 TagUtils tagUtils = TagUtils.getInstance(); 237 if ( tagUtils.isXhtml(pageContext) ) { 238 tag.append(" />"); 239 } else { 240 tag.append(">"); 241 } 242 243 if ( var != null ) { 244 int varScope = PageContext.PAGE_SCOPE; 246 if ( scope != null ) { 247 varScope = tagUtils.getScope(scope); 248 } 249 pageContext.setAttribute(var, hrefValue.toString(), varScope); 250 251 } else { 252 tagUtils.write(pageContext, tag.toString()); 253 } 254 255 } 256 257 } 258 | Popular Tags |