| 1 | package org.apache.velocity.runtime.parser.node; |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2000-2002,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 org.apache.velocity.runtime.parser.Parser; |
| 20 | import org.apache.velocity.runtime.parser.Token; |
| 21 | import org.apache.velocity.context.InternalContextAdapter; |
| 22 | import org.apache.velocity.exception.ResourceNotFoundException; |
| 23 | import org.apache.velocity.exception.ParseErrorException; |
| 24 | import org.apache.velocity.exception.MethodInvocationException; |
| 25 | |
| 26 | import java.io.IOException; |
| 27 | import java.io.Writer; |
| 28 | |
| 29 | /** |
| 30 | * Represents all comments... |
| 31 | * |
| 32 | * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a> |
| 33 | * @version $Id: ASTComment.java,v 1.5.4.1 2004/03/03 23:22:58 geirm Exp $ |
| 34 | */ |
| 35 | public class ASTComment extends SimpleNode |
| 36 | { |
| 37 | private static final char[] ZILCH = "".toCharArray(); |
| 38 | |
| 39 | private char[] carr; |
| 40 | |
| 41 | public ASTComment(int id) |
| 42 | { |
| 43 | super(id); |
| 44 | } |
| 45 | |
| 46 | public ASTComment(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 | * We need to make sure we catch any of the dreaded MORE tokens. |
| 59 | */ |
| 60 | public Object init(InternalContextAdapter context, Object data) |
| 61 | throws Exception |
| 62 | { |
| 63 | Token t = getFirstToken(); |
| 64 | |
| 65 | int loc1 = t.image.indexOf("##"); |
| 66 | int loc2 = t.image.indexOf("#*"); |
| 67 | |
| 68 | if (loc1 == -1 && loc2 == -1) |
| 69 | { |
| 70 | carr = ZILCH; |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | carr = t.image.substring(0, (loc1 == -1) ? loc2 : loc1).toCharArray(); |
| 75 | } |
| 76 | |
| 77 | return data; |
| 78 | } |
| 79 | |
| 80 | public boolean render( InternalContextAdapter context, Writer writer) |
| 81 | throws IOException, MethodInvocationException, ParseErrorException, ResourceNotFoundException |
| 82 | { |
| 83 | writer.write(carr); |
| 84 | |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | } |