001: package org.apache.velocity.runtime.parser.node;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.io.IOException;
023: import java.io.Writer;
024:
025: import org.apache.velocity.context.InternalContextAdapter;
026: import org.apache.velocity.exception.MethodInvocationException;
027: import org.apache.velocity.exception.ParseErrorException;
028: import org.apache.velocity.exception.ResourceNotFoundException;
029: import org.apache.velocity.runtime.parser.Parser;
030: import org.apache.velocity.runtime.parser.ParserVisitor;
031: import org.apache.velocity.runtime.parser.Token;
032:
033: /**
034: * Represents all comments...
035: *
036: * @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
037: * @version $Id: ASTComment.java 471381 2006-11-05 08:56:58Z wglass $
038: */
039: public class ASTComment extends SimpleNode {
040: private static final char[] ZILCH = "".toCharArray();
041:
042: private char[] carr;
043:
044: /**
045: * @param id
046: */
047: public ASTComment(int id) {
048: super (id);
049: }
050:
051: /**
052: * @param p
053: * @param id
054: */
055: public ASTComment(Parser p, int id) {
056: super (p, id);
057: }
058:
059: /**
060: * @see org.apache.velocity.runtime.parser.node.SimpleNode#jjtAccept(org.apache.velocity.runtime.parser.ParserVisitor, java.lang.Object)
061: */
062: public Object jjtAccept(ParserVisitor visitor, Object data) {
063: return visitor.visit(this , data);
064: }
065:
066: /**
067: * We need to make sure we catch any of the dreaded MORE tokens.
068: * @param context
069: * @param data
070: * @return The data object.
071: */
072: public Object init(InternalContextAdapter context, Object data) {
073: Token t = getFirstToken();
074:
075: int loc1 = t.image.indexOf("##");
076: int loc2 = t.image.indexOf("#*");
077:
078: if (loc1 == -1 && loc2 == -1) {
079: carr = ZILCH;
080: } else {
081: carr = t.image.substring(0, (loc1 == -1) ? loc2 : loc1)
082: .toCharArray();
083: }
084:
085: return data;
086: }
087:
088: /**
089: * @see org.apache.velocity.runtime.parser.node.SimpleNode#render(org.apache.velocity.context.InternalContextAdapter, java.io.Writer)
090: */
091: public boolean render(InternalContextAdapter context, Writer writer)
092: throws IOException, MethodInvocationException,
093: ParseErrorException, ResourceNotFoundException {
094:
095: if (context.getAllowRendering()) {
096: writer.write(carr);
097: }
098:
099: return true;
100: }
101:
102: }
|