1 package org.apache.velocity.runtime.directive;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.Writer;
23 import java.io.IOException;
24
25 import org.apache.velocity.runtime.RuntimeServices;
26
27 import org.apache.velocity.context.InternalContextAdapter;
28 import org.apache.velocity.runtime.parser.node.Node;
29
30 import org.apache.velocity.exception.MethodInvocationException;
31 import org.apache.velocity.exception.ParseErrorException;
32 import org.apache.velocity.exception.ResourceNotFoundException;
33 import org.apache.velocity.exception.TemplateInitException;
34
35
36 /**
37 * Base class for all directives used in Velocity.
38 *
39 * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
40 * @version $Id: Directive.java 471381 2006-11-05 08:56:58Z wglass $
41 */
42 public abstract class Directive implements DirectiveConstants, Cloneable
43 {
44 private int line = 0;
45 private int column = 0;
46
47 /**
48 *
49 */
50 protected RuntimeServices rsvc = null;
51
52 /**
53 * Return the name of this directive.
54 * @return The name of this directive.
55 */
56 public abstract String getName();
57
58 /**
59 * Get the directive type BLOCK/LINE.
60 * @return The directive type BLOCK/LINE.
61 */
62 public abstract int getType();
63
64 /**
65 * Allows the template location to be set.
66 * @param line
67 * @param column
68 */
69 public void setLocation( int line, int column )
70 {
71 this.line = line;
72 this.column = column;
73 }
74
75 /**
76 * for log msg purposes
77 * @return The current line for log msg purposes.
78 */
79 public int getLine()
80 {
81 return line;
82 }
83
84 /**
85 * for log msg purposes
86 * @return The current column for log msg purposes.
87 */
88 public int getColumn()
89 {
90 return column;
91 }
92
93 /**
94 * How this directive is to be initialized.
95 * @param rs
96 * @param context
97 * @param node
98 * @throws TemplateInitException
99 */
100 public void init( RuntimeServices rs, InternalContextAdapter context,
101 Node node)
102 throws TemplateInitException
103 {
104 rsvc = rs;
105
106 // int i, k = node.jjtGetNumChildren();
107
108 //for (i = 0; i < k; i++)
109 // node.jjtGetChild(i).init(context, rs);
110 }
111
112 /**
113 * How this directive is to be rendered
114 * @param context
115 * @param writer
116 * @param node
117 * @return True if the directive rendered successfully.
118 * @throws IOException
119 * @throws ResourceNotFoundException
120 * @throws ParseErrorException
121 * @throws MethodInvocationException
122 */
123 public abstract boolean render( InternalContextAdapter context,
124 Writer writer, Node node )
125 throws IOException, ResourceNotFoundException, ParseErrorException,
126 MethodInvocationException;
127 }