1 package org.apache.velocity.runtime.parser.node; 2 3 18 19 import java.io.IOException ; 20 import java.io.Writer ; 21 22 import org.apache.velocity.context.InternalContextAdapter; 23 import org.apache.velocity.runtime.RuntimeConstants; 24 import org.apache.velocity.runtime.parser.Parser; 25 26 import org.apache.velocity.exception.MethodInvocationException; 27 28 import org.apache.velocity.app.event.EventCartridge; 29 30 37 public class ASTSetDirective extends SimpleNode 38 { 39 private String leftReference = ""; 40 private Node right; 41 private ASTReference left; 42 boolean blather = false; 43 44 public ASTSetDirective(int id) 45 { 46 super(id); 47 } 48 49 public ASTSetDirective(Parser p, int id) 50 { 51 super(p, id); 52 } 53 54 55 public Object jjtAccept(ParserVisitor visitor, Object data) 56 { 57 return visitor.visit(this, data); 58 } 59 60 63 public Object init(InternalContextAdapter context, Object data) 64 throws Exception 65 { 66 69 70 super.init( context, data ); 71 72 right = getRightHandSide(); 73 left = getLeftHandSide(); 74 75 blather = rsvc.getBoolean(RuntimeConstants.RUNTIME_LOG_REFERENCE_LOG_INVALID, true); 76 77 80 leftReference = left.getFirstToken().image.substring(1); 81 82 return data; 83 } 84 85 88 public boolean render( InternalContextAdapter context, Writer writer) 89 throws IOException , MethodInvocationException 90 { 91 94 95 Object value = right.value(context); 96 97 100 101 if ( value == null) 102 { 103 106 if(blather) 107 { 108 EventCartridge ec = context.getEventCartridge(); 109 110 boolean doit = true; 111 112 115 if (ec != null) 116 { 117 doit = ec.shouldLogOnNullSet( left.literal(), right.literal() ); 118 } 119 120 if (doit) 121 { 122 rsvc.error("RHS of #set statement is null. Context will not be modified. " 123 + context.getCurrentTemplateName() + " [line " + getLine() 124 + ", column " + getColumn() + "]"); 125 } 126 } 127 128 return false; 129 } 130 131 136 137 if (left.jjtGetNumChildren() == 0) 138 { 139 context.put( leftReference, value); 140 } 141 else 142 { 143 left.setValue(context, value); 144 } 145 146 return true; 147 } 148 149 152 private ASTReference getLeftHandSide() 153 { 154 return (ASTReference) jjtGetChild(0); 155 156 } 158 159 162 private Node getRightHandSide() 163 { 164 return jjtGetChild(1); 165 } 167 } 168 | Popular Tags |