当前位置: 首页>>代码示例>>C#>>正文


C# App.VelocityEngine类代码示例

本文整理汇总了C#中NVelocity.App.VelocityEngine的典型用法代码示例。如果您正苦于以下问题:C# VelocityEngine类的具体用法?C# VelocityEngine怎么用?C# VelocityEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


VelocityEngine类属于NVelocity.App命名空间,在下文中一共展示了VelocityEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            DataBooks book=new DataBooks();
            book.name = context.Request["bookname"];
            book.type = context.Request["booktype"];
            if(book.name!=null)
                bookcollector.Add(book);

            context.Response.ContentType = "text/html";
            VelocityEngine vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
            vltEngine.Init();

            VelocityContext vltContext = new VelocityContext();

            //vltContext.Put("msg", "");
            vltContext.Put("bookcollector", bookcollector);
            vltContext.Put("book", book);

            Template vltTemplate = vltEngine.GetTemplate("Front/ShopingCar.html");//模版文件所在位置

            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);
            string html = vltWriter.GetStringBuilder().ToString();
            context.Response.Write(html);
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:27,代码来源:ShopingCar.ashx.cs

示例2: NVelocityHelper

 static NVelocityHelper()
 {
     _velocity = new VelocityEngine();
     var props = new ExtendedProperties();
     props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, ConfigurationManager.AppSettings["TemplateFolder"]);
     _velocity.Init(props);
 }
开发者ID:lynchjames,项目名称:CallJSON,代码行数:7,代码来源:NVelocityHelper.cs

示例3: Setup

		public void Setup()
		{
			context = new VelocityContext();

			ve = new VelocityEngine();
			ve.Init();
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:7,代码来源:MacroTestCase.cs

示例4: RenderTemplate

        public string RenderTemplate(string masterPage, string templateName, IDictionary<string, object> data)
        {
            if (string.IsNullOrEmpty(templateName))
            {
                throw new ArgumentException("The \"templateName\" parameter must be specified", "templateName");
            }

            var name = !string.IsNullOrEmpty(masterPage)
                 ? masterPage : templateName;

            var engine = new VelocityEngine();
            var props = new ExtendedProperties();
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, _templatesPath);
            engine.Init(props);
            var template = engine.GetTemplate(name);
            template.Encoding = Encoding.UTF8.BodyName;
            var context = new VelocityContext();

            var templateData = data ?? new Dictionary<string, object>();
            foreach (var key in templateData.Keys)
            {
                context.Put(key, templateData[key]);
            }

            if (!string.IsNullOrEmpty(masterPage))
            {
                context.Put("childContent", templateName);
            }

            using (var writer = new StringWriter())
            {
                engine.MergeTemplate(name, context, writer);
                return writer.GetStringBuilder().ToString();
            }
        }
开发者ID:leon737,项目名称:MvcBlanket,代码行数:35,代码来源:NVelocityTemplateRepository.cs

示例5: RenderHtml

        /// <summary>
        /// 用data数据填充templateName模板,渲染生成html返回
        /// </summary>
        /// <param name="templateName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string RenderHtml(string templateName, object data)
        {
            //第一步:Creating a VelocityEngine也就是创建一个VelocityEngine的实例
            VelocityEngine vltEngine = new VelocityEngine();   //也可以使用带参构造函数直接实例
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
            vltEngine.Init();
            //vltEngine.AddProperty(RuntimeConstants.INPUT_ENCODING, "gb2312");
            //vltEngine.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "gb2312");

            //第二步:Creating the Template加载模板文件
            //这时通过的是Template类,并使用VelocityEngine的GetTemplate方法加载模板
            Template vltTemplate = vltEngine.GetTemplate(templateName);

            //第三步:Merging the template整合模板
            VelocityContext vltContext = new VelocityContext();
            vltContext.Put("Data", data);//设置参数,在模板中可以通过$data来引用

            //第四步:创建一个IO流来输出模板内容推荐使用StringWriter(因为template中以string形式存放)
            System.IO.StringWriter vltWriter = new System.IO.StringWriter();
            vltTemplate.Merge(vltContext, vltWriter);

            string html = vltWriter.GetStringBuilder().ToString();
            return html;
        }
