##### Coverage Report - org.melati.template.webmacro.PropagateEvaluationExceptionHandler

Classes in this File | Line Coverage | Branch Coverage | Complexity
PropagateEvaluationExceptionHandler |
61% | 8/13
50% | 5/10
| 3.0;3

1 |  |
     /*
2 |  |
      * $Source: /usr/cvsroot/melati/melati/src/site/resources/withWebmacro/org.melati.template.webmacro.PropagateEvaluationExceptionHandler.html,v $
3 |  |
      * $Revision: 1.1 $
4 |  |
      *
5 |  |
      * Copyright (C) 2000 Tim Joyce
6 |  |
      *
7 |  |
      * Part of Melati (http://melati.org), a framework for the rapid
8 |  |
      * development of clean, maintainable web applications.
9 |  |
      *
10 |  |
      * Melati is free software; Permission is granted to copy, distribute
11 |  |
      * and/or modify this software under the terms either:
12 |  |
      *
13 |  |
      * a) the GNU General Public License as published by the Free Software
14 |  |
      *    Foundation; either version 2 of the License, or (at your option)
15 |  |
      *    any later version,
16 |  |
      *
17 |  |
      *    or
18 |  |
      *
19 |  |
      * b) any version of the Melati Software License, as published
20 |  |
      *    at http://melati.org
21 |  |
      *
22 |  |
      * You should have received a copy of the GNU General Public License and
23 |  |
      * the Melati Software License along with this program;
24 |  |
      * if not, write to the Free Software Foundation, Inc.,
25 |  |
      * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
26 |  |
      * GNU General Public License and visit http://melati.org to obtain the
27 |  |
      * Melati Software License.
28 |  |
      *
29 |  |
      * Feel free to contact the Developers of Melati (http://melati.org),
30 |  |
      * if you would like to work out a different arrangement than the options
31 |  |
      * outlined here.  It is our intention to allow Melati to be used by as
32 |  |
      * wide an audience as possible.
33 |  |
      *
34 |  |
      * This program is distributed in the hope that it will be useful,
35 |  |
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 |  |
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37 |  |
      * GNU General Public License for more details.
38 |  |
      *
39 |  |
      * Contact details for copyright holder:
40 |  |
      *
41 |  |
      *     Tim Joyce <timj At paneris.org>
42 |  |
      */
43 |  |
44 |  |
     package org.melati.template.webmacro;
45 |  |
46 |  |
     import org.webmacro.PropertyException;
47 |  |
     import org.webmacro.Context;
48 |  |
     import org.webmacro.Broker;
49 |  |
     import org.webmacro.engine.EvaluationExceptionHandler;
50 |  |
     import org.webmacro.engine.Variable;
51 |  |
     import org.webmacro.util.Settings;
52 |  |
53 |  |
     /**
54 |  |
      * An implementation of EvaluationExceptionHandler which throws an exception
55 |  |
      * whenever it is called.
56 |  |
      *
57 |  |
      * This will generally cause the exception to be
58 |  |
      * displayed to the user -- useful for debugging.
59 |  |
      *
60 |  |
      * Modified to allow #if ($null).
61 |  |
      *
62 |  |
      * @author Tim Joyce
63 |  |
      */
64 |  |
65 |  |
     public class PropagateEvaluationExceptionHandler
66 |  |
       implements EvaluationExceptionHandler {
67 |  |
68 |  |
        /**
69 |  |
        * Constructor.
70 |  |
        */
71 | 1939 |
       public PropagateEvaluationExceptionHandler() {
72 | 1939 |
        }
73 |  |
74 |  |
       /**
75 |  |
        * Forced upon us by the interface, but unused.
76 |  |
        *
77 |  |
        * {@inheritDoc}
78 |  |
        * @see org.webmacro.engine.EvaluationExceptionHandler#
79 |  |
        *        init(org.webmacro.Broker, org.webmacro.util.Settings)
80 |  |
        */
81 |  |
       public void init(Broker b, Settings config) {
82 | 0 |
        }
83 |  |
84 |  |
        /**
85 |  |
        * {@inheritDoc}
86 |  |
        * @see org.webmacro.engine.EvaluationExceptionHandler#
87 |  |
        *          evaluate(org.webmacro.engine.Variable,
88 |  |
        *                   org.webmacro.Context, java.lang.Exception)
89 |  |
        */
90 |  |
       public void evaluate(Variable variable,
91 |  |
                             Context context,
92 |  |
                             Exception problem)
93 |  |
        throws PropertyException {
94 | 16 |
          if (problem instanceof PropertyException.NoSuchVariableException
95 |  |
           || problem instanceof PropertyException.NullValueException
96 |  |
           || problem instanceof PropertyException.NullToStringException)
97 | 0 |
            return;
98 | 16 |
          if (problem instanceof PropertyException)
99 | 16 |
            throw (PropertyException) problem;
100 |  |
          else
101 | 0 |
            throw new PropertyException("Error evaluating variable "
102 |  |
                                        + variable.getVariableName() + ": "
103 |  |
                                        + problem, problem);
104 |  |
        }
105 |  |
106 |  |
        /**
107 |  |
        * {@inheritDoc}
108 |  |
        * @see org.webmacro.engine.EvaluationExceptionHandler#expand(
109 |  |
        *          org.webmacro.engine.Variable, org.webmacro.Context, java.lang.Exception)
110 |  |
        */
111 |  |
       public String expand(Variable variable,
112 |  |
                             Context context,
113 |  |
                             Exception problem)
114 |  |
        throws PropertyException {
115 | 16 |
          if (problem instanceof PropertyException)
116 | 16 |
            throw (PropertyException) problem;
117 |  |
          else
118 | 0 |
            throw new PropertyException("Error evaluating variable "
119 |  |
                                        + variable.getVariableName() + ": "
120 |  |
                                        + problem, problem);
121 |  |
        }
122 |  |
123 |  |
124 |  |
        /**
125 |  |
        * {@inheritDoc}
126 |  |
        * @see org.webmacro.engine.EvaluationExceptionHandler#warningString(java.lang.String)
127 |  |
        */
128 |  |
       public String warningString(String warningText) throws PropertyException {
129 | 4 |
           throw new PropertyException("Evaluation warning: " + warningText);
130 |  |
        }
131 |  |
132 |  |
133 |  |
        /**
134 |  |
        * {@inheritDoc}
135 |  |
        *
136 |  |
        * I do not believe that this can be exercised, without a bug in webmacro.
137 |  |
        * @see org.webmacro.engine.EvaluationExceptionHandler#errorString(java.lang.String)
138 |  |
        */
139 |  |
       public String errorString(String errorText) throws PropertyException {
140 | 0 |
           throw new PropertyException("Evaluation error: " + errorText);
141 |  |
        }
142 |  |
     }
143 |  |