SetApplicationAttribute() public method

Set the an ApplicationAttribute, which is an Object set by the application which is accessible from any component of the system that gets a RuntimeServices. This allows communication between the application environment and custom pluggable components of the Velocity engine, such as loaders and loggers.

Note that there is no enforcement or rules for the key used - it is up to the application developer. However, to help make the intermixing of components possible, using the target Class name (e.g. com.foo.bar ) as the key might help avoid collision.

public SetApplicationAttribute ( Object key, Object value ) : void
key Object object 'name' under which the object is stored
value Object object to store under this key
return void
示例#1
0
	/// <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 virtual 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) {
		System.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);
	}
 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);
 }