public VMContext(IInternalContextAdapter inner, IRuntimeServices rsvc) { this.InitBlock(); this.localcontextscope = rsvc.GetBoolean("velocimacro.context.localscope", false); this.wrappedContext = inner; this.innerContext = inner.BaseContext; }
/// <summary> CTOR, wraps an ICA /// </summary> public VMContext(IInternalContextAdapter inner, IRuntimeServices runtimeServices) { InitBlock(); localContextScope = runtimeServices.GetBoolean(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, false); wrappedContext = inner; innerContext = inner.BaseContext; }
/// <summary> C'tor for the VelociMacro factory. /// /// </summary> /// <param name="rsvc">Reference to a runtime services object. /// </param> public VelocimacroFactory(IRuntimeServices rsvc) { this.rsvc = rsvc; this.log = new LogDisplayWrapper(rsvc.Log, "Velocimacro : ", rsvc.GetBoolean(RuntimeConstants.VM_MESSAGES_ON, true)); /* * we always access in a synchronized(), so we * can use an unsynchronized hashmap */ libModMap = new Dictionary <string, Twonk>(); vmManager = new VelocimacroManager(rsvc); }
/// <summary> Render the method exception, and optionally the exception message and stack Trace. /// /// </summary> /// <param name="claz">the class of the object the method is being applied to /// </param> /// <param name="method">the method /// </param> /// <param name="e">the thrown exception /// </param> /// <returns> an object to insert in the page /// </returns> /// <throws> Exception an exception to be thrown instead inserting an object </throws> public virtual object MethodException(System.Type claz, string method, System.Exception e) { bool showMessage = rs.GetBoolean(SHOW_MESSAGE, false); bool showStackTrace = rs.GetBoolean(SHOW_STACK_TRACE, false); System.Text.StringBuilder st; if (showMessage && showStackTrace) { st = new System.Text.StringBuilder(200); st.Append(e.GetType().FullName).Append("\n"); st.Append(e.Message).Append("\n"); st.Append(GetStackTrace(e)); } else if (showMessage) { st = new System.Text.StringBuilder(50); st.Append(e.GetType().FullName).Append("\n"); st.Append(e.Message).Append("\n"); } else if (showStackTrace) { st = new System.Text.StringBuilder(200); st.Append(e.GetType().FullName).Append("\n"); st.Append(GetStackTrace(e)); } else { st = new System.Text.StringBuilder(15); st.Append(e.GetType().FullName).Append("\n"); } return(st.ToString()); }
/// <summary> Intialize the Runtime macro. At the Init time no implementation so we /// just save the values to use at the render time. /// /// </summary> /// <param name="rs">runtime services /// </param> /// <param name="context">InternalContextAdapter /// </param> /// <param name="node">node containing the macro call /// </param> public override void Init(IRuntimeServices rs, IInternalContextAdapter context, INode node) { base.Init(rs, context, node); rsvc = rs; this.node = node; /** * Only check for strictRef setting if this really looks like a macro, * so strict mode doesn't balk at things like #E0E0E0 in a template. */ Token t = node.LastToken; if (t.Image[0] == ')') { strictRef = rsvc.GetBoolean(NVelocity.Runtime.RuntimeConstants.RUNTIME_REFERENCES_STRICT, false); } }
/// <summary> /// Initialize the ResourceManager. /// </summary> public void Initialize(IRuntimeServices rs) { runtimeServices = rs; runtimeServices.Info(string.Format("Default ResourceManager initializing. ({0})", GetType())); ResourceLoader resourceLoader; AssembleResourceLoaderInitializers(); for(int i = 0; i < sourceInitializerList.Count; i++) { ExtendedProperties configuration = (ExtendedProperties) sourceInitializerList[i]; String loaderClass = configuration.GetString("class"); if (loaderClass == null) { runtimeServices.Error( string.Format( "Unable to find '{0}.resource.loader.class' specification in configuration. This is a critical value. Please adjust configuration.", configuration.GetString(RESOURCE_LOADER_IDENTIFIER))); continue; } resourceLoader = ResourceLoaderFactory.getLoader(runtimeServices, loaderClass); resourceLoader.CommonInit(runtimeServices, configuration); resourceLoader.Init(configuration); resourceLoaders.Add(resourceLoader); } // now see if this is overridden by configuration logWhenFound = runtimeServices.GetBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true); // now, is a global cache specified? String resourceManagerCacheClassName = runtimeServices.GetString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS); Object o = null; if (resourceManagerCacheClassName != null && resourceManagerCacheClassName.Length > 0) { try { Type type = Type.GetType(resourceManagerCacheClassName); o = Activator.CreateInstance(type); } catch(System.Exception) { String err = string.Format( "The specified class for ResourceCache ({0}) does not exist (or is not accessible to the current classLoader).", resourceManagerCacheClassName); runtimeServices.Error(err); o = null; } if (!(o is ResourceCache)) { String err = string.Format( "The specified class for ResourceCache ({0}) does not implement NVelocity.Runtime.Resource.ResourceCache. Using default ResourceCache implementation.", resourceManagerCacheClassName); runtimeServices.Error(err); o = null; } } // if we didn't get through that, just use the default. if (o == null) { o = new ResourceCacheImpl(); } globalCache = (ResourceCache) o; globalCache.initialize(runtimeServices); runtimeServices.Info("Default ResourceManager initialization complete."); }
/// <summary> Initialize the ResourceManager. /// /// </summary> /// <param name="rsvc"> The Runtime Services object which is associated with this Resource Manager. /// /// </param> /// <throws> Exception </throws> public virtual void Initialize(IRuntimeServices rsvc) { lock (syncOjb) { if (isInit) { log.Debug("Re-initialization of ResourceLoader attempted and ignored."); return; } ResourceLoader resourceLoader = null; this.rsvc = rsvc; log = rsvc.Log; log.Trace("Default ResourceManager initializing. (" + this.GetType() + ")"); AssembleResourceLoaderInitializers(); for (IEnumerator it = sourceInitializerList.GetEnumerator(); it.MoveNext();) { /** * Resource loader can be loaded either via class name or be passed * in as an instance. */ ExtendedProperties configuration = (ExtendedProperties)it.Current; string loaderClass = StringUtils.NullTrim(configuration.GetString("class")); ResourceLoader loaderInstance = (ResourceLoader)configuration["instance"]; if (loaderInstance != null) { resourceLoader = loaderInstance; } else if (loaderClass != null) { resourceLoader = ResourceLoaderFactory.GetLoader(rsvc, loaderClass); } else { string msg = "Unable to find '" + configuration.GetString(RESOURCE_LOADER_IDENTIFIER) + ".resource.loader.class' specification in configuration." + " This is a critical value. Please adjust configuration."; log.Error(msg); throw new System.Exception(msg); } resourceLoader.CommonInit(rsvc, configuration); resourceLoader.Init(configuration); resourceLoaders.Add(resourceLoader); } /* * now see if this is overridden by configuration */ logWhenFound = rsvc.GetBoolean(NVelocity.Runtime.RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true); /* * now, is a global cache specified? */ string cacheClassName = rsvc.GetString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS); object cacheObject = null; if (!string.IsNullOrEmpty(cacheClassName)) { try { cacheObject = System.Activator.CreateInstance(Type.GetType(cacheClassName.Replace(';', ','))); } catch (System.Exception cnfe) { string msg = "The specified class for ResourceCache (" + cacheClassName + ") does not exist or is not accessible to the current classloader."; log.Error(msg, cnfe); throw cnfe; } if (!(cacheObject is IResourceCache)) { string msg = "The specified resource cache class (" + cacheClassName + ") must implement " + typeof(IResourceCache).FullName; log.Error(msg); throw new System.SystemException(msg); } } /* * if we didn't Get through that, just use the default. */ if (cacheObject == null) { cacheObject = new ResourceCacheImpl(); } globalCache = (IResourceCache)cacheObject; globalCache.Initialize(rsvc); log.Trace("Default ResourceManager initialization complete."); } }
/// <summary> /// Initialize the ResourceManager. /// </summary> public void Initialize(IRuntimeServices rs) { runtimeServices = rs; runtimeServices.Info(string.Format("Default ResourceManager initializing. ({0})", GetType())); ResourceLoader resourceLoader; AssembleResourceLoaderInitializers(); for (int i = 0; i < sourceInitializerList.Count; i++) { ExtendedProperties configuration = (ExtendedProperties)sourceInitializerList[i]; String loaderClass = configuration.GetString("class"); if (loaderClass == null) { runtimeServices.Error( string.Format( "Unable to find '{0}.resource.loader.class' specification in configuration. This is a critical value. Please adjust configuration.", configuration.GetString(RESOURCE_LOADER_IDENTIFIER))); continue; } resourceLoader = ResourceLoaderFactory.getLoader(runtimeServices, loaderClass); resourceLoader.CommonInit(runtimeServices, configuration); resourceLoader.Init(configuration); resourceLoaders.Add(resourceLoader); } // now see if this is overridden by configuration logWhenFound = runtimeServices.GetBoolean(RuntimeConstants.RESOURCE_MANAGER_LOGWHENFOUND, true); // now, is a global cache specified? String resourceManagerCacheClassName = runtimeServices.GetString(RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS); Object o = null; if (resourceManagerCacheClassName != null && resourceManagerCacheClassName.Length > 0) { try { Type type = Type.GetType(resourceManagerCacheClassName); o = Activator.CreateInstance(type); } catch (Exception) { String err = string.Format( "The specified class for ResourceCache ({0}) does not exist (or is not accessible to the current classLoader).", resourceManagerCacheClassName); runtimeServices.Error(err); o = null; } if (!(o is ResourceCache)) { String err = string.Format( "The specified class for ResourceCache ({0}) does not implement NVelocity.Runtime.Resource.ResourceCache. Using default ResourceCache implementation.", resourceManagerCacheClassName); runtimeServices.Error(err); o = null; } } // if we didn't get through that, just use the default. if (o == null) { o = new ResourceCacheImpl(); } globalCache = (ResourceCache)o; globalCache.initialize(runtimeServices); runtimeServices.Info("Default ResourceManager initialization complete."); }