jvanzyl 00/10/20 12:14:06
Added: src/java/org/apache/velocity/runtime/parser/node
ASTAddNode.java ASTAndNode.java ASTAssignment.java
ASTBlock.java ASTComment.java ASTDirective.java
ASTDivNode.java ASTEQNode.java
ASTElseIfStatement.java ASTElseStatement.java
ASTExpression.java ASTFalse.java ASTGENode.java
ASTGTNode.java ASTIdentifier.java
ASTIfStatement.java ASTIncludeStatement.java
ASTLENode.java ASTLTNode.java ASTMethod.java
ASTModNode.java ASTMulNode.java ASTNENode.java
ASTNotNode.java ASTNumberLiteral.java
ASTObjectArray.java ASTOrNode.java
ASTParameters.java ASTReference.java
ASTSetDirective.java ASTStringLiteral.java
ASTSubtractNode.java ASTText.java ASTTrue.java
ASTVariable.java ASTWord.java ASTprocess.java
AbstractExecutor.java MapExecutor.java Node.java
NodeUtils.java PropertyExecutor.java
SimpleNode.java
Log:
- moving node structure into a separate package now that it
is pretty much final.
Revision Changes Path
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTAddNode.java
Index: ASTAddNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTAddNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTAddNode extends SimpleNode
{
public ASTAddNode(int id)
{
super(id);
}
public ASTAddNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object value(Context context)
{
return new Integer(((Integer) jjtGetChild(0).value(context)).intValue() +
((Integer) jjtGetChild(1).value(context)).intValue());
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java
Index: ASTAndNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTAndNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTAndNode extends SimpleNode
{
public ASTAndNode(int id)
{
super(id);
}
public ASTAndNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
if (jjtGetChild(0).evaluate(context) &&
jjtGetChild(1).evaluate(context))
return true;
else
return false;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTAssignment.java
Index: ASTAssignment.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTAssignment.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTAssignment extends SimpleNode
{
public ASTAssignment(int id)
{
super(id);
}
public ASTAssignment(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTBlock.java
Index: ASTBlock.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTBlock.java */
package org.apache.velocity.runtime.parser.node;
import java.io.Writer;
import java.io.IOException;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTBlock extends SimpleNode
{
public ASTBlock(int id)
{
super(id);
}
public ASTBlock(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public void render(Context context, Writer writer)
throws IOException
{
int i, k = jjtGetNumChildren();
for (i = 0; i < k; i++)
jjtGetChild(i).render(context, writer);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTComment.java
Index: ASTComment.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTComment.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTComment extends SimpleNode {
public ASTComment(int id) {
super(id);
}
public ASTComment(Parser p, int id) {
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
Index: ASTDirective.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTDirective.java */
package org.apache.velocity.runtime.parser.node;
import java.io.Writer;
import java.io.IOException;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.directive.Directive;
import org.apache.velocity.runtime.parser.*;
public class ASTDirective extends SimpleNode
{
private Directive directive;
private String directiveName;
private boolean isDirective;
public ASTDirective(int id)
{
super(id);
}
public ASTDirective(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object init(Context context, Object data) throws Exception
{
directiveName = getFirstToken().image.substring(1);
if (parser.isDirective(directiveName))
{
isDirective = true;
directive = parser.getDirective(directiveName);
directive.init(context,this);
}
else
{
isDirective = false;
}
return data;
}
public void render(Context context, Writer writer)
throws IOException
{
if (isDirective)
directive.render(context, writer, this);
else
writer.write(directiveName);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTDivNode.java
Index: ASTDivNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTDivNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTDivNode extends SimpleNode
{
public ASTDivNode(int id)
{
super(id);
}
public ASTDivNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object value(Context context)
{
return new Integer(((Integer) jjtGetChild(0).value(context)).intValue() /
((Integer) jjtGetChild(1).value(context)).intValue());
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTEQNode.java
Index: ASTEQNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTEQNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTEQNode extends SimpleNode
{
public ASTEQNode(int id)
{
super(id);
}
public ASTEQNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
if (jjtGetChild(0).value(context) instanceof Boolean &&
((Boolean)jjtGetChild(0).value(context)).booleanValue() ==
((Boolean)jjtGetChild(1).value(context)).booleanValue())
return true;
else if (jjtGetChild(0).value(context) instanceof Integer &&
((Integer)jjtGetChild(0).value(context)).intValue() ==
((Integer)jjtGetChild(1).value(context)).intValue())
return true;
else if (jjtGetChild(0).value(context) instanceof String &&
jjtGetChild(0).value(context).toString()
.equals(jjtGetChild(1).value(context).toString()))
return true;
else
return false;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java
Index: ASTElseIfStatement.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTElseIfStatement.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTElseIfStatement extends SimpleNode
{
public ASTElseIfStatement(int id)
{
super(id);
}
public ASTElseIfStatement(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTElseStatement.java
Index: ASTElseStatement.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTElseStatement.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTElseStatement extends SimpleNode
{
public ASTElseStatement(int id)
{
super(id);
}
public ASTElseStatement(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTExpression.java
Index: ASTExpression.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTExpression.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTExpression extends SimpleNode
{
public ASTExpression(int id)
{
super(id);
}
public ASTExpression(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
return jjtGetChild(0).evaluate(context);
}
public Object value(Context context)
{
return jjtGetChild(0).value(context);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTFalse.java
Index: ASTFalse.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTFalse.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTFalse extends SimpleNode
{
public ASTFalse(int id)
{
super(id);
}
public ASTFalse(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
return false;
}
public Object value(Context context)
{
return new Boolean(false);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGENode.java
Index: ASTGENode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTGENode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTGENode extends SimpleNode
{
public ASTGENode(int id)
{
super(id);
}
public ASTGENode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
if (((Integer)jjtGetChild(0).value(context)).intValue() >=
((Integer)jjtGetChild(1).value(context)).intValue())
return true;
else
return false;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTGTNode.java
Index: ASTGTNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTGTNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTGTNode extends SimpleNode
{
public ASTGTNode(int id)
{
super(id);
}
public ASTGTNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
if (((Integer)jjtGetChild(0).value(context)).intValue() >
((Integer)jjtGetChild(1).value(context)).intValue())
return true;
else
return false;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
Index: ASTIdentifier.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTIdentifier.java */
package org.apache.velocity.runtime.parser.node;
import java.util.Map;
import java.lang.reflect.Method;
import org.apache.velocity.Context;
import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.runtime.parser.*;
public class ASTIdentifier extends SimpleNode
{
private AbstractExecutor executor;
public ASTIdentifier(int id)
{
super(id);
}
public ASTIdentifier(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object init(Context context, Object data)
throws Exception
{
String identifier = getFirstToken().image;
String method = "get" + identifier;
//! Now there might just be an error here.
// If there is a typo in the property
// then a MapExecutor is created and
// this needs to be prevented.
try
{
executor = new PropertyExecutor();
Method m = ((Class)data).getMethod(method,null);
executor.setData(m);
return m.getReturnType();
}
catch (NoSuchMethodException nsme)
{
executor = new MapExecutor();
executor.setData(identifier);
return Object.class;
}
}
public Object execute(Object o, Context context)
{
return executor.execute(o, context);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java
Index: ASTIfStatement.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTIfStatement.java */
package org.apache.velocity.runtime.parser.node;
import java.io.Writer;
import java.io.IOException;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTIfStatement extends SimpleNode
{
public ASTIfStatement(int id)
{
super(id);
}
public ASTIfStatement(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public void render(Context context, Writer writer)
throws IOException
{
Object data = null;
Node expression;
// Only process the child nodes if the expression
// evaluates to true. But we also need to look for
// the presence of an else block and process that
// if the expression doesn't evaluate to true.
//if (evaluateExpression(expression))
expression = jjtGetChild(0);
if (expression.evaluate(context))
{
jjtGetChild(1).render(context, writer);
}
else
{
/* The condition for the if statement above evaluated
* to false so now we walk through the child nodes
* looking for elseif/else children.
*/
int children = jjtGetNumChildren();
for (int i = 2; i < children; i++)
{
Node child = jjtGetChild(i);
if (child.getType() == ParserTreeConstants.JJTELSEIFSTATEMENT)
{
expression = child.jjtGetChild(0);
if (expression.evaluate(context))
{
child.jjtGetChild(1).render(context, writer);
break;
}
}
else
child.jjtGetChild(0).render(context, writer);
}
}
}
public void process(Context context, ParserVisitor visitor)
{
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTIncludeStatement.java
Index: ASTIncludeStatement.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTIncludeStatement.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTIncludeStatement extends SimpleNode
{
public ASTIncludeStatement(int id)
{
super(id);
}
public ASTIncludeStatement(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTLENode.java
Index: ASTLENode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTLENode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTLENode extends SimpleNode
{
public ASTLENode(int id)
{
super(id);
}
public ASTLENode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
if (((Integer)jjtGetChild(0).value(context)).intValue() <=
((Integer)jjtGetChild(1).value(context)).intValue())
return true;
else
return false;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTLTNode.java
Index: ASTLTNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTLTNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTLTNode extends SimpleNode
{
public ASTLTNode(int id)
{
super(id);
}
public ASTLTNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
if (((Integer)jjtGetChild(0).value(context)).intValue() <
((Integer)jjtGetChild(1).value(context)).intValue())
return true;
else
return false;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
Index: ASTMethod.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTMethod.java */
package org.apache.velocity.runtime.parser.node;
import java.lang.reflect.Method;
import org.apache.velocity.Context;
import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.util.Introspector;
import org.apache.velocity.runtime.parser.*;
public class ASTMethod extends SimpleNode
{
private String methodName;
private int paramCount;
private Method method;
private Object[] params;
public ASTMethod(int id)
{
super(id);
}
public ASTMethod(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object init(Context context, Object data)
throws Exception
{
methodName = getFirstToken().image;
paramCount = jjtGetNumChildren() - 1;
params = new Object[paramCount];
method = Introspector.getMethod((Class) data, methodName, paramCount);
// Now the parameters have to be processed, there
// may be references contained within that need
// to be introspected.
for (int i = 0; i < paramCount; i++)
jjtGetChild(i + 1).init(context, null);
return method.getReturnType();
}
public Object execute(Object o, Context context)
{
// I need to pass in the arguments to the
// method.
for (int j = 0; j < paramCount; j++)
params[j] = jjtGetChild(j + 1).value(context);
try
{
return method.invoke(o, params);
}
catch (Exception e)
{
return null;
}
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTModNode.java
Index: ASTModNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTModNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTModNode extends SimpleNode
{
public ASTModNode(int id)
{
super(id);
}
public ASTModNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTMulNode.java
Index: ASTMulNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTMulNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTMulNode extends SimpleNode
{
public ASTMulNode(int id)
{
super(id);
}
public ASTMulNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object value(Context context)
{
return new Integer(((Integer) jjtGetChild(0).value(context)).intValue() *
((Integer) jjtGetChild(1).value(context)).intValue());
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTNENode.java
Index: ASTNENode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTNENode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTNENode extends SimpleNode
{
public ASTNENode(int id)
{
super(id);
}
public ASTNENode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
if (jjtGetChild(0).value(context) instanceof Boolean &&
((Boolean)jjtGetChild(0).value(context)).booleanValue() !=
((Boolean)jjtGetChild(1).value(context)).booleanValue())
return true;
else if (jjtGetChild(0).value(context) instanceof Integer &&
((Integer)jjtGetChild(0).value(context)).intValue() !=
((Integer)jjtGetChild(1).value(context)).intValue())
return true;
else if (jjtGetChild(0).value(context) instanceof String &&
! jjtGetChild(0).value(context).toString()
.equals(jjtGetChild(1).value(context).toString()))
return true;
else
return false;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTNotNode.java
Index: ASTNotNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTNotNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTNotNode extends SimpleNode
{
public ASTNotNode(int id)
{
super(id);
}
public ASTNotNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
if (jjtGetChild(0).evaluate(context))
return false;
else
return true;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTNumberLiteral.java
Index: ASTNumberLiteral.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTNumberLiteral.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTNumberLiteral extends SimpleNode
{
public ASTNumberLiteral(int id)
{
super(id);
}
public ASTNumberLiteral(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object value(Context context)
{
return new Integer(getFirstToken().image);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java
Index: ASTObjectArray.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTObjectArray.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTObjectArray extends SimpleNode
{
public ASTObjectArray(int id)
{
super(id);
}
public ASTObjectArray(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object value(Context context)
{
int size = jjtGetNumChildren();
Object[] objectArray = new Object[size];
for (int i = 0; i < size; i++)
{
objectArray[i] = jjtGetChild(i).value(context);
}
return objectArray;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java
Index: ASTOrNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTOrNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTOrNode extends SimpleNode
{
public ASTOrNode(int id)
{
super(id);
}
public ASTOrNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTParameters.java
Index: ASTParameters.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTParameters.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTParameters extends SimpleNode
{
public ASTParameters(int id)
{
super(id);
}
public ASTParameters(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java
Index: ASTReference.java
===================================================================
//* Generated By:JJTree: Do not edit this line. ASTReference.java */
package org.apache.velocity.runtime.parser.node;
import java.io.Writer;
import java.io.IOException;
import java.util.Map;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.util.ClassUtils;
import org.apache.velocity.runtime.parser.*;
public class ASTReference extends SimpleNode
{
private String nullString;
private Object root;
private Object value;
public ASTReference(int id)
{
super(id);
}
public ASTReference(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object init(Context context, Object data) throws Exception
{
root = getVariableValue(context, getRoot());
// An object has to be in the context for
// subsequent introspection.
if (root == null) return null;
Class clazz = root.getClass();
// All children here are either Identifier() nodes
// or Method() nodes.
int children = jjtGetNumChildren();
for (int i = 0; i < children; i++)
clazz = (Class) jjtGetChild(i).init(context, clazz);
return data;
}
public Object execute(Object o, Context context)
{
Object result = getVariableValue(context, getRoot());
if (result == null)
return null;
int children = jjtGetNumChildren();
for (int i = 0; i < children; i++)
result = jjtGetChild(i).execute(result,context);
return result;
}
public void render(Context context, Writer writer)
throws IOException
{
value = execute(null, context);
if (value == null)
writer.write(NodeUtils
.specialText(getFirstToken()) +
nullString);
else
writer.write(NodeUtils
.specialText(getFirstToken()) +
value.toString());
}
public boolean evaluate(Context context)
{
value = execute(null, context);
if (value == null)
return false;
else if (value instanceof Boolean)
{
if (((Boolean) value).booleanValue())
return true;
else
return false;
}
else
return true;
}
public Object value(Context context)
{
return execute(null, context);
}
public void setValue(Context context, Object value)
{
// The rootOfIntrospection is the object we will
// retrieve from the Context. This is the base
// object we will apply reflection to.
String root = getRoot();
Object result = getVariableValue(context, root);
if (result == null)
{
Runtime.error("Reference error: " + root + " " +
"not defined in the context.");
}
// How many child nodes do we have?
int children = jjtGetNumChildren();
for (int i = 0; i < children - 1; i++)
result = jjtGetChild(i).execute(result, context);
Object[] args = { value };
ClassUtils.invoke(result, "set" + jjtGetChild(children - 1)
.getFirstToken().image, args);
}
private String getRoot()
{
Token t = getFirstToken();
if (t.image.equals("$!"))
{
nullString = "";
if (t.next.image.equals("{"))
// $!{provider.Title}
return t.next.next.image;
else
// $!provider.Title
return t.next.image;
}
else if (t.image.equals("${"))
{
// ${provider.Title}
nullString = literal();
return t.next.image;
}
else
{
// $provider.Title
nullString = literal();
return t.image.substring(1);
}
}
/**
* Return the literal string representation
* of a reference. Used when a reference has
* a null value.
*
* For a variable reference like $foo this isn't
* working. hmmm.
*/
public String literal()
{
Token t = getFirstToken();
StringBuffer sb = new StringBuffer(t.image);
// Check to see if there are any children. If
// there aren't then we can return with the first
// token becasue it's a shorthand variable reference
// like $foo.
if (children == null)
return sb.toString();
while(t.next != null && t.next.last == false)
{
t = t.next;
sb.append(t.image);
}
sb.append(getLastToken().image);
return sb.toString();
}
public Object getVariableValue(Context context, String variable)
{
if (context.containsKey(variable))
return context.get(variable);
else
return null;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
Index: ASTSetDirective.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTSetDirective.java */
package org.apache.velocity.runtime.parser.node;
import java.io.IOException;
import java.io.Writer;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTSetDirective extends SimpleNode
{
public ASTSetDirective(int id)
{
super(id);
}
public ASTSetDirective(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public void render(Context context, Writer writer)
throws IOException
{
Object value = null;
Node right = jjtGetChild(0).jjtGetChild(0)
.jjtGetChild(1).jjtGetChild(0);
value = right.value(context);
ASTReference left = (ASTReference) jjtGetChild(0)
.jjtGetChild(0).jjtGetChild(0);
if (left.jjtGetNumChildren() == 0)
context.put(left.getFirstToken().image.substring(1), value);
else
left.setValue(context, value);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
Index: ASTStringLiteral.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTStringLiteral.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTStringLiteral extends SimpleNode
{
public ASTStringLiteral(int id)
{
super(id);
}
public ASTStringLiteral(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object value(Context context)
{
return getFirstToken().image.substring(1, getFirstToken().image.length() -
1);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTSubtractNode.java
Index: ASTSubtractNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTSubtractNode.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTSubtractNode extends SimpleNode
{
public ASTSubtractNode(int id)
{
super(id);
}
public ASTSubtractNode(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object value(Context context)
{
return new Integer(((Integer) jjtGetChild(0).value(context)).intValue() -
((Integer) jjtGetChild(1).value(context)).intValue());
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTText.java
Index: ASTText.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTText.java */
package org.apache.velocity.runtime.parser.node;
import java.io.Writer;
import java.io.IOException;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTText extends SimpleNode
{
private String text;
public ASTText(int id)
{
super(id);
}
public ASTText(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public Object init(Context context, Object data) throws Exception
{
text = NodeUtils.specialText(getFirstToken()) +
getFirstToken().image;
return data;
}
public void render(Context context, Writer writer)
throws IOException
{
writer.write(text);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTTrue.java
Index: ASTTrue.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTTrue.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTTrue extends SimpleNode
{
public ASTTrue(int id)
{
super(id);
}
public ASTTrue(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public boolean evaluate(Context context)
{
return true;
}
public Object value(Context context)
{
return new Boolean(true);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTVariable.java
Index: ASTVariable.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTVariable.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTVariable extends SimpleNode
{
public ASTVariable(int id)
{
super(id);
}
public ASTVariable(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTWord.java
Index: ASTWord.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTWord.java */
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class ASTWord extends SimpleNode {
public ASTWord(int id) {
super(id);
}
public ASTWord(Parser p, int id) {
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/ASTprocess.java
Index: ASTprocess.java
===================================================================
/* Generated By:JJTree: Do not edit this line. ASTprocess.java */
package org.apache.velocity.runtime.parser.node;
import java.io.Writer;
import java.io.IOException;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class ASTprocess extends SimpleNode
{
public ASTprocess(int id)
{
super(id);
}
public ASTprocess(Parser p, int id)
{
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
public void render(Context context, Writer writer)
throws IOException
{
int i, k = jjtGetNumChildren();
for (i = 0; i < k; i++)
jjtGetChild(i).render(context, writer);
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/AbstractExecutor.java
Index: AbstractExecutor.java
===================================================================
package org.apache.velocity.runtime.parser.node;
import java.util.Map;
import org.apache.velocity.Context;
public abstract class AbstractExecutor
{
protected Object data;
public abstract Object execute(Object o, Context context);
public void setData(Object data)
{
this.data = data;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/MapExecutor.java
Index: MapExecutor.java
===================================================================
package org.apache.velocity.runtime.parser.node;
import java.util.Map;
import org.apache.velocity.Context;
public class MapExecutor extends AbstractExecutor
{
private String name;
public void setData(Object data)
{
this.name = data.toString();
}
public Object execute(Object o, Context context)
{
if (((Map)o).containsKey(name))
{
return ((Map)o).get(name);
}
else
{
return null;
}
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/Node.java
Index: Node.java
===================================================================
/* Generated By:JJTree: Do not edit this line. Node.java */
package org.apache.velocity.runtime.parser.node;
import java.io.Writer;
import java.io.IOException;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
/* All AST nodes must implement this interface. It provides basic
machinery for constructing the parent and child relationships
between nodes. */
public interface Node
{
/** This method is called after the node has been made the current
node. It indicates that child nodes can now be added to it. */
public void jjtOpen();
/** This method is called after all the child nodes have been
added. */
public void jjtClose();
/** This pair of methods are used to inform the node of its
parent. */
public void jjtSetParent(Node n);
public Node jjtGetParent();
/** This method tells the node to add its argument to the node's
list of children. */
public void jjtAddChild(Node n, int i);
/** This method returns a child node. The children are numbered
from zero, left to right. */
public Node jjtGetChild(int i);
/** Return the number of children the node has. */
public int jjtGetNumChildren();
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data);
public Object childrenAccept(ParserVisitor visitor, Object data);
// added
public Token getFirstToken();
public Token getLastToken();
public int getType();
public Object init(Context context, Object data) throws Exception;
public boolean evaluate(Context context);
public Object value(Context context);
public void render(Context context, Writer writer)
throws IOException;
public Object execute(Object o, Context context);
public void setInfo(int info);
public int getInfo();
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/NodeUtils.java
Index: NodeUtils.java
===================================================================
package org.apache.velocity.runtime.parser.node;
import org.apache.velocity.runtime.parser.*;
public class NodeUtils
{
public static String specialText(Token t)
{
String specialText = "";
if (t.specialToken == null || t.specialToken.image.startsWith("##"))
return specialText;
Token tmp_t = t.specialToken;
while (tmp_t.specialToken != null)
tmp_t = tmp_t.specialToken;
while (tmp_t != null)
{
specialText += tmp_t.image;
tmp_t = tmp_t.next;
}
return specialText;
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
Index: PropertyExecutor.java
===================================================================
package org.apache.velocity.runtime.parser.node;
import java.lang.reflect.Method;
import org.apache.velocity.Context;
public class PropertyExecutor extends AbstractExecutor
{
protected Method method;
public void setData(Object data)
{
this.method = (Method) data;
}
public Object execute(Object o, Context context)
{
try
{
return method.invoke(o, null);
}
catch (Exception e)
{
return null;
}
}
}
1.1
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
Index: SimpleNode.java
===================================================================
/* Generated By:JJTree: Do not edit this line. SimpleNode.java */
package org.apache.velocity.runtime.parser.node;
import java.io.Writer;
import java.io.IOException;
import org.apache.velocity.Context;
import org.apache.velocity.runtime.parser.*;
public class SimpleNode implements Node
{
protected Node parent;
protected Node[] children;
protected int id;
protected Parser parser;
protected int info; // added
public boolean state;
/* Added */
protected Token first, last;
public SimpleNode(int i)
{
id = i;
}
public SimpleNode(Parser p, int i)
{
this(i);
parser = p;
}
public void jjtOpen()
{
first = parser.getToken(1); // added
}
public void jjtClose()
{
last = parser.getToken(0); // added
if (id == ParserTreeConstants.JJTREFERENCE)
last.last = true;
}
public void setFirstToken(Token t)
{
this.first = first;
}
public Token getFirstToken()
{
return first;
}
public Token getLastToken()
{
return last;
}
public void jjtSetParent(Node n)
{
parent = n;
}
public Node jjtGetParent()
{
return parent;
}
public void jjtAddChild(Node n, int i)
{
if (children == null)
{
children = new Node[i + 1];
}
else if (i >= children.length)
{
Node c[] = new Node[i + 1];
System.arraycopy(children, 0, c, 0, children.length);
children = c;
}
children[i] = n;
}
public Node jjtGetChild(int i)
{
return children[i];
}
public int jjtGetNumChildren()
{
return (children == null) ? 0 : children.length;
}
/** Accept the visitor. **/
public Object jjtAccept(ParserVisitor visitor, Object data)
{
return visitor.visit(this, data);
}
/** Accept the visitor. **/
public Object childrenAccept(ParserVisitor visitor, Object data)
{
if (children != null)
{
for (int i = 0; i < children.length; ++i)
{
children[i].jjtAccept(visitor, data);
}
}
return data;
}
/* You can override these two methods in subclasses of SimpleNode to
customize the way the node appears when the tree is dumped. If
your output uses more than one line you should override
toString(String), otherwise overriding toString() is probably all
you need to do. */
public String toString()
{
return ParserTreeConstants.jjtNodeName[id];
}
public String toString(String prefix)
{
return prefix + toString();
}
/* Override this method if you want to customize how the node dumps
out its children. */
public void dump(String prefix)
{
System.out.println(toString(prefix));
if (children != null)
{
for (int i = 0; i < children.length; ++i)
{
SimpleNode n = (SimpleNode) children[i];
if (n != null)
{
n.dump(prefix + " ");
}
}
}
}
// All additional methods
public Object init(Context context, Object data) throws Exception
{
int i, k = jjtGetNumChildren();
for (i = 0; i < k; i++)
jjtGetChild(i).init(context, data);
return data;
}
public boolean evaluate(Context context)
{
return false;
}
public Object value(Context context)
{
return null;
}
public void render(Context context, Writer writer)
throws IOException
{
}
public Object execute(Object o, Context context)
{
return null;
}
public int getType()
{
return id;
}
public void setInfo(int info)
{
this.info = info;
}
public int getInfo()
{
return info;
}
}