| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.commons.jelly.tags.core.WhileTag |
|
|
| 1 | /* |
|
| 2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
| 3 | * |
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 5 | * you may not use this file except in compliance with the License. |
|
| 6 | * You may obtain a copy of the License at |
|
| 7 | * |
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 9 | * |
|
| 10 | * Unless required by applicable law or agreed to in writing, software |
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 13 | * See the License for the specific language governing permissions and |
|
| 14 | * limitations under the License. |
|
| 15 | */ |
|
| 16 | ||
| 17 | package org.apache.commons.jelly.tags.core; |
|
| 18 | ||
| 19 | import org.apache.commons.jelly.JellyTagException; |
|
| 20 | import org.apache.commons.jelly.MissingAttributeException; |
|
| 21 | import org.apache.commons.jelly.TagSupport; |
|
| 22 | import org.apache.commons.jelly.XMLOutput; |
|
| 23 | import org.apache.commons.jelly.expression.Expression; |
|
| 24 | import org.apache.commons.jelly.impl.BreakException; |
|
| 25 | import org.apache.commons.logging.Log; |
|
| 26 | import org.apache.commons.logging.LogFactory; |
|
| 27 | ||
| 28 | /** |
|
| 29 | * A tag which performs an iteration while the result of an expression is true. |
|
| 30 | * |
|
| 31 | * @author <a href="mailto:eric@ericalexander.net">Eric Alexander</a> |
|
| 32 | * @author dIon Gillard |
|
| 33 | * @version $Revision: 155420 $ |
|
| 34 | */ |
|
| 35 | public class WhileTag extends TagSupport { |
|
| 36 | ||
| 37 | /** The Log to which logging calls will be made. */ |
|
| 38 | 546 | private static final Log log = LogFactory.getLog(WhileTag.class); |
| 39 | ||
| 40 | /** The expression to use to determine if the while should continue */ |
|
| 41 | private Expression test; |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Create a new while tag |
|
| 45 | */ |
|
| 46 | 26 | public WhileTag() { |
| 47 | 26 | } |
| 48 | ||
| 49 | /** |
|
| 50 | * Tag interface |
|
| 51 | * @param output destination for xml output |
|
| 52 | * @throws MissingAttributeException when the test attribute is missing |
|
| 53 | * @throws Exception for anything else |
|
| 54 | */ |
|
| 55 | public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { |
|
| 56 | 26 | if (test != null) { |
| 57 | try { |
|
| 58 | 78 | while (test.evaluateAsBoolean(getContext())) { |
| 59 | 78 | if (log.isDebugEnabled()) { |
| 60 | 0 | log.debug("evaluated to true! gonna keep on chuggin!"); |
| 61 | } |
|
| 62 | 78 | invokeBody(output); |
| 63 | 52 | } |
| 64 | } |
|
| 65 | 26 | catch (BreakException e) { |
| 66 | 26 | if (log.isDebugEnabled()) { |
| 67 | 0 | log.debug("loop terminated by break: " + e, e); |
| 68 | } |
|
| 69 | 0 | } |
| 70 | 26 | } |
| 71 | else { |
|
| 72 | 0 | throw new MissingAttributeException("test"); |
| 73 | } |
|
| 74 | 26 | } |
| 75 | ||
| 76 | // Properties |
|
| 77 | //------------------------------------------------------------------------- |
|
| 78 | ||
| 79 | /** |
|
| 80 | * Setter for the expression |
|
| 81 | * @param e the expression to test |
|
| 82 | */ |
|
| 83 | public void setTest(Expression e) { |
|
| 84 | 26 | this.test = e; |
| 85 | 26 | } |
| 86 | } |
|
| 87 |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |