| 1 | package org.apache.velocity.runtime.parser.node; |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2000-2001,2004 The Apache Software Foundation. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | import java.io.Writer; |
| 20 | import java.io.IOException; |
| 21 | |
| 22 | import org.apache.velocity.context.InternalContextAdapter; |
| 23 | import org.apache.velocity.runtime.parser.*; |
| 24 | |
| 25 | import org.apache.velocity.exception.MethodInvocationException; |
| 26 | import org.apache.velocity.exception.ParseErrorException; |
| 27 | import org.apache.velocity.exception.ResourceNotFoundException; |
| 28 | |
| 29 | /** |
| 30 | * This class is responsible for handling the ElseIf VTL control statement. |
| 31 | * |
| 32 | * Please look at the Parser.jjt file which is |
| 33 | * what controls the generation of this class. |
| 34 | * |
| 35 | * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a> |
| 36 | * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a> |
| 37 | * @version $Id: ASTElseIfStatement.java,v 1.9.8.1 2004/03/03 23:22:58 geirm Exp $ |
| 38 | */ |
| 39 | public class ASTElseIfStatement extends SimpleNode |
| 40 | { |
| 41 | public ASTElseIfStatement(int id) |
| 42 | { |
| 43 | super(id); |
| 44 | } |
| 45 | |
| 46 | public ASTElseIfStatement(Parser p, int id) |
| 47 | { |
| 48 | super(p, id); |
| 49 | } |
| 50 | |
| 51 | /** Accept the visitor. **/ |
| 52 | public Object jjtAccept(ParserVisitor visitor, Object data) |
| 53 | { |
| 54 | return visitor.visit(this, data); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * An ASTElseStatement is true if the expression |
| 59 | * it contains evaluates to true. Expressions know |
| 60 | * how to evaluate themselves, so we do that |
| 61 | * here and return the value back to ASTIfStatement |
| 62 | * where this node was originally asked to evaluate |
| 63 | * itself. |
| 64 | */ |
| 65 | public boolean evaluate ( InternalContextAdapter context) |
| 66 | throws MethodInvocationException |
| 67 | { |
| 68 | return jjtGetChild(0).evaluate(context); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * renders the block |
| 73 | */ |
| 74 | public boolean render( InternalContextAdapter context, Writer writer) |
| 75 | throws IOException,MethodInvocationException, |
| 76 | ResourceNotFoundException, ParseErrorException |
| 77 | { |
| 78 | return jjtGetChild(1).render( context, writer ); |
| 79 | } |
| 80 | } |