/// <summary> Internal Put method to select between local and global scope. /// /// </summary> /// <param name="key">name of item to set /// </param> /// <param name="value">object to set to key /// </param> /// <param name="forceLocal">True forces the object into the local scope. /// </param> /// <returns> old stored object /// </returns> protected internal virtual object Put(string key, object value, bool forceLocal) { INode astNode = (INode)vmproxyhash[key]; if (astNode != null) { if (astNode.Type == ParserTreeConstants.JJTREFERENCE) { ASTReference ref_Renamed = (ASTReference)astNode; if (ref_Renamed.GetNumChildren() > 0) { ref_Renamed.SetValue(innerContext, value); return(null); } else { return(innerContext.Put(ref_Renamed.RootString, value)); } } } object tempObject; tempObject = localcontext[key]; localcontext[key] = value; object old = tempObject; if (!forceLocal) { old = base.Put(key, value); } return(old); }
/// <summary> Implementation of the Context.Get() method. First checks /// localcontext, then arguments, then global context. /// /// </summary> /// <param name="key">name of item to Get /// </param> /// <returns> stored object or null /// </returns> public override object Get(string key) { object o = localcontext[key]; if (o != null) { return(o); } INode astNode = (INode)vmproxyhash[key]; if (astNode != null) { int type = astNode.Type; // if the macro argument (astNode) is a reference, we need to Evaluate it // in case it is a multilevel node if (type == NVelocity.Runtime.Parser.ParserTreeConstants.JJTREFERENCE) { ASTReference ref_Renamed = (ASTReference)astNode; if (ref_Renamed.GetNumChildren() > 0) { return(ref_Renamed.Execute((object)null, innerContext)); } else { object obj = innerContext.Get(ref_Renamed.RootString); if (obj == null && ref_Renamed.strictRef) { if (!innerContext.ContainsKey(ref_Renamed.RootString)) { throw new MethodInvocationException("Parameter '" + ref_Renamed.RootString + "' not defined", null, key, ref_Renamed.TemplateName, ref_Renamed.Line, ref_Renamed.Column); } } return(obj); } } else if (type == NVelocity.Runtime.Parser.ParserTreeConstants.JJTTEXT) { // this really shouldn't happen. text is just a throwaway arg for #foreach() try { System.IO.StringWriter writer = new System.IO.StringWriter(); astNode.Render(innerContext, writer); return(writer.ToString()); } catch (System.SystemException e) { throw e; } catch (System.Exception e) { string msg = "ProxyVMContext.Get() : error rendering reference"; rsvc.Log.Error(msg, e); throw new VelocityException(msg, e); } } else { // use value method to render other dynamic nodes return(astNode.Value(innerContext)); } } return(base.Get(key)); }