1 package org.apache.velocity.runtime.parser.node; 2 3 18 19 import java.io.Writer ; 20 import java.io.IOException ; 21 22 import org.apache.velocity.context.InternalContextAdapter; 23 import org.apache.velocity.runtime.directive.Directive; 24 import org.apache.velocity.runtime.parser.Parser; 25 26 import org.apache.velocity.exception.MethodInvocationException; 27 import org.apache.velocity.exception.ParseErrorException; 28 import org.apache.velocity.exception.ResourceNotFoundException; 29 30 42 public class ASTDirective extends SimpleNode 43 { 44 private Directive directive; 45 private String directiveName = ""; 46 private boolean isDirective; 47 48 public ASTDirective(int id) 49 { 50 super(id); 51 } 52 53 public ASTDirective(Parser p, int id) 54 { 55 super(p, id); 56 } 57 58 59 60 public Object jjtAccept(ParserVisitor visitor, Object data) 61 { 62 return visitor.visit(this, data); 63 } 64 65 public Object init( InternalContextAdapter context, Object data) 66 throws Exception 67 { 68 super.init( context, data ); 69 70 73 74 if (parser.isDirective( directiveName )) 75 { 76 isDirective = true; 77 78 directive = (Directive) parser.getDirective( directiveName ) 79 .getClass().newInstance(); 80 81 directive.init(rsvc, context,this); 82 83 directive.setLocation( getLine(), getColumn() ); 84 } 85 else if (rsvc.isVelocimacro( directiveName, context.getCurrentTemplateName() )) 86 { 87 90 91 isDirective = true; 92 directive = (Directive) rsvc.getVelocimacro( directiveName, context.getCurrentTemplateName() ); 93 94 directive.init( rsvc, context, this ); 95 directive.setLocation( getLine(), getColumn() ); 96 } 97 else 98 { 99 isDirective = false; 100 } 101 102 return data; 103 } 104 105 public boolean render( InternalContextAdapter context, Writer writer) 106 throws IOException ,MethodInvocationException, ResourceNotFoundException, ParseErrorException 107 { 108 111 112 if (isDirective) 113 { 114 directive.render(context, writer, this); 115 } 116 else 117 { 118 writer.write( "#"); 119 writer.write( directiveName ); 120 } 121 122 return true; 123 } 124 125 129 public void setDirectiveName( String str ) 130 { 131 directiveName = str; 132 return; 133 } 134 135 138 public String getDirectiveName() 139 { 140 return directiveName; 141 } 142 } 143 144 145 | Popular Tags |