1 | package org.apache.velocity.runtime.directive; |
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.runtime.RuntimeServices; |
23 | |
24 | import org.apache.velocity.context.InternalContextAdapter; |
25 | import org.apache.velocity.runtime.parser.node.Node; |
26 | |
27 | import org.apache.velocity.exception.MethodInvocationException; |
28 | import org.apache.velocity.exception.ParseErrorException; |
29 | import org.apache.velocity.exception.ResourceNotFoundException; |
30 | |
31 | |
32 | /** |
33 | * Base class for all directives used in Velocity. |
34 | * |
35 | * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a> |
36 | * @version $Id: Directive.java,v 1.18.4.1 2004/03/03 23:22:55 geirm Exp $ |
37 | */ |
38 | public abstract class Directive implements DirectiveConstants, Cloneable |
39 | { |
40 | private int line = 0; |
41 | private int column = 0; |
42 | |
43 | protected RuntimeServices rsvc = null; |
44 | |
45 | /** Return the name of this directive */ |
46 | public abstract String getName(); |
47 | |
48 | /** Get the directive type BLOCK/LINE */ |
49 | public abstract int getType(); |
50 | |
51 | /** Allows the template location to be set */ |
52 | public void setLocation( int line, int column ) |
53 | { |
54 | this.line = line; |
55 | this.column = column; |
56 | } |
57 | |
58 | /** for log msg purposes */ |
59 | public int getLine() |
60 | { |
61 | return line; |
62 | } |
63 | |
64 | /** for log msg purposes */ |
65 | public int getColumn() |
66 | { |
67 | return column; |
68 | } |
69 | |
70 | /** |
71 | * How this directive is to be initialized. |
72 | */ |
73 | public void init( RuntimeServices rs, InternalContextAdapter context, |
74 | Node node) |
75 | throws Exception |
76 | { |
77 | rsvc = rs; |
78 | |
79 | // int i, k = node.jjtGetNumChildren(); |
80 | |
81 | //for (i = 0; i < k; i++) |
82 | // node.jjtGetChild(i).init(context, rs); |
83 | } |
84 | |
85 | /** |
86 | * How this directive is to be rendered |
87 | */ |
88 | public abstract boolean render( InternalContextAdapter context, |
89 | Writer writer, Node node ) |
90 | throws IOException, ResourceNotFoundException, ParseErrorException, |
91 | MethodInvocationException; |
92 | } |