开发者ID:zhangtaoxgu,项目名称:aspnetProject,代码行数:31,代码来源:CommonHelper.cs

示例6: Initialize

		public void Initialize()
		{
            ActiveRecordStarter.Initialize( new XmlConfigurationSource("activeRecord.xml"),
              typeof(Acl) ,
              typeof(Category) ,
              typeof(Chat) ,
              typeof(ChatMessage) ,
              typeof(ConfigCombo) ,
              typeof(ConfigModel) ,
              typeof(Container) ,
              typeof(Content) ,
              typeof(DataModel) ,
              typeof(Field) ,
              typeof(FieldTemplate) ,
              typeof(CastlePortal.File) ,
              typeof(Forum) ,
              typeof(ForumFolder) ,
              typeof(ForumMessage) ,
              typeof(Group) ,
              typeof(Menu) ,
              typeof(Role) ,
              typeof(CastlePortal.Template) ,
              typeof(CastlePortal.Type) ,
              typeof(Language),
              typeof(MenuTranslation),
              typeof(TypeTranslation),
              typeof(User)
           );
           
           velocity = new VelocityEngine();
           ExtendedProperties props = new ExtendedProperties();
           velocity.Init(props);
		}
开发者ID:BackupTheBerlios,项目名称:castleportal-svn,代码行数:33,代码来源:Test1.cs

示例7: Format

        /// <summary>The format.</summary>
        /// <param name="text">The text.</param>
        /// <param name="items">The items.</param>
        /// <returns>The format.</returns>
        /// <exception cref="TemplateException"></exception>
        public string Format(string text, Dictionary<string, object> items)
        {
            try
            {
                VelocityContext velocityContext = new VelocityContext();

                if (items != null)
                {
                    foreach (var pair in items)
                    {
                        velocityContext.Put(pair.Key, pair.Value);
                    }
                }

                StringWriter sw = new StringWriter();
                VelocityEngine velocityEngine = new VelocityEngine();
                velocityEngine.Init();

                bool ok = velocityEngine.Evaluate(velocityContext, sw, "ContextTest.CaseInsensitive", text);

                if (!ok)
                {
                    throw new TemplateException("Template run error (try adding an extra newline at the end of the file)");
                }

                return sw.ToString();
            }
            catch (ParseErrorException parseErrorException)
            {
                throw new TemplateException(parseErrorException.Message, parseErrorException);
            }
        }
开发者ID:ClusterReply,项目名称:minisqlquery,代码行数:37,代码来源:NVelocityWrapper.cs

示例8: Transformer

	/// <summary>
	/// Sole public CTOR.  We rely on the caller to give us a
	/// VelocityEngine ready with all macros registered.
	/// The context is the callers context with all tools and
	/// style drek.
	/// </summary>
	public Transformer(VelocityEngine ve, TemplateHandler th, IContext context, Hashtable applicationValues, bool validate) {
	    this.ve = ve;
	    this.baseContext = context;
	    this.templateHandler = th;

	    appValue = applicationValues;
	}
开发者ID:BackupTheBerlios,项目名称:ch3etah-svn,代码行数:13,代码来源:Transformer.cs

示例9: SetUp

		public void SetUp()
		{
			ve = new VelocityEngine();
			ve.Init();

			ctx = new VelocityContext();
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:7,代码来源:ObjectComparisonTestCase.cs

示例10: RenderTemplate

        public void RenderTemplate(string templateName, object model)
        {
            string templateFullPath = applicationInfo.AbsolutizePath("Web/Pages/Templates/" + templateName + ".vm.html");

            ITemplateSource template = new CacheableFileTemplate(
                templateFullPath,
                fileCache);
            string templateText = template.GetTemplate();

            VelocityEngine velocity = new VelocityEngine();
            velocity.Init();

            VelocityContext velocityContext = new VelocityContext();
            velocityContext.Put("m", model);
            velocityContext.Put("h", this);

            using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                if (false == velocity.Evaluate(velocityContext, stringWriter, null, templateText))
                    throw new InvalidOperationException("Template expansion failed");

                writer.InnerWriter.Write(stringWriter.ToString());
            }

            writer.WriteLine();
        }
开发者ID:Ryks,项目名称:detergent,代码行数:26,代码来源:NVelocityHtmlRenderHelper.cs

示例11: NVelocityView

 /// <summary>
 /// Initializes a new instance of the <see cref="NVelocityView"/> class.
 /// </summary>
 /// <param name="template">The template.</param>
 /// <param name="viewData">The view data.</param>
 /// <param name="engine">The engine.</param>
 public NVelocityView(Template template, ViewDataDictionary viewData, VelocityEngine engine)
 {
     _context = new VelocityContext();
     _template = template;
     _engine = engine;
     ViewData = viewData;
 }
开发者ID:PaulStovell,项目名称:bindable,代码行数:13,代码来源:NVelocityView.cs

示例12: MergeTemplateIntoString

        /// <summary>
        /// Merge the specified Velocity template with the given model into a string.
        /// </summary>
        /// <param name="velocityEngine">VelocityEngine to work with</param>
        /// <param name="templateLocation">the location of template, relative to Velocity's resource loader path</param>
        /// <param name="encoding">the encoding string to use for the merge</param>
        /// <param name="model">the Hashtable that contains model names as keys and model objects</param>       
        /// <returns>the result as string</returns>
        /// <exception cref="VelocityException">thrown if any exception is thrown by the velocity engine</exception>		
        public static string MergeTemplateIntoString(
            VelocityEngine velocityEngine, string templateLocation, string encoding, Hashtable model) {

            StringWriter result = new StringWriter();
            MergeTemplate(velocityEngine, templateLocation, encoding, model, result);
            return result.ToString();
        }
开发者ID:fgq841103,项目名称:spring-net,代码行数:16,代码来源:VelocityEngineUtils.cs

示例13: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";

            string username = context.Request.Form["username"];
            string password = context.Request.Form["password"];

            if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password))
            {

                VelocityEngine vltEngine = new VelocityEngine();
                vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                vltEngine.Init();

                VelocityContext vltContext = new VelocityContext();
                //vltContext.Put("p", person);//设置参数,在模板中可以通过$data来引用
                vltContext.Put("username", "");
                vltContext.Put("password", "");
                vltContext.Put("msg", "");

                Template vltTemplate = vltEngine.GetTemplate("Front/login.html");//模版文件所在位置

                System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                vltTemplate.Merge(vltContext, vltWriter);

                string html = vltWriter.GetStringBuilder().ToString();
                context.Response.Write(html);
            }
            else
            {
                if (dataaccess(username, password))
                {
                    context.Session["username"] = username;
                    context.Response.Redirect("Index.ashx");
                }
                else
                {

                    VelocityEngine vltEngine = new VelocityEngine();
                    vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                    vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, System.Web.Hosting.HostingEnvironment.MapPath("~/templates"));//模板文件所在的文件夹
                    vltEngine.Init();

                    VelocityContext vltContext = new VelocityContext();
                    //vltContext.Put("p", person);//设置参数,在模板中可以通过$data来引用
                    vltContext.Put("username", username);
                    vltContext.Put("password", password);
                    vltContext.Put("msg", "用户名密码错误");

                    Template vltTemplate = vltEngine.GetTemplate("Front/login.html");//模版文件所在位置

                    System.IO.StringWriter vltWriter = new System.IO.StringWriter();
                    vltTemplate.Merge(vltContext, vltWriter);

                    string html = vltWriter.GetStringBuilder().ToString();
                    context.Response.Write(html);
                }
            }
        }
开发者ID:ujsxn,项目名称:UJSBookStore,代码行数:60,代码来源:Login.ashx.cs

示例14: Helper

        public Helper()
        {
            vltEngine = new VelocityEngine();
            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, AppDomain.CurrentDomain.BaseDirectory);

            vltEngine.Init();
        }
开发者ID:yunchenglk,项目名称:XY.Application,代码行数:8,代码来源:Helper.cs

示例15: NVelocityTemplateRepository

        public NVelocityTemplateRepository(string templateDirectory)
        {
            engine = new VelocityEngine();
            ExtendedProperties props = new ExtendedProperties();
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDirectory);

            engine.Init(props);
        }
开发者ID:zhsh1241,项目名称:Sconit5_Shenya,代码行数:8,代码来源:NVelocityTemplateRepository.cs


注:本文中的NVelocity.App.VelocityEngine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。