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 724825 2008-12-09 18:56:06Z nbubna $ 41 */ 42 public abstract class Directive implements DirectiveConstants, Cloneable 43 { 44 private int line = 0; 45 private int column = 0; 46 private String templateName; 47 48 /** 49 * 50 */ 51 protected RuntimeServices rsvc = null; 52 53 /** 54 * Return the name of this directive. 55 * @return The name of this directive. 56 */ 57 public abstract String getName(); 58 59 /** 60 * Get the directive type BLOCK/LINE. 61 * @return The directive type BLOCK/LINE. 62 */ 63 public abstract int getType(); 64 65 /** 66 * Allows the template location to be set. 67 * @param line 68 * @param column 69 */ 70 public void setLocation( int line, int column ) 71 { 72 this.line = line; 73 this.column = column; 74 } 75 76 /** 77 * Allows the template location to be set. 78 * @param line 79 * @param column 80 */ 81 public void setLocation(int line, int column, String templateName) 82 { 83 setLocation(line, column); 84 this.templateName = templateName; 85 } 86 87 /** 88 * for log msg purposes 89 * @return The current line for log msg purposes. 90 */ 91 public int getLine() 92 { 93 return line; 94 } 95 96 /** 97 * for log msg purposes 98 * @return The current column for log msg purposes. 99 */ 100 public int getColumn() 101 { 102 return column; 103 } 104 105 /** 106 * @return The template file name this directive was defined in, or null if not 107 * defined in a file. 108 */ 109 public String getTemplateName() 110 { 111 return templateName; 112 } 113 114 /** 115 * How this directive is to be initialized. 116 * @param rs 117 * @param context 118 * @param node 119 * @throws TemplateInitException 120 */ 121 public void init( RuntimeServices rs, InternalContextAdapter context, 122 Node node) 123 throws TemplateInitException 124 { 125 rsvc = rs; 126 127 // int i, k = node.jjtGetNumChildren(); 128 129 //for (i = 0; i < k; i++) 130 // node.jjtGetChild(i).init(context, rs); 131 } 132 133 /** 134 * How this directive is to be rendered 135 * @param context 136 * @param writer 137 * @param node 138 * @return True if the directive rendered successfully. 139 * @throws IOException 140 * @throws ResourceNotFoundException 141 * @throws ParseErrorException 142 * @throws MethodInvocationException 143 */ 144 public abstract boolean render( InternalContextAdapter context, 145 Writer writer, Node node ) 146 throws IOException, ResourceNotFoundException, ParseErrorException, 147 MethodInvocationException; 148 }