[Adapdev-commits] Adapdev/src/Adapdev.NVelocity/Runtime/Parser/Node ASTAddNode.cs,1.2,1.3 ASTAndNode
Status: Beta
Brought to you by:
intesar66
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.NVelocity/Runtime/Parser/Node In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22005/src/Adapdev.NVelocity/Runtime/Parser/Node Added Files: ASTAddNode.cs ASTAndNode.cs ASTAssignment.cs ASTBlock.cs ASTComment.cs ASTDirective.cs ASTDivNode.cs ASTEQNode.cs ASTElseIfStatement.cs ASTElseStatement.cs ASTEscape.cs ASTEscapedDirective.cs ASTExpression.cs ASTFalse.cs ASTGENode.cs ASTGTNode.cs ASTIdentifier.cs ASTIfStatement.cs ASTIncludeStatement.cs ASTIntegerRange.cs ASTLENode.cs ASTLTNode.cs ASTMethod.cs ASTModNode.cs ASTMulNode.cs ASTNENode.cs ASTNotNode.cs ASTNumberLiteral.cs ASTObjectArray.cs ASTOrNode.cs ASTParameters.cs ASTReference.cs ASTSetDirective.cs ASTStringLiteral.cs ASTSubtractNode.cs ASTText.cs ASTTrue.cs ASTVariable.cs ASTWord.cs ASTprocess.cs AbstractExecutor.cs BooleanPropertyExecutor.cs GetExecutor.cs INode.cs NodeUtils.cs ParserVisitor.cs PropertyExecutor.cs SimpleNode.cs Log Message: --- NEW FILE: ASTTrue.cs --- namespace NVelocity.Runtime.Parser.Node { /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using NVelocity.Context; public class ASTTrue : SimpleNode { //UPGRADE_NOTE: Field value was renamed. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1029"' private static Boolean value_Renamed_Field = true; public ASTTrue(int id) : base(id) { } public ASTTrue(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } public override bool evaluate(InternalContextAdapter context) { return true; } public override Object value_Renamed(InternalContextAdapter context) { return value_Renamed_Field; } } } --- NEW FILE: ASTObjectArray.cs --- namespace NVelocity.Runtime.Parser.Node { /* Generated By:JJTree: Do not edit this line. ASTObjectArray.java */ /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using System.Collections; using NVelocity.Context; public class ASTObjectArray : SimpleNode { public ASTObjectArray(int id) : base(id) { } public ASTObjectArray(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } public override Object value_Renamed(InternalContextAdapter context) { int size = jjtGetNumChildren(); ArrayList objectArray = new ArrayList(); for (int i = 0; i < size; i++) { objectArray.Add(jjtGetChild(i).value_Renamed(context)); } return objectArray; } } } --- NEW FILE: ASTGENode.cs --- namespace NVelocity.Runtime.Parser.Node { /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using NVelocity.Context; public class ASTGENode : SimpleNode { public ASTGENode(int id) : base(id) { } public ASTGENode(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } public override bool evaluate(InternalContextAdapter context) { /* * get the two args */ Object left = jjtGetChild(0).value_Renamed(context); Object right = jjtGetChild(1).value_Renamed(context); /* * if either is null, lets log and bail */ if (left == null || right == null) { rsvc.error((left == null ? "Left" : "Right") + " side (" + jjtGetChild((left == null ? 0 : 1)).literal() + ") of '>=' operation has null value." + " Operation not possible. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); return false; } /* * if not an Integer, not much we can do either */ if (!(left is Int32) || !(right is Int32)) { rsvc.error((!(left is Int32) ? "Left" : "Right") + " side of '>=' operation is not a valid type. " + " It is a " + (!(left is Int32) ? left.GetType() : right.GetType()) + ". Currently only integers (1,2,3...) and Integer type is supported. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); return false; } return ((Int32) left) >= ((Int32) right); } } } --- NEW FILE: ASTGTNode.cs --- namespace NVelocity.Runtime.Parser.Node { /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using NVelocity.Context; public class ASTGTNode : SimpleNode { public ASTGTNode(int id) : base(id) { } public ASTGTNode(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } public override bool evaluate(InternalContextAdapter context) { /* * get the two args */ Object left = jjtGetChild(0).value_Renamed(context); Object right = jjtGetChild(1).value_Renamed(context); /* * if either is null, lets log and bail */ if (left == null || right == null) { rsvc.error((left == null ? "Left" : "Right") + " side (" + jjtGetChild((left == null ? 0 : 1)).literal() + ") of '>' operation has null value." + " Operation not possible. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); return false; } /* * if not an Integer, not much we can do either */ if (!(left is Int32) || !(right is Int32)) { rsvc.error((!(left is Int32) ? "Left" : "Right") + " side of '>' operation is not a valid type. " + " It is a " + (!(left is Int32) ? left.GetType() : right.GetType()) + ". Currently only integers (1,2,3...) and Integer type is supported. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); return false; } return ((Int32) left) > ((Int32) right); } } } --- NEW FILE: AbstractExecutor.cs --- namespace NVelocity.Runtime.Parser.Node { using System; using System.Reflection; using NVelocity.Context; /// <summary> Abstract class that is used to execute an arbitrary /// method that is in introspected. This is the superclass /// for the GetExecutor and PropertyExecutor. /// </summary> public abstract class AbstractExecutor { protected internal RuntimeServices rsvc = null; /// <summary> Method to be executed. /// </summary> protected internal MethodInfo method = null; protected internal PropertyInfo property = null; /// <summary> Execute method against context. /// </summary> public abstract Object execute(Object o, InternalContextAdapter context); /// <summary> Tell whether the executor is alive by looking /// at the value of the method. /// </summary> public virtual bool isAlive() { return (method != null || property != null); } } } --- NEW FILE: ASTAndNode.cs --- namespace NVelocity.Runtime.Parser.Node { /* Generated By:JJTree: Do not edit this line. ASTAndNode.java */ /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using NVelocity.Context; /// <summary> Please look at the Parser.jjt file which is /// what controls the generation of this class. /// * /// </summary> /// <author> <a href="mailto:jv...@ap...">Jason van Zyl</a> /// </author> /// <author> <a href="mailto:ge...@op...">Geir Magnusson Jr.</a> /// </author> /// <version> $Id: ASTAndNode.cs,v 1.3 2005/11/16 05:45:23 intesar66 Exp $ /// /// </version> public class ASTAndNode : SimpleNode { public ASTAndNode(int id) : base(id) { } public ASTAndNode(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } /// <summary> Returns the value of the expression. /// Since the value of the expression is simply the boolean /// result of evaluate(), lets return that. /// </summary> public override Object value_Renamed(InternalContextAdapter context) { return evaluate(context); } /// <summary> logical and : /// null && right = false /// left && null = false /// null && null = false /// </summary> public override bool evaluate(InternalContextAdapter context) { INode left = jjtGetChild(0); INode right = jjtGetChild(1); /* * if either is null, lets log and bail */ if (left == null || right == null) { rsvc.error((left == null ? "Left" : "Right") + " side of '&&' operation is null." + " Operation not possible. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); return false; } /* * short circuit the test. Don't eval the RHS if the LHS is false */ if (left.evaluate(context)) { if (right.evaluate(context)) { return true; } } return false; } } } --- NEW FILE: ASTEscapedDirective.cs --- namespace NVelocity.Runtime.Parser.Node { /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using System.IO; using NVelocity.Context; /// <summary> This class is responsible for handling EscapedDirectives /// in VTL. /// /// Please look at the Parser.jjt file which is /// what controls the generation of this class. /// * /// </summary> /// <author> <a href="mailto:ge...@op...">Geir Magnusson Jr.</a> /// </author> /// <version> $Id: ASTEscapedDirective.cs,v 1.3 2005/11/16 05:45:23 intesar66 Exp $ /// /// </version> public class ASTEscapedDirective : SimpleNode { public ASTEscapedDirective(int id) : base(id) { } public ASTEscapedDirective(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } public override bool render(InternalContextAdapter context, TextWriter writer) { writer.Write(FirstToken.image); return true; } } } --- NEW FILE: ASTMulNode.cs --- namespace NVelocity.Runtime.Parser.Node { /* Generated By:JJTree: Do not edit this line. ASTMulNode.java */ /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using NVelocity.Context; /// <summary> Handles integer multiplication /// * /// Please look at the Parser.jjt file which is /// what controls the generation of this class. /// * /// </summary> /// <author> <a href="mailto:jv...@ap...">Jason van Zyl</a> /// </author> /// <author> <a href="mailto:ge...@op...">Geir Magnusson Jr.</a> /// </author> /// <version> $Id: ASTMulNode.cs,v 1.3 2005/11/16 05:45:23 intesar66 Exp $ /// </version> public class ASTMulNode : SimpleNode { public ASTMulNode(int id) : base(id) { } public ASTMulNode(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } /// <summary> computes the product of the two args. Returns null if either arg is null /// or if either arg is not an integer /// </summary> public override Object value_Renamed(InternalContextAdapter context) { /* * get the two args */ Object left = jjtGetChild(0).value_Renamed(context); Object right = jjtGetChild(1).value_Renamed(context); /* * if either is null, lets log and bail */ if (left == null || right == null) { rsvc.error((left == null ? "Left" : "Right") + " side (" + jjtGetChild((left == null ? 0 : 1)).literal() + ") of multiplication operation has null value." + " Operation not possible. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); return null; } /* * if not an Integer, not much we can do either */ if (!(left is Int32) || !(right is Int32)) { rsvc.error((!(left is Int32) ? "Left" : "Right") + " side of multiplication operation is not a valid type. " + "Currently only integers (1,2,3...) and Integer type is supported. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); return null; } return ((Int32) left)*((Int32) right); } } } --- NEW FILE: NodeUtils.cs --- namespace NVelocity.Runtime.Parser.Node { /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using System.Text; using Context = Context.IContext; /// <summary> Utilities for dealing with the AST node structure. /// * /// </summary> /// <author> <a href="mailto:jv...@ap...">Jason van Zyl</a> /// </author> /// <author> <a href="mailto:ge...@op...">Geir Magnusson Jr.</a> /// </author> /// <version> $Id: NodeUtils.cs,v 1.3 2005/11/16 05:45:23 intesar66 Exp $ /// /// </version> public class NodeUtils { /// <summary> Collect all the <SPECIAL_TOKEN>s that /// are carried along with a token. Special /// tokens do not participate in parsing but /// can still trigger certain lexical actions. /// In some cases you may want to retrieve these /// special tokens, this is simply a way to /// extract them. /// </summary> 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) { String st = tmp_t.image; StringBuilder sb = new StringBuilder(); for (int i = 0; i < st.Length; i++) { char c = st[i]; if (c == '#' || c == '$') { sb.Append(c); } /* * more dreaded MORE hack :) * * looking for ("\\")*"$" sequences */ if (c == '\\') { bool ok = true; bool term = false; int j = i; for (ok = true; ok && j < st.Length; j++) { char cc = st[j]; if (cc == '\\') { /* * if we see a \, keep going */ continue; } else if (cc == '$') { /* * a $ ends it correctly */ term = true; ok = false; } else { /* * nah... */ ok = false; } } if (term) { String foo = st.Substring(i, (j) - (i)); sb.Append(foo); i = j; } } } specialText += sb.ToString(); tmp_t = tmp_t.next; } return specialText; } /// <summary> complete node literal /// * /// </summary> public static String tokenLiteral(Token t) { return specialText(t) + t.image; } /// <summary> Utility method to interpolate context variables /// into string literals. So that the following will /// work: /// * /// #set $name = "candy" /// $image.getURI("${name}.jpg") /// * /// And the string literal argument will /// be transformed into "candy.jpg" before /// the method is executed. /// </summary> public static String interpolate(String argStr, Context vars) { StringBuilder argBuf = new StringBuilder(); for (int cIdx = 0; cIdx < argStr.Length; ) { char ch = argStr[cIdx]; switch (ch) { case '$': StringBuilder nameBuf = new StringBuilder(); for (++cIdx; cIdx < argStr.Length; ++cIdx) { ch = argStr[cIdx]; if (ch == '_' || ch == '-' || Char.IsLetterOrDigit(ch)) nameBuf.Append(ch); else if (ch == '{' || ch == '}') continue; else break; } if (nameBuf.Length > 0) { Object value_Renamed = vars.Get(nameBuf.ToString()); if (value_Renamed == null) argBuf.Append("$").Append(nameBuf.ToString()); else { //UPGRADE_TODO: The equivalent in .NET for method 'java.Object.toString' may return a different value. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1043"' argBuf.Append(value_Renamed.ToString()); } } break; default: argBuf.Append(ch); ++cIdx; break; } } return argBuf.ToString(); } } } --- NEW FILE: ASTWord.cs --- namespace NVelocity.Runtime.Parser.Node { /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; public class ASTWord : SimpleNode { public ASTWord(int id) : base(id) { } public ASTWord(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } } } --- NEW FILE: ASTStringLiteral.cs --- namespace NVelocity.Runtime.Parser.Node { /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using System.IO; using NVelocity.Context; /// <summary> ASTStringLiteral support. Will interpolate! /// * /// </summary> /// <author> <a href="mailto:ge...@op...">Geir Magnusson Jr.</a> /// </author> /// <author> <a href="mailto:jv...@ap...">Jason van Zyl</a> /// </author> /// <version> $Id: ASTStringLiteral.cs,v 1.3 2005/11/16 05:45:23 intesar66 Exp $ /// /// </version> public class ASTStringLiteral : SimpleNode { /* cache the value of the interpolation switch */ private bool interpolate = true; private SimpleNode nodeTree = null; private String image = ""; private String interpolateimage = ""; public ASTStringLiteral(int id) : base(id) { } public ASTStringLiteral(Parser p, int id) : base(p, id) { } /// <summary> init : we don't have to do much. Init the tree (there /// shouldn't be one) and then see if interpolation is turned on. /// </summary> public override Object init(InternalContextAdapter context, Object data) { /* * simple habit... we prollie don't have an AST beneath us */ base.init(context, data); /* * the stringlit is set at template parse time, so we can * do this here for now. if things change and we can somehow * create stringlits at runtime, this must * move to the runtime execution path * * so, only if interpolation is turned on AND it starts * with a " AND it has a directive or reference, then we * can interpolate. Otherwise, don't bother. */ interpolate = rsvc.getBoolean(RuntimeConstants_Fields.INTERPOLATE_STRINGLITERALS, true) && FirstToken.image.StartsWith("\"") && ((FirstToken.image.IndexOf((Char) '$') != - 1) || (FirstToken.image.IndexOf((Char) '#') != - 1)); /* * get the contents of the string, minus the '/" at each end */ image = FirstToken.image.Substring(1, (FirstToken.image.Length - 1) - (1)); /* * tack a space on the end (dreaded <MORE> kludge) */ interpolateimage = image + " "; if (interpolate) { /* * now parse and init the nodeTree */ //UPGRADE_ISSUE: The equivalent of constructor 'java.io.BufferedReader.BufferedReader' is incompatible with the expected type in C#. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1109"' TextReader br = new StringReader(interpolateimage); /* * it's possible to not have an initialization context - or we don't * want to trust the caller - so have a fallback value if so * * Also, do *not* dump the VM namespace for this template */ nodeTree = rsvc.parse(br, (context != null) ? context.CurrentTemplateName : "StringLiteral", false); /* * init with context. It won't modify anything */ nodeTree.init(context, rsvc); } return data; } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } /// <summary> renders the value of the string literal /// If the properties allow, and the string literal contains a $ or a # /// the literal is rendered against the context /// Otherwise, the stringlit is returned. /// </summary> public override Object value_Renamed(InternalContextAdapter context) { if (interpolate) { try { /* * now render against the real context */ TextWriter writer = new StringWriter(); nodeTree.render(context, writer); /* * and return the result as a String */ String ret = writer.ToString(); /* * remove the space from the end (dreaded <MORE> kludge) */ return ret.Substring(0, (ret.Length - 1) - (0)); } catch (Exception e) { /* * eh. If anything wrong, just punt * and output the literal */ rsvc.error("Error in interpolating string literal : " + e); } } /* * ok, either not allowed to interpolate, there wasn't * a ref or directive, or we failed, so * just output the literal */ return image; } } } --- NEW FILE: ASTNENode.cs --- namespace NVelocity.Runtime.Parser.Node { /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Velocity", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact ap...@ap.... * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ using System; using NVelocity.Context; public class ASTNENode : SimpleNode { public ASTNENode(int id) : base(id) { } public ASTNENode(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. * /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } public override bool evaluate(InternalContextAdapter context) { Object left = jjtGetChild(0).value_Renamed(context); Object right = jjtGetChild(1).value_Renamed(context); /* * null check */ if (left == null || right == null) { rsvc.error((left == null ? "Left" : "Right") + " side (" + jjtGetChild((left == null ? 0 : 1)).literal() + ") of '!=' operation has null value." + " Operation not possible. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]"); return false; } /* * check to see if they are the same class. I don't think this is slower * as I don't think that getClass() results in object creation, and we can * extend == to handle all classes */ if (left.GetType().Equals(right.GetType())) { return !(left.Equals(right)); } else { rsvc.error("Error in evaluation of != expression." + " Both arguments must be of the same Class." + " Currently left = " + left.GetType() + ", right = " + right.GetType() + ". " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "] (ASTEQNode)"); return false; } } } } --- NEW FILE: ASTReference.cs --- namespace NVelocity.Runtime.Parser.Node { using System; using System.Collections; using System.IO; using System.Reflection; using System.Text; using NVelocity.App.Events; using NVelocity.Context; using NVelocity.Exception; using NVelocity.Runtime.Exception; /// <summary> /// This class is responsible for handling the references in /// VTL ($foo). /// /// Please look at the Parser.jjt file which is /// what controls the generation of this class. /// </summary> /// <author> <a href="mailto:jv...@ap...">Jason van Zyl</a></author> /// <author> <a href="mailto:ge...@op...">Geir Magnusson Jr.</a></author> /// <author> <a href="mailto:Chr...@dl...">Christoph Reck</a></author> /// <author> <a href="mailto:kjo...@tr...>Kent Johnson</a></author> /// <version> $Id: ASTReference.cs,v 1.3 2005/11/16 05:45:23 intesar66 Exp $ </version> public class ASTReference : SimpleNode { public virtual String RootString { get { return rootString; } } private String Root { get { Token t = FirstToken; /* * we have a special case where something like * $(\\)*!, where the user want's to see something * like $!blargh in the output, but the ! prevents it from showing. * I think that at this point, this isn't a reference. */ /* so, see if we have "\\!" */ int slashbang = t.image.IndexOf("\\!"); if (slashbang != - 1) { /* * lets do all the work here. I would argue that if this occurrs, it's * not a reference at all, so preceeding \ characters in front of the $ * are just schmoo. So we just do the escape processing trick (even | odd) * and move on. This kind of breaks the rule pattern of $ and # but '!' really * tosses a wrench into things. */ /* * count the escapes : even # -> not escaped, odd -> escaped */ int i = 0; int len = t.image.Length; i = t.image.IndexOf((Char) '$'); if (i == - 1) { /* yikes! */ rsvc.error("ASTReference.getRoot() : internal error : no $ found for slashbang."); computableReference = false; nullString = t.image; return nullString; } while (i < len && t.image[i] != '\\') { i++; } /* ok, i is the first \ char */ int start = i; int count = 0; while (i < len && t.image[i++] == '\\') { count++; } /* * now construct the output string. We really don't care about leading * slashes as this is not a reference. It's quasi-schmoo */ nullString = t.image.Substring(0, (start) - (0)); // prefix up to the first nullString += t.image.Substring(start, (start + count - 1) - (start)); // get the slashes nullString += t.image.Substring(start + count); // and the rest, including the /* * this isn't a valid reference, so lets short circuit the value and set calcs */ computableReference = false; return nullString; } /* * we need to see if this reference is escaped. if so * we will clean off the leading \'s and let the * regular behavior determine if we should output this * as \$foo or $foo later on in render(). Lazyness.. */ escaped = false; if (t.image.StartsWith("\\")) { /* * count the escapes : even # -> not escaped, odd -> escaped */ int i = 0; int len = t.image.Length; while (i < len && t.image[i] == '\\') { i++; } if ((i%2) != 0) escaped = true; if (i > 0) escPrefix = t.image.Substring(0, (i/2) - (0)); t.image = t.image.Substring(i); } /* * Look for preceeding stuff like '#' and '$' * and snip it off, except for the * last $ */ int loc1 = t.image.LastIndexOf((Char) '$'); /* * if we have extra stuff, loc > 0 * ex. '#$foo' so attach that to * the prefix. */ if (loc1 > 0) { morePrefix = morePrefix + t.image.Substring(0, (loc1) - (0)); t.image = t.image.Substring(loc1); } /* * Now it should be clean. Get the literal in case this reference * isn't backed by the context at runtime, and then figure out what * we are working with. */ nullString = literal(); if (t.image.StartsWith("$!")) { referenceType = QUIET_REFERENCE; /* * only if we aren't escaped do we want to null the output */ if (!escaped) nullString = ""; if (t.image.StartsWith("$!{")) { /* * ex : $!{provider.Title} */ return t.next.image; } else { /* * ex : $!provider.Title */ return t.image.Substring(2); } } else if (t.image.Equals("${")) { /* * ex : ${provider.Title} */ referenceType = FORMAL_REFERENCE; return t.next.image; } else if (t.image.StartsWith("$")) { /* * just nip off the '$' so we have * the root */ referenceType = NORMAL_REFERENCE; return t.image.Substring(1); } else { /* * this is a 'RUNT', which can happen in certain circumstances where * the parser is fooled into believeing that an IDENTIFIER is a real * reference. Another 'dreaded' MORE hack :). */ referenceType = RUNT; return t.image; } } } public virtual String Literal { set { /* * do only once */ if (this.literal_Renamed_Field == null) this.literal_Renamed_Field = value; } } /* Reference types */ private const int NORMAL_REFERENCE = 1; private const int FORMAL_REFERENCE = 2; private const int QUIET_REFERENCE = 3; private const int RUNT = 4; private int referenceType; private String nullString; private String rootString; private bool escaped = false; private bool computableReference = true; private String escPrefix = ""; private String morePrefix = ""; private String identifier = ""; //UPGRADE_NOTE: Field literal was renamed. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1029"' private String literal_Renamed_Field = null; private int numChildren = 0; public ASTReference(int id) : base(id) { } public ASTReference(Parser p, int id) : base(p, id) { } /// <summary>Accept the visitor. /// </summary> public override Object jjtAccept(ParserVisitor visitor, Object data) { return visitor.visit(this, data); } public override Object init(InternalContextAdapter context, Object data) { /* * init our children */ base.init(context, data); /* * the only thing we can do in init() is getRoot() * as that is template based, not context based, * so it's thread- and context-safe */ rootString = Root; numChildren = jjtGetNumChildren(); /* * and if appropriate... */ if (numChildren > 0) { identifier = jjtGetChild(numChildren - 1).FirstToken.image; } return data; } /// <summary> Returns the 'root string', the reference key /// </summary> /// <summary> gets an Object that 'is' the value of the reference /// * /// </summary> /// <param name="o"> unused Object parameter /// </param> /// <param name="context">context used to generate value /// /// </param> public override Object execute(Object o, InternalContextAdapter context) { if (referenceType == RUNT) return null; /* * get the root object from the context */ Object result = getVariableValue(context, rootString); if (result == null) { return null; } /* * Iteratively work 'down' (it's flat...) the reference * to get the value, but check to make sure that * every result along the path is valid. For example: * * $hashtable.Customer.Name * * The $hashtable may be valid, but there is no key * 'Customer' in the hashtable so we want to stop * when we find a null value and return the null * so the error gets logged. */ try { for (int i = 0; i < numChildren; i++) { result = jjtGetChild(i).execute(result, context); if (result == null) { return null; } } return result; } catch (MethodInvocationException mie) { /* * someone tossed their cookies */ rsvc.error("Method " + mie.MethodName + " threw exception for reference $" + rootString + " in template " + context.CurrentTemplateName + " at " + " [" + this.Line + "," + this.Column + "]"); mie.ReferenceName = rootString; throw mie; } } /// <summary> gets the value of the reference and outputs it to the /// writer. /// * /// </summary> /// <param name="context"> context of data to use in getting value /// </param> /// <param name="writer"> writer to render to /// /// </param> public override bool render(InternalContextAdapter context, TextWriter writer) { if (referenceType == RUNT) { writer.Write(rootString); return true; } Object value_Renamed = execute(null, context); /* * if this reference is escaped (\$foo) then we want to do one of two things : * 1) if this is a reference in the context, then we want to print $foo * 2) if not, then \$foo (its considered shmoo, not VTL) */ if (escaped) { if (value_Renamed == null) { writer.Write(escPrefix); writer.Write("\\"); writer.Write(nullString); } else { writer.Write(escPrefix); writer.Write(nullString); } return true; } /* * the normal processing * * if we have an event cartridge, get a new value object */ EventCartridge ec = context.EventCartridge; if (ec != null) { value_Renamed = ec.referenceInsert(nullString, value_Renamed); } /* * if value is null... */ if (value_Renamed == null) { /* * write prefix twice, because it's shmoo, so the \ don't escape each other... */ writer.Write(escPrefix); writer.Write(escPrefix); writer.Write(morePrefix); writer.Write(nullString); if (referenceType != QUIET_REFERENCE && rsvc.getBoolean(RuntimeConstants_Fields.RUNTIME_LOG_REFERENCE_LOG_INVALID, true)) { rsvc.warn(new ReferenceException("reference : template = " + context.CurrentTemplat... [truncated message content] |