struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/html BaseTag.java
Date Fri, 16 May 2003 12:34:50 GMT
dgraham     2003/05/16 05:34:50

  Modified:    src/share/org/apache/struts/taglib/html BaseTag.java
  Log:
  Refactored doStartTag() into smaller methods.
  
  Revision  Changes    Path
  1.15      +71 -40    jakarta-struts/src/share/org/apache/struts/taglib/html/BaseTag.java
  
  Index: BaseTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/BaseTag.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- BaseTag.java	8 Mar 2003 19:23:49 -0000	1.14
  +++ BaseTag.java	16 May 2003 12:34:50 -0000	1.15
  @@ -118,52 +118,83 @@
        */
       public int doStartTag() throws JspException {
           HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
  -        String serverName = request.getServerName();
  -        String scheme = request.getScheme();
  -        int port = request.getServerPort();
  -        
  -        StringBuffer buf = new StringBuffer("<base href=\"");
  -        buf.append(scheme);
  -        buf.append("://");
  +        String serverName = (this.server == null) ? request.getServerName() : this.server;
  +        
  +        String baseTag =
  +            renderBaseElement(
  +                request.getScheme(),
  +                serverName,
  +                request.getServerPort(),
  +                request.getRequestURI());
   
  -        if (this.server != null) {
  -            serverName = this.server;
  +        JspWriter out = pageContext.getOut();
  +        try {
  +            out.write(baseTag);
  +        } catch (IOException e) {
  +            pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
  +            throw new JspException(messages.getMessage("common.io", e.toString()));
           }
  +        
  +        return EVAL_BODY_INCLUDE;
  +    }
   
  -        buf.append(serverName);
  -        if ("http".equals(scheme) && (80 == port)) {
  +    /**
  +     * Render a fully formed HTML &lt;base&gt; element and return it as a String.
  +     * @param scheme The scheme used in the url (ie. http or https).
  +     * @param serverName
  +     * @param port
  +     * @param uri  The portion of the url from the protocol name up to the query 
  +     * string.
  +     * @return String An HTML &lt;base&gt; element.
  +     */
  +    protected String renderBaseElement(
  +        String scheme,
  +        String serverName,
  +        int port,
  +        String uri) {
  +            
  +        StringBuffer tag = new StringBuffer("<base href=\"");
  +        tag.append(scheme);
  +        tag.append("://");
  +        
  +        tag.append(serverName);
  +        if ("http".equals(scheme) && (port == 80)) {
               ;
  -        } else if ("https".equals(scheme) && (443 == port)) {
  +        } else if ("https".equals(scheme) && (port == 443)) {
               ;
           } else {
  -            buf.append(":");
  -            buf.append(port);
  +            tag.append(":");
  +            tag.append(port);
           }
  -        buf.append(request.getRequestURI());
  -        buf.append("\"");
  -        if (target != null) {
  -            buf.append(" target=\"");
  -            buf.append(target);
  -            buf.append("\"");
  +        
  +        tag.append(uri);
  +        tag.append("\"");
  +        
  +        if (this.target != null) {
  +            tag.append(" target=\"");
  +            tag.append(this.target);
  +            tag.append("\"");
           }
  -
  -        String xhtml =
  -            (String) this.pageContext.getAttribute(Globals.XHTML_KEY, PageContext.PAGE_SCOPE);
  -
  -        if ("true".equalsIgnoreCase(xhtml)) {
  -            buf.append(" />");
  +        
  +        if (this.isXhtml()) {
  +            tag.append(" />");
           } else {
  -            buf.append(">");
  +            tag.append(">");
           }
  +        
  +        return tag.toString();
  +    }
   
  -        JspWriter out = pageContext.getOut();
  -        try {
  -            out.write(buf.toString());
  -        } catch (IOException e) {
  -            pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
  -            throw new JspException(messages.getMessage("common.io", e.toString()));
  -        }
  -        return EVAL_BODY_INCLUDE;
  +    /**
  +     * Returns true if the tag is in XHTML mode.
  +     */
  +    protected boolean isXhtml() {
  +        String xhtml =
  +            (String) this.pageContext.getAttribute(
  +                Globals.XHTML_KEY,
  +                PageContext.PAGE_SCOPE);
  +
  +        return "true".equalsIgnoreCase(xhtml);
       }
       
       /**
  @@ -171,7 +202,7 @@
        * @return String
        */
       public String getServer() {
  -        return server;
  +        return this.server;
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


Mime
View raw message