| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PropagateEvaluationExceptionHandler |
|
| 2.4285714285714284;2.429 |
| 1 | /* | |
| 2 | * $Source: /usr/cvsroot/melati/melati/src/main/java/org/melati/template/webmacro/PropagateEvaluationExceptionHandler.java,v $ | |
| 3 | * $Revision: 1.4 $ | |
| 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 | 106 | public PropagateEvaluationExceptionHandler() { |
| 72 | 106 | } |
| 73 | ||
| 74 | /** | |
| 75 | * Constructor. | |
| 76 | * @param b the WebMacro broker | |
| 77 | */ | |
| 78 | 0 | public PropagateEvaluationExceptionHandler(Broker b) { |
| 79 | 0 | init(b, b.getSettings()); |
| 80 | 0 | } |
| 81 | ||
| 82 | /** | |
| 83 | * {@inheritDoc} | |
| 84 | * @see org.webmacro.engine.EvaluationExceptionHandler# | |
| 85 | * init(org.webmacro.Broker, org.webmacro.util.Settings) | |
| 86 | */ | |
| 87 | public void init(Broker b, Settings config) { | |
| 88 | 0 | } |
| 89 | ||
| 90 | /** | |
| 91 | * {@inheritDoc} | |
| 92 | * @see org.webmacro.engine.EvaluationExceptionHandler# | |
| 93 | * evaluate(org.webmacro.engine.Variable, | |
| 94 | * org.webmacro.Context, java.lang.Exception) | |
| 95 | */ | |
| 96 | public void evaluate(Variable variable, | |
| 97 | Context context, | |
| 98 | Exception problem) | |
| 99 | throws PropertyException { | |
| 100 | 2 | if (problem instanceof PropertyException.NoSuchVariableException |
| 101 | || problem instanceof PropertyException.NullValueException | |
| 102 | || problem instanceof PropertyException.NullToStringException) | |
| 103 | 0 | return; |
| 104 | 2 | if (problem instanceof PropertyException) |
| 105 | 2 | throw (PropertyException) problem; |
| 106 | else | |
| 107 | 0 | throw new PropertyException("Error evaluating variable " |
| 108 | + variable.getVariableName() + ": " | |
| 109 | + problem, problem); | |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * {@inheritDoc} | |
| 114 | * @see org.webmacro.engine.EvaluationExceptionHandler#expand( | |
| 115 | * org.webmacro.engine.Variable, org.webmacro.Context, java.lang.Exception) | |
| 116 | */ | |
| 117 | public String expand(Variable variable, | |
| 118 | Context context, | |
| 119 | Exception problem) | |
| 120 | throws PropertyException { | |
| 121 | 2 | if (problem instanceof PropertyException) |
| 122 | 2 | throw (PropertyException) problem; |
| 123 | else | |
| 124 | 0 | throw new PropertyException("Error evaluating variable " |
| 125 | + variable.getVariableName() + ": " | |
| 126 | + problem, problem); | |
| 127 | } | |
| 128 | ||
| 129 | ||
| 130 | /** | |
| 131 | * {@inheritDoc} | |
| 132 | * @see org.webmacro.engine.EvaluationExceptionHandler#warningString(java.lang.String) | |
| 133 | */ | |
| 134 | public String warningString(String warningText) throws PropertyException { | |
| 135 | 2 | throw new PropertyException("Evaluation warning: " + warningText); |
| 136 | } | |
| 137 | ||
| 138 | ||
| 139 | /** | |
| 140 | * {@inheritDoc} | |
| 141 | * @see org.webmacro.engine.EvaluationExceptionHandler#errorString(java.lang.String) | |
| 142 | */ | |
| 143 | public String errorString(String errorText) throws PropertyException { | |
| 144 | 0 | throw new PropertyException("Evaluation error: " + errorText); |
| 145 | } | |
| 146 | } | |
| 147 |