001: package org.apache.velocity.runtime.directive;
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.Writer;
023: import java.io.IOException;
024:
025: import org.apache.velocity.runtime.RuntimeServices;
026:
027: import org.apache.velocity.context.InternalContextAdapter;
028: import org.apache.velocity.runtime.parser.node.Node;
029:
030: import org.apache.velocity.exception.MethodInvocationException;
031: import org.apache.velocity.exception.ParseErrorException;
032: import org.apache.velocity.exception.ResourceNotFoundException;
033: import org.apache.velocity.exception.TemplateInitException;
034:
035: /**
036: * Base class for all directives used in Velocity.
037: *
038: * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
039: * @version $Id: Directive.java 471381 2006-11-05 08:56:58Z wglass $
040: */
041: public abstract class Directive implements DirectiveConstants,
042: Cloneable {
043: private int line = 0;
044: private int column = 0;
045:
046: /**
047: *
048: */
049: protected RuntimeServices rsvc = null;
050:
051: /**
052: * Return the name of this directive.
053: * @return The name of this directive.
054: */
055: public abstract String getName();
056:
057: /**
058: * Get the directive type BLOCK/LINE.
059: * @return The directive type BLOCK/LINE.
060: */
061: public abstract int getType();
062:
063: /**
064: * Allows the template location to be set.
065: * @param line
066: * @param column
067: */
068: public void setLocation(int line, int column) {
069: this .line = line;
070: this .column = column;
071: }
072:
073: /**
074: * for log msg purposes
075: * @return The current line for log msg purposes.
076: */
077: public int getLine() {
078: return line;
079: }
080:
081: /**
082: * for log msg purposes
083: * @return The current column for log msg purposes.
084: */
085: public int getColumn() {
086: return column;
087: }
088:
089: /**
090: * How this directive is to be initialized.
091: * @param rs
092: * @param context
093: * @param node
094: * @throws TemplateInitException
095: */
096: public void init(RuntimeServices rs,
097: InternalContextAdapter context, Node node)
098: throws TemplateInitException {
099: rsvc = rs;
100:
101: // int i, k = node.jjtGetNumChildren();
102:
103: //for (i = 0; i < k; i++)
104: // node.jjtGetChild(i).init(context, rs);
105: }
106:
107: /**
108: * How this directive is to be rendered
109: * @param context
110: * @param writer
111: * @param node
112: * @return True if the directive rendered successfully.
113: * @throws IOException
114: * @throws ResourceNotFoundException
115: * @throws ParseErrorException
116: * @throws MethodInvocationException
117: */
118: public abstract boolean render(InternalContextAdapter context,
119: Writer writer, Node node) throws IOException,
120: ResourceNotFoundException, ParseErrorException,
121: MethodInvocationException;
122: }
|