Coverage details for org.chwf.taglib.jutil.PrintErrorTag

LineHitsSource
1 /*
2 Chrysalis Web Framework [http://chrysalis.sourceforge.net]
3 Copyright (c) 2002, 2003, 2004, Paul Strack
4  
5 All rights reserved.
6  
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9  
10 1. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12  
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16  
17 3. Neither the name of the copyright holder nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20  
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32  
33 package org.chwf.taglib.jutil;
34  
35 import java.io.IOException;
36  
37 import javax.servlet.http.HttpServletRequest;
38  
39 import org.chwf.servlet.MultiParameterException;
40 import org.chwf.servlet.ServletUtils;
41 import org.chwf.taglib.base.LifeCycleTagSupport;
42  
43 /**
44  * Tag handler for the <code>&lt;printError&gt;</code> tag. It checks for an
45  * exception object in the request and prints its message.
46  *
47  * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a>
48  */
496public class PrintErrorTag extends LifeCycleTagSupport {
50  
51   /** For parameter-associated errors. */
52   private String parameter;
53  
54   /**
55    * Clean up data for tag handler reuse and pooling. Should be overridden in
56    * tag handler. Subclasses should always invoke their superclass's cleanup
57    * method: <code>super.cleanup()</code>
58    */
59   public void cleanup() {
601    super.cleanup();
611    this.parameter = null;
621  }
63  
64   /**
65    * For parameter-associated errors.
66    *
67    * @param parameter The parameter.
68    */
69   public void setParameter(String parameter) {
703    this.parameter = parameter;
713  }
72  
73   /**
74    * For parameter-associated errors.
75    *
76    * @return The parameter.
77    */
78   public String getParameter() {
795    return parameter;
80   }
81  
82   /**
83    * Prints the error message.
84    * @return SKIP_BODY
85    * @throws IOException For IO exceptions.
86    */
87   public int doStart() throws IOException {
883    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
893    Throwable error = ServletUtils.retrieveError(request);
903    if (error != null) {
913      if (getParameter() != null) {
922        if (error instanceof MultiParameterException) {
931          MultiParameterException mpe = (MultiParameterException) error;
941          String message = mpe.getMessage(getParameter());
951          if (message != null) {
961            pageContext.getOut().print(message);
97           }
98         }
99       } else {
1001        pageContext.getOut().print(error.getMessage());
101       }
102     }
1033    return SKIP_BODY;
104   }
105 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.