예제 #1
0
파일: Dvsl.cs 프로젝트: DF-thangld/web_game
	/// <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);
	}
예제 #2
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);
        }