/// <summary> /// Initialize a SpringResourceLoader for the given VelocityEngine. /// <br/>Called by <code>InitVelocityResourceLoader</code>. /// /// <b>Important</b>: the NVeloctity ResourceLoaderFactory.getLoader /// method replaces ';' with ',' when attempting to construct our resource /// loader. The name on the SPRING_RESOURCE_LOADER_CLASS property /// has to be in the form of "ClassFullName; AssemblyName" in replacement /// of the tranditional "ClassFullName, AssemblyName" to work. /// </summary> /// <param name="velocityEngine">velocityEngine the VelocityEngine to configure</param> /// <param name="extendedProperties"></param> /// <param name="resourceLoaderPathString">resourceLoaderPath the path to load Velocity resources from</param> /// <see cref="SpringResourceLoader"/> /// <see cref="InitVelocityResourceLoader"/> protected void InitSpringResourceLoader(VelocityEngine velocityEngine, ExtendedProperties extendedProperties, string resourceLoaderPathString) { extendedProperties.SetProperty(RuntimeConstants.RESOURCE_LOADER, SpringResourceLoader.NAME); Type springResourceLoaderType = typeof(SpringResourceLoader); string springResourceLoaderTypeName = springResourceLoaderType.FullName + "; " + springResourceLoaderType.Assembly.GetName().Name; extendedProperties.SetProperty(SpringResourceLoader.SPRING_RESOURCE_LOADER_CLASS, springResourceLoaderTypeName); velocityEngine.SetApplicationAttribute(SpringResourceLoader.SPRING_RESOURCE_LOADER, ResourceLoader); velocityEngine.SetApplicationAttribute(SpringResourceLoader.SPRING_RESOURCE_LOADER_PATH, resourceLoaderPathString); }
public void Initialize() { var props = new ExtendedProperties(); if (ViewSourceLoader.HasSource("nvelocity.properties")) { using (var stream = ViewSourceLoader.GetViewSource("nvelocity.properties").OpenViewStream()) { props.Load(stream); } } // Set up a custom directive manager props.SetProperty("directive.manager", "Castle.MonoRail.Framework.Views.NVelocity.CustomDirectiveManager; Castle.MonoRail.Framework.Views.NVelocity"); InitializeVelocityProperties(props); velocity.SetApplicationAttribute(ServiceProvider, provider); velocity.Init(props); }
/// <summary> /// <p> /// Sets the stylesheet for this transformation set /// </p> /// /// <p> /// Note that don't need this for each document you want /// to transform. Just do it once, and transform away... /// </p> /// </summary> /// <param name="styleReader">Reader with stylesheet char stream</param> public void SetStylesheet(TextReader value) { ready = false; /* * now initialize Velocity - we need to do that * on change of stylesheet */ ve = new VelocityEngine(); /* * if there are user properties, set those first - carefully */ if (velConfig != null) { ConfigureVelocityEngine(ve, velConfig); } /* * register our template() directive */ ve.SetProperty("userdirective", @"NVelocity.Dvsl.Directive.MatchDirective\,NVelocity"); ve.Init(); /* * add our template accumulator */ ve.SetApplicationAttribute("NVelocity.Dvsl.TemplateHandler", templateHandler); /* * load and render the stylesheet * * this sets stylesheet specific context * values */ StringWriter junkWriter = new StringWriter(); styleContext = new VelocityContext(); ve.Evaluate(styleContext, junkWriter, "DVSL:stylesheet", value); /* * now run the base template through for the rules */ // TODO - use ResourceLocator or something else - I don't like the path to the resource Stream s = this.GetType().Assembly.GetManifestResourceStream("NVelocity.Dvsl.Resource.defaultroot.dvsl"); if (s == null) { Console.Out.WriteLine("DEFAULT TRANSFORM RULES NOT FOUND "); } else { ve.Evaluate(new VelocityContext(), junkWriter, "defaultroot.dvsl", new StreamReader(s)); s.Close(); } /* * need a new transformer, as it depends on the * velocity engine */ transformer = new Transformer(ve, templateHandler, baseContext, appVals, validate); }