1 18 19 package org.apache.struts.taglib.html; 20 21 import java.io.IOException ; 22 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.jsp.JspException ; 25 import javax.servlet.jsp.JspWriter ; 26 import javax.servlet.jsp.PageContext ; 27 import javax.servlet.jsp.tagext.TagSupport ; 28 29 import org.apache.struts.Globals; 30 import org.apache.struts.taglib.TagUtils; 31 import org.apache.struts.util.MessageResources; 32 import org.apache.struts.util.RequestUtils; 33 34 44 45 public class BaseTag extends TagSupport { 46 47 50 protected static MessageResources messages = 51 MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); 52 53 56 protected String server = null; 57 58 61 protected String target = null; 62 63 public String getTarget() { 64 return (this.target); 65 } 66 67 public void setTarget(String target) { 68 this.target = target; 69 } 70 71 76 public int doStartTag() throws JspException { 77 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 78 String serverName = (this.server == null) ? request.getServerName() : this.server; 79 80 String baseTag = 81 renderBaseElement( 82 request.getScheme(), 83 serverName, 84 request.getServerPort(), 85 request.getRequestURI()); 86 87 JspWriter out = pageContext.getOut(); 88 try { 89 out.write(baseTag); 90 } catch (IOException e) { 91 pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); 92 throw new JspException (messages.getMessage("common.io", e.toString())); 93 } 94 95 return EVAL_BODY_INCLUDE; 96 } 97 98 108 protected String renderBaseElement( 109 String scheme, 110 String serverName, 111 int port, 112 String uri) { 113 114 StringBuffer tag = new StringBuffer ("<base HREF=\""); 115 tag.append(RequestUtils.createServerUriStringBuffer(scheme,serverName,port,uri).toString()); 116 117 tag.append("\""); 118 119 if (this.target != null) { 120 tag.append(" target=\""); 121 tag.append(this.target); 122 tag.append("\""); 123 } 124 125 if (TagUtils.getInstance().isXhtml(this.pageContext)) { 126 tag.append(" />"); 127 } else { 128 tag.append(">"); 129 } 130 131 return tag.toString(); 132 } 133 134 138 public String getServer() { 139 return this.server; 140 } 141 142 146 public void setServer(String server) { 147 this.server = server; 148 } 149 150 } 151 | Popular Tags |