craigmcc    01/04/28 20:59:05

  Modified:    src/share/org/apache/struts/taglib/template GetTag.java
                        InsertTag.java
  Log:
  If <template:get> or <template:insert> throw an exception, do not override
  a nested exception already created by an included JSP page if it already
  exists at the standard Action.EXCEPTION_KEY request attribute key.
  
  PR: Bugzilla #1324
  Submitted by: Dmitri Plotnikov <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.8       +24 -8     
jakarta-struts/src/share/org/apache/struts/taglib/template/GetTag.java
  
  Index: GetTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/template/GetTag.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- GetTag.java       2001/02/26 16:44:16     1.7
  +++ GetTag.java       2001/04/29 03:59:04     1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/template/GetTag.java,v 1.7 
2001/02/26 16:44:16 dgeary Exp $
  - * $Revision: 1.7 $
  - * $Date: 2001/02/26 16:44:16 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/template/GetTag.java,v 1.8 
2001/04/29 03:59:04 craigmcc Exp $
  + * $Revision: 1.8 $
  + * $Date: 2001/04/29 03:59:04 $
    *
    * ====================================================================
    *
  @@ -75,7 +75,7 @@
    * it, depending upon the value of the content's direct attribute.
    *
    * @author David Geary
  - * @version $Revision: 1.7 $ $Date: 2001/02/26 16:44:16 $
  + * @version $Revision: 1.8 $ $Date: 2001/04/29 03:59:04 $
    */
   public class GetTag extends TagSupport {
   
  @@ -152,8 +152,7 @@
                  pageContext.getOut().print(content.toString());
               }
               catch(java.io.IOException ex) {
  -               pageContext.setAttribute(Action.EXCEPTION_KEY, ex,
  -                                        PageContext.REQUEST_SCOPE);
  +               saveException(ex);
                  throw new JspException(ex.getMessage());
               }
            }
  @@ -162,8 +161,7 @@
                  pageContext.include(content.toString());
               }
               catch(Exception ex) { 
  -               pageContext.setAttribute(Action.EXCEPTION_KEY, ex,
  -                                        PageContext.REQUEST_SCOPE);
  +               saveException(ex);
                  throw new JspException(ex.getMessage());
               }
            }
  @@ -183,5 +181,23 @@
         name = role = null;
   
      }
  +
  +
  +    /**
  +     * Save the specified exception in request scope if there is not already
  +     * one present.
  +     *
  +     * @param exception Exception to be conditionally saved
  +     */
  +    private void saveException(Throwable exception) {
  +
  +        if (pageContext.getAttribute(Action.EXCEPTION_KEY,
  +                                     PageContext.REQUEST_SCOPE) != null)
  +            return;
  +        pageContext.setAttribute(Action.EXCEPTION_KEY, exception,
  +                                 PageContext.REQUEST_SCOPE);
  +
  +    }
  +
   
   }
  
  
  
  1.7       +23 -6     
jakarta-struts/src/share/org/apache/struts/taglib/template/InsertTag.java
  
  Index: InsertTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/template/InsertTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- InsertTag.java    2001/02/26 16:44:16     1.6
  +++ InsertTag.java    2001/04/29 03:59:05     1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/template/InsertTag.java,v 
1.6 2001/02/26 16:44:16 dgeary Exp $
  - * $Revision: 1.6 $
  - * $Date: 2001/02/26 16:44:16 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/template/InsertTag.java,v 
1.7 2001/04/29 03:59:05 craigmcc Exp $
  + * $Revision: 1.7 $
  + * $Date: 2001/04/29 03:59:05 $
    *
    * ====================================================================
    *
  @@ -74,7 +74,7 @@
    * tags, which are accessed by &lt;template:get&gt; in the template.
    *
    * @author David Geary
  - * @version $Revision: 1.6 $ $Date: 2001/02/26 16:44:16 $
  + * @version $Revision: 1.7 $ $Date: 2001/04/29 03:59:05 $
    */
   public class InsertTag extends TagSupport {
   
  @@ -145,8 +145,7 @@
            pageContext.include(template);
         }
         catch(Exception ex) { // IOException or ServletException
  -         pageContext.setAttribute(Action.EXCEPTION_KEY, ex,
  -                                  PageContext.REQUEST_SCOPE);
  +         saveException(ex);
            throw new JspException(ex.getMessage());
         }
         ContentMapStack.pop(pageContext);
  @@ -177,5 +176,23 @@
         map = null;
   
      }
  +
  +
  +    /**
  +     * Save the specified exception in request scope if there is not already
  +     * one present.
  +     *
  +     * @param exception Exception to be conditionally saved
  +     */
  +    private void saveException(Throwable exception) {
  +
  +        if (pageContext.getAttribute(Action.EXCEPTION_KEY,
  +                                     PageContext.REQUEST_SCOPE) != null)
  +            return;
  +        pageContext.setAttribute(Action.EXCEPTION_KEY, exception,
  +                                 PageContext.REQUEST_SCOPE);
  +
  +    }
  +
   
   }
  
  
  

Reply via email to