You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2003/07/14 01:33:27 UTC

cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/logic RedirectTag.java ForwardTag.java

dgraham     2003/07/13 16:33:27

  Modified:    src/share/org/apache/struts/taglib/logic RedirectTag.java
                        ForwardTag.java
  Log:
  Fixed formatting.
  
  Revision  Changes    Path
  1.15      +54 -56    jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java
  
  Index: RedirectTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- RedirectTag.java	23 Sep 2002 05:22:08 -0000	1.14
  +++ RedirectTag.java	13 Jul 2003 23:33:27 -0000	1.15
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,33 +59,29 @@
    *
    */
   
  -
   package org.apache.struts.taglib.logic;
   
  -
   import java.io.IOException;
   import java.net.MalformedURLException;
   import java.util.Map;
  +
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.jsp.JspException;
   import javax.servlet.jsp.tagext.TagSupport;
  +
   import org.apache.struts.util.MessageResources;
   import org.apache.struts.util.RequestUtils;
   
  -
   /**
    * Generate a URL-encoded redirect to the specified URI.
    *
    * @author Craig R. McClanahan
    * @version $Revision$ $Date$
    */
  -
   public class RedirectTag extends TagSupport {
   
  -
       // ------------------------------------------------------------- Properties
   
  -
       /**
        * The anchor to be added to the end of the generated hyperlink.
        */
  @@ -99,42 +95,38 @@
           this.anchor = anchor;
       }
   
  -
       /**
        * The logical forward name from which to retrieve the redirect URI.
        */
       protected String forward = null;
   
       public String getForward() {
  -    return (this.forward);
  +        return (this.forward);
       }
   
       public void setForward(String forward) {
  -    this.forward = forward;
  +        this.forward = forward;
       }
   
  -
       /**
        * The redirect URI.
        */
       protected String href = null;
   
       public String getHref() {
  -    return (this.href);
  +        return (this.href);
       }
   
       public void setHref(String href) {
  -    this.href = href;
  +        this.href = href;
       }
   
  -
       /**
        * The message resources for this package.
        */
       protected static MessageResources messages =
  -     MessageResources.getMessageResources
  -        ("org.apache.struts.taglib.logic.LocalStrings");
  -
  +        MessageResources.getMessageResources(
  +            "org.apache.struts.taglib.logic.LocalStrings");
   
       /**
        * The JSP bean name for query parameters.
  @@ -142,14 +134,13 @@
       protected String name = null;
   
       public String getName() {
  -    return (this.name);
  +        return (this.name);
       }
   
       public void setName(String name) {
  -    this.name = name;
  +        this.name = name;
       }
   
  -
       /**
        * The module-relative page URL (beginning with a slash) to which
        * this redirect will be rendered.
  @@ -164,7 +155,6 @@
           this.page = page;
       }
   
  -
       /**
        * The single-parameter request parameter name to generate.
        */
  @@ -178,7 +168,6 @@
           this.paramId = paramId;
       }
   
  -
       /**
        * The single-parameter JSP bean name.
        */
  @@ -192,7 +181,6 @@
           this.paramName = paramName;
       }
   
  -
       /**
        * The single-parameter JSP bean property.
        */
  @@ -206,7 +194,6 @@
           this.paramProperty = paramProperty;
       }
   
  -
       /**
        * The single-parameter JSP bean scope.
        */
  @@ -220,21 +207,19 @@
           this.paramScope = paramScope;
       }
   
  -
       /**
        * The JSP bean property name for query parameters.
        */
       protected String property = null;
   
       public String getProperty() {
  -    return (this.property);
  +        return (this.property);
       }
   
       public void setProperty(String property) {
  -    this.property = property;
  +        this.property = property;
       }
   
  -
       /**
        * The scope of the bean specified by the name property, if any.
        */
  @@ -248,7 +233,6 @@
           this.scope = scope;
       }
   
  -
       /**
        * Include our transaction control token?
        */
  @@ -262,10 +246,8 @@
           this.transaction = transaction;
       }
   
  -
       // --------------------------------------------------------- Public Methods
   
  -
       /**
        * Defer generation until the end of this tag is encountered.
        *
  @@ -277,7 +259,6 @@
   
       }
   
  -
       /**
        * Render the redirect and skip the remainder of this page.
        *
  @@ -286,24 +267,43 @@
       public int doEndTag() throws JspException {
   
           // Calculate the redirect URL
  -        Map params = RequestUtils.computeParameters
  -            (pageContext, paramId, paramName, paramProperty, paramScope,
  -             name, property, scope, transaction);
  +        Map params =
  +            RequestUtils.computeParameters(
  +                pageContext,
  +                paramId,
  +                paramName,
  +                paramProperty,
  +                paramScope,
  +                name,
  +                property,
  +                scope,
  +                transaction);
  +                
           String url = null;
           try {
  -            url = RequestUtils.computeURL(pageContext, forward, href,
  -                                          page, params, anchor, true);
  +            url =
  +                RequestUtils.computeURL(
  +                    pageContext,
  +                    forward,
  +                    href,
  +                    page,
  +                    params,
  +                    anchor,
  +                    true);
  +                    
           } catch (MalformedURLException e) {
               RequestUtils.saveException(pageContext, e);
  -            throw new JspException
  -                (messages.getMessage("redirect.url", e.toString()));
  +            throw new JspException(
  +                messages.getMessage("redirect.url", e.toString()));
           }
   
           // Perform the redirection
  -    HttpServletResponse response =
  -      (HttpServletResponse) pageContext.getResponse();
  +        HttpServletResponse response =
  +            (HttpServletResponse) pageContext.getResponse();
  +            
           try {
               response.sendRedirect(url);
  +            
           } catch (IOException e) {
               RequestUtils.saveException(pageContext, e);
               throw new JspException(e.getMessage());
  @@ -314,26 +314,24 @@
   
       }
   
  -
       /**
        * Release any acquired resources.
        */
       public void release() {
   
  -    super.release();
  +        super.release();
           anchor = null;
  -    forward = null;
  -    href = null;
  -    name = null;
  +        forward = null;
  +        href = null;
  +        name = null;
           page = null;
  -    paramId = null;
  -    paramName = null;
  -    paramProperty = null;
  -    paramScope = null;
  -    property = null;
  +        paramId = null;
  +        paramName = null;
  +        paramProperty = null;
  +        paramScope = null;
  +        property = null;
           scope = null;
   
       }
  -
   
   }
  
  
  
  1.15      +49 -53    jakarta-struts/src/share/org/apache/struts/taglib/logic/ForwardTag.java
  
  Index: ForwardTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/ForwardTag.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ForwardTag.java	1 May 2003 17:13:47 -0000	1.14
  +++ ForwardTag.java	13 Jul 2003 23:33:27 -0000	1.15
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,20 +59,18 @@
    *
    */
   
  -
   package org.apache.struts.taglib.logic;
   
  -
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.jsp.JspException;
   import javax.servlet.jsp.tagext.TagSupport;
  +
   import org.apache.struts.action.ActionForward;
   import org.apache.struts.config.ModuleConfig;
   import org.apache.struts.util.MessageResources;
   import org.apache.struts.util.RequestUtils;
   
  -
   /**
    * Perform a forward or redirect to a page that is looked up in the
    * configuration information associated with our application.
  @@ -80,20 +78,16 @@
    * @author Craig R. McClanahan
    * @version $Revision$ $Date$
    */
  -
   public class ForwardTag extends TagSupport {
   
  -
       // ----------------------------------------------------------- Properties
   
  -
       /**
        * The message resources for this package.
        */
       protected static MessageResources messages =
  -	MessageResources.getMessageResources
  -	("org.apache.struts.taglib.logic.LocalStrings");
  -
  +        MessageResources.getMessageResources(
  +            "org.apache.struts.taglib.logic.LocalStrings");
   
       /**
        * The logical name of the <code>ActionForward</code> entry to be
  @@ -109,10 +103,8 @@
           this.name = name;
       }
   
  -
       // ------------------------------------------------------- Public Methods
   
  -
       /**
        * Defer processing until the end of this tag is encountered.
        *
  @@ -120,11 +112,10 @@
        */
       public int doStartTag() throws JspException {
   
  -	return (SKIP_BODY);
  +        return (SKIP_BODY);
   
       }
   
  -
       /**
        * Look up the ActionForward associated with the specified name,
        * and perform a forward or redirect to that path as indicated.
  @@ -133,55 +124,61 @@
        */
       public int doEndTag() throws JspException {
   
  -	// Look up the desired ActionForward entry
  -	ActionForward forward = null;
  +        // Look up the desired ActionForward entry
  +        ActionForward forward = null;
           ModuleConfig config = RequestUtils.getModuleConfig(pageContext);
  -	if (config != null)
  -	    forward = (ActionForward) config.findForwardConfig(name);
  -	if (forward == null) {
  -            JspException e = new JspException
  -		(messages.getMessage("forward.lookup", name));
  +        
  +        if (config != null){
  +            forward = (ActionForward) config.findForwardConfig(name);
  +        }
  +            
  +        if (forward == null) {
  +            JspException e =
  +                new JspException(messages.getMessage("forward.lookup", name));
               RequestUtils.saveException(pageContext, e);
               throw e;
           }
   
  -	// Forward or redirect to the corresponding actual path
  -	String path = forward.getPath();
  -    path = config.getPrefix() + path;
  +        // Forward or redirect to the corresponding actual path
  +        String path = forward.getPath();
  +        path = config.getPrefix() + path;
   
  -
  -	if (forward.getRedirect()) {
  +        if (forward.getRedirect()) {
               HttpServletRequest request =
                   (HttpServletRequest) pageContext.getRequest();
  -	    HttpServletResponse response =
  -		(HttpServletResponse) pageContext.getResponse();
  -	    try {
  -                if (path.startsWith("/"))
  +                
  +            HttpServletResponse response =
  +                (HttpServletResponse) pageContext.getResponse();
  +                
  +            try {
  +                if (path.startsWith("/")) {
                       path = request.getContextPath() + path;
  -		response.sendRedirect(response.encodeRedirectURL(path));
  -	    } catch (Exception e) {
  +                }
  +                response.sendRedirect(response.encodeRedirectURL(path));
  +                
  +            } catch (Exception e) {
                   RequestUtils.saveException(pageContext, e);
  -		throw new JspException
  -		    (messages.getMessage("forward.redirect",
  -					 name, e.toString()));
  -	    }
  -	} else {
  -	    try {
  -		pageContext.forward(path);
  -	    } catch (Exception e) {
  +                throw new JspException(
  +                    messages.getMessage("forward.redirect", name, e.toString()));
  +            }
  +            
  +        } else {
  +            
  +            try {
  +                pageContext.forward(path);
  +                
  +            } catch (Exception e) {
                   RequestUtils.saveException(pageContext, e);
  -		throw new JspException
  -		    (messages.getMessage("forward.forward",
  -					 name, e.toString()));
  -	    }
  -	}
  +                throw new JspException(
  +                    messages.getMessage("forward.forward", name, e.toString()));
  +            }
  +        }
   
  -	// Skip the remainder of this page
  -	return (SKIP_PAGE);
  +        // Skip the remainder of this page
  +        return (SKIP_PAGE);
   
       }
   
  -
       /**
        * Release all allocated resources.
        */
  @@ -191,6 +188,5 @@
           name = null;
   
       }
  -
   
   }
  
  
  

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