AddProperty() public method

Add a property to the configuration. If it already exists then the value stated here will be added to the configuration entry. For example, if * resource.loader = file * is already present in the configuration and you * addProperty("resource.loader", "classpath") * Then you will end up with a Vector like the following: * ["file", "classpath"] *
public AddProperty ( String key, Object token ) : void
key String
token Object
return void
Beispiel #1
1
 static NVelocity()
 {
     filePath = Utils.GetMapPath(BaseConfigs.GetForumPath);
     engine = new VelocityEngine();
     props = new ExtendedProperties();
     props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
     props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
     props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, filePath);
     engine.Init(props);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="NVelocityViewEngine"/> class.
        /// </summary>
        /// <param name="assemblies">The assemblies.</param>
        /// <param name="extensionMethodTypes">The extension method types.</param>
        public NVelocityViewEngine(IEnumerable<Assembly> assemblies, params Type[] extensionMethodTypes)
        {
            var properties = new ExtendedProperties();
            properties.AddProperty("resource.loader", "parials");
            properties.AddProperty("parials.resource.loader.class", typeof(PartialFileResourceLoader).AssemblyQualifiedName.Replace(",", ";"));
            properties.AddProperty("parials.resource.loader.assembly", assemblies.Select(a => a.FullName).ToList());
            _engine = new VelocityEngine();
            _engine.Init(properties);

            _extensionMethods = extensionMethodTypes.SelectMany(type => type.GetMethods(BindingFlags.Public | BindingFlags.Static)).Select(method => new DynamicDispatchMethod(method)).ToArray();
        }
Beispiel #3
1
 static NVelocityHelper()
 {
     _velocity = new VelocityEngine();
     var props = new ExtendedProperties();
     props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, ConfigurationManager.AppSettings["TemplateFolder"]);
     _velocity.Init(props);
 }
 private static ExtendedProperties GetBasicProperties()
 {
     ExtendedProperties properties = new ExtendedProperties();
     properties.AddProperty("resource.loader", "assembly");
     properties.AddProperty("assembly.resource.loader.class",
         "NVelocity.Runtime.Resource.Loader.AssemblyResourceLoader, NVelocity");
     return properties;
 }
 public TemplateHelper(string templatePath)
 {
     velocity = new VelocityEngine();
     ExtendedProperties props = new ExtendedProperties();
     props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath);
     props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
     velocity.Init(props);
     context = new VelocityContext();
 }
        public void  Apply(IEnumerable<ChangeScript> changeScripts)
        {
            string filename = string.Format(CultureInfo.InvariantCulture, "{0}_{1}.vm", this.syntax, this.GetTemplateQualifier());

            var model = new Hashtable();
            
            model.Add("scripts", changeScripts);
            model.Add("changeLogTableName", this.changeLogTableName);
            model.Add("delimiter", this.delimiter);
            model.Add("separator", this.delimiterType is RowDelimiter ? Environment.NewLine : string.Empty);

            try
            {
                ExtendedProperties props = new ExtendedProperties();

                var assemblyName = typeof(TemplateBasedApplier).Assembly.GetName().Name;

                ReplaceManagersWithDbDeployVersions(props, assemblyName);

                if (this.templateDirectory == null)
                {
                    props.AddProperty("resource.loader", "assembly");

                    // The ";" will be replaced by "," in the resource loader factory.
                    // This is because if we add a property with a comma in the value, it will add *two* values to the property.
                    props.AddProperty(
                        "assembly.resource.loader.class",
                        typeof(DbDeployAssemblyResourceLoader).FullName + "; " + assemblyName);

                    props.AddProperty("assembly.resource.loader.assembly", assemblyName);
                    filename = "Net.Sf.Dbdeploy.Resources." + filename;
                }
                else
                {
                    props.SetProperty("file.resource.loader.path", this.templateDirectory.FullName);
                }

                var templateEngine = new VelocityEngine(props);

                var context = new VelocityContext(model);

                Template template = templateEngine.GetTemplate(filename);

                template.Merge(context, this.writer);
            }
            catch (ResourceNotFoundException ex)
            {
                string locationMessage = templateDirectory == null 
                    ? string.Empty 
                    : (" at " + templateDirectory.FullName);

                throw new UsageException(
                    "Could not find template named " + filename + locationMessage + Environment.NewLine + "Check that you have got the name of the database syntax correct.",
                    ex);
            }
        }
Beispiel #7
0
        public void Init(string virtualDir)
        {
            //创建VelocityEngine实例对象
            velocity = new VelocityEngine();
            //使用设置初始化VelocityEngine
            ExtendedProperties props = new ExtendedProperties();
            props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, string.Format("{0}\\{1}", Root.TrimEnd('\\'), virtualDir));
            props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
            //  props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
            velocity.Init(props);

            //为模板变量赋值
            context = new VelocityContext();
        }
        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();
            }
        }
Beispiel #9
0
        /// <summary>
        /// 初始话NVelocity模块
        /// </summary>
        /// <param name="templatDir">模板文件夹路径</param>
        public void Init(string templatDir)
        {
            //创建VelocityEngine实例对象
            _velocity = new VelocityEngine();

            //使用设置初始化VelocityEngine
            var props = new ExtendedProperties();
            props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatDir);
            props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
            props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
            _velocity.Init(props);

            //为模板变量赋值
            _context = new VelocityContext();
        }
        public void Test()
        {
            var vlte = new VelocityEngine();
            var props = new ExtendedProperties();
            props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, AppDomain.CurrentDomain.BaseDirectory);
            vlte.Init(props);

            var vlc = new VelocityContext();
            vlc.Put("test", "test");

            var vtp = vlte.GetTemplate("NVelocityTest.vm");
            var str = new StringWriter();
            vtp.Merge(vlc, str);
            Console.WriteLine(str.GetStringBuilder().ToString());
        }
Beispiel #11
0
        public static string Format(HttpContext context, string pattern, VelocityContext velocitycontext)
        {
                using (var writer = new StringWriter())
                {
                    try
                    {
                        if (!_isInitialized)
                        {
                            var props = new ExtendedProperties();
                            props.AddProperty("file.resource.loader.path",
                                              new ArrayList(new[]
                                                                {
                                                                    ".",
                                                                    Path.Combine(
                                                                        context.Server.MapPath(feed.HandlerBasePath),
                                                                        "Patterns")
                                                                }));
                            Velocity.Init(props);
                            _isInitialized = true;
                        }
                        //Load patterns
                        var template = Patterns.Get(pattern, () => LoadTemplate(pattern));

                        template.Merge(velocitycontext, writer);
                        return writer.GetStringBuilder().ToString();

                    }
                    catch (Exception)
                    {
                        //Format failed some way
                        return writer.GetStringBuilder().ToString();
                    }
                }
        }
        public NVelocityTemplateRepository(string templateDirectory)
        {
            engine = new VelocityEngine();
            ExtendedProperties props = new ExtendedProperties();
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templateDirectory);

            engine.Init(props);
        }
        public void Init()
        {
            _velocity = new VelocityEngine();

            var properties = new ExtendedProperties();
            properties.AddProperty(
                "resource.loader", 
                "assembly");
            properties.AddProperty(
                "assembly.resource.loader.class",
                "NVelocity.Runtime.Resource.Loader.AssemblyResourceLoader, NVelocity");
            properties.AddProperty(
                "assembly.resource.loader.assembly", 
                "CrystalQuartz.Web");

            _velocity.Init(properties);
        }
        public virtual bool Configure()
        {
            _engine = new VelocityEngine();
            var props = new ExtendedProperties();
            props.AddProperty("file.resource.loader.path", TemplatePath);
            _engine.Init(props);

            return true;
        }
Beispiel #15
0
 public virtual string FillResponseTemplate(IDictionary<string, object> viewParams)
 {
     var engine = new VelocityEngine();
     var props = new ExtendedProperties();
     props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "assembly");
     props.AddProperty("assembly.resource.loader.class",
                       "NVelocity.Runtime.Resource.Loader.AssemblyResourceLoader, NVelocity");
     props.AddProperty("assembly.resource.loader.assembly", GetType().Assembly.FullName);
     engine.Init(props);
     var vcontext = new VelocityContext();
     foreach (var k in viewParams) {
         vcontext.Put(k.Key, k.Value);
     }
     using (var writer = new StringWriter()) {
         engine.GetTemplate(ViewName).Merge(vcontext, writer);
         return writer.GetStringBuilder().ToString();
     }
 }
        public TemplateHelper(string templatePath)
        {
            velocity = new VelocityEngine();

            //使用设置初始化VelocityEngine
            ExtendedProperties props = new ExtendedProperties();

            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath);
            props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");

            //   props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "gb2312");
            //    props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");

            //  props.SetProperty(RuntimeConstants.RESOURCE_MANAGER_CLASS, "NVelocity.Runtime.Resource.ResourceManagerImpl\\,NVelocity");

            velocity.Init(props);
            //RuntimeConstants.RESOURCE_MANAGER_CLASS
            //为模板变量赋值
            context = new VelocityContext();
        }
        /// <summary>
        /// Generates a report filled with the content supplied by <paramref name="report"/>.
        /// </summary>
        /// <param name="report">Specifies the report model.</param>
        public void Generate(IReport report)
        {
            var engine = new VelocityEngine();
            var properties = new ExtendedProperties();
            properties.AddProperty("resource.loader", "assembly");
            properties.AddProperty("resource.manager.class", typeof(ResourceManagerImpl).AssemblyQualifiedName);
            properties.AddProperty("directive.manager", EncodeExternalAssemblyQualifiedType(typeof(DirectiveManagerProxy)));
            properties.AddProperty("assembly.resource.loader.class", typeof(AssemblyResourceLoader).AssemblyQualifiedName);
            properties.AddProperty("assembly.resource.loader.assembly", GetType().Assembly.GetName().Name);
            engine.Init(properties);

            var htmlTemplate = engine.GetTemplate("Xunit.Reporting.Internal.Generator.HtmlTemplate.vm");
            var generationContext = new VelocityContext();
            generationContext.Put("report", report);
            generationContext.Put("pluralizer", new Pluralizer());

            _outputWriter.Write(
                string.Concat(report.ReflectedAssembly, ".html"),
                writer => htmlTemplate.Merge(generationContext, writer));
        }
Beispiel #18
0
		/// <summary>
		/// Creates an instance of the EmailBuilder using the specified properties.
		/// </summary>
		/// <param name="nvelocityProperties"></param>
		public EmailBuilder(IDictionary<string, object> nvelocityProperties)
		{
			var properties = new ExtendedProperties();

			foreach (var pair in nvelocityProperties)
			{
				properties.AddProperty(pair.Key, pair.Value);
			}

			velocityEngine = new VelocityEngine();
			velocityEngine.Init(properties);
		}
Beispiel #19
0
        public NVelocityHelper(string templatePath)
        {
            this.templatePath = templatePath;
            velocity = new VelocityEngine();

            //使用设置初始化VelocityEngine
            ExtendedProperties props = new ExtendedProperties();

            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath);
            props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true); //是否缓存
            props.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)30); //缓存时间(秒)

            //   props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "gb2312");
            //    props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");

            //  props.SetProperty(RuntimeConstants.RESOURCE_MANAGER_CLASS, "NVelocity.Runtime.Resource.ResourceManagerImpl\\,NVelocity");

            velocity.Init(props);
            //RuntimeConstants.RESOURCE_MANAGER_CLASS
            //为模板变量赋值
            context = new VelocityContext();
        }
        public NVelocityViewEngine(IDictionary properties)
        {
            if( properties == null ) properties = DEFAULT_PROPERTIES;

            var props = new ExtendedProperties();
            foreach(string key in properties.Keys)
            {
                props.AddProperty(key, properties[key]);
            }

            _masterFolder = props.GetString("master.folder", string.Empty);

            _engine = new VelocityEngine();
            _engine.Init(props);
        }
Beispiel #21
0
    /// <summary>
    /// 初始话NVelocity模块
    /// </summary>
    /// <param name="templatePath">模板文件夹路径</param>
    public void Init(string templatePath) {
        //创建VelocityEngine实例对象
        velocity = new VelocityEngine();

        //使用设置初始化VelocityEngine
        ExtendedProperties props = new ExtendedProperties();
        props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
        string path = "".GetMapPath() + templatePath;
        props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, path);

        props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
        props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");

        //props.SetProperty(RuntimeConstants.RESOURCE_LOADER, "assembly");
        //props.SetProperty("assembly.resource.loader.assembly", new List<string>() { "Pub.Class" });

        //是否缓存
        props.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)30);    //缓存时间(秒)

        velocity.Init(props);

        //为模板变量赋值
        context = new VelocityContext();
    }
Beispiel #22
0
 /// <summary>
 /// 通过模版文件路径读取文件内容
 /// </summary>
 /// <param name="path">模版文件路径</param>
 /// <param name="ht">模版文件的参数</param>
 /// <returns>StringWriter对象</returns>
 public static StringWriter GetFileText(string path, Hashtable ht)
 {
     if (String.IsNullOrEmpty(path))
     {
         throw new ArgumentNullException("模版文件路径为空!");
     }
     try
     {
         string tmpPath = path.Substring(0,path.LastIndexOf(@"\"));
         string filePath = path.Substring(path.LastIndexOf(@"\")+1);
         //创建NVelocity引擎的实例对象
         VelocityEngine velocity = new VelocityEngine();
         ExtendedProperties props = new ExtendedProperties();
         props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
         props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, tmpPath);
         props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true);
         props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
         props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
         velocity.Init(props);
         //从文件中读取模板
         Template temp = velocity.GetTemplate(filePath);
         IContext context = new VelocityContext();
         foreach (string key in ht.Keys)
         {
             context.Put(key, ht[key]);
         }
         //合并模板
         StringWriter writer = new StringWriter();
         temp.Merge(context, writer);
         return writer;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public ModelGenerator(FileExists p_FileExists, string p_NameSpace,
            bool p_MakePartial, bool p_PropChange, bool p_Validate)
        {
            _FileExists = p_FileExists;
            _NameSpace = p_NameSpace;
            _MakePartial = p_MakePartial;
            _PropChange = p_PropChange;
            _EnableValidationAttributes = p_Validate;
            _fhResult = FileHandlingResult.None;

            // Initialize NVelocity
            engine = new VelocityEngine();
            ExtendedProperties props = new ExtendedProperties();
            props.AddProperty("file.resource.loader.path", new ArrayList(new string[] { ".", @".\Templates" }));
            engine.Init(props);
        }
Beispiel #24
0
        /// <summary>
        /// 生成内容
        /// </summary>
        /// <returns></returns>
        public string GetString()
        {
            VelocityEngine ve = new VelocityEngine();//模板引擎实例化
            ExtendedProperties ep = new ExtendedProperties();//模板引擎参数实例化

            ep.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)300); //缓存时间(秒)
            ve.Init(ep);

            VelocityContext vc = new VelocityContext(); //当前的数据信息载体集合

            foreach (var item in Items)
            {
                vc.Put(item.Key, item.Value);
            }
            TextWriter writer = new StringWriter();
            ve.MergeTemplate(TemplateName, "utf-8", vc, writer);

            return writer.ToString();
        }
        public NVelocityViewEngine(IDictionary properties)
        {
            base.MasterLocationFormats = new string[] { "~/Views/{1}/{0}.vm", "~/Views/Shared/{0}.vm" };
            base.AreaMasterLocationFormats = new string[] { "~/Areas/{2}/Views/{1}/{0}.vm", "~/Areas/{2}/Views/Shared/{0}.vm" };
            base.ViewLocationFormats = new string[] { "~/Views/{1}/{0}.vm", "~/Views/Shared/{0}.vm" };
            base.AreaViewLocationFormats = new string[] { "~/Areas/{2}/Views/{1}/{0}.vm", "~/Areas/{2}/Views/Shared/{0}.vm" };
            base.PartialViewLocationFormats = base.ViewLocationFormats;
            base.AreaPartialViewLocationFormats = base.AreaViewLocationFormats;
            base.FileExtensions = new string[] { "vm" };

            if (properties == null) properties = DEFAULT_PROPERTIES;

            ExtendedProperties props = new ExtendedProperties();
            foreach (string key in properties.Keys)
            {
                props.AddProperty(key, properties[key]);
            }

            _engine = new VelocityEngine();
            _engine.Init(props);
        }
Beispiel #26
0
        /// <summary>
        /// ��ʼ��NVelocityģ��
        /// </summary>
        /// <param name="templatDir">ģ���ļ���·��</param>
        public void Init(string templatDir, string charset)
        {
            //����VelocityEngineʵ������
            velocity = new VelocityEngine();

            //ʹ�����ó�ʼ��VelocityEngine
            ExtendedProperties props = new ExtendedProperties();
            props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, HttpContext.Current.Server.MapPath(templatDir));
            props.AddProperty(RuntimeConstants.INPUT_ENCODING, charset);
            props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, charset);
            velocity.Init(props);

            //Ϊģ�������ֵ
            context = new VelocityContext();
        }
		private void LoadMacros(ExtendedProperties props)
		{
			var macros = ViewSourceLoader.ListViews("macros",this.ViewFileExtension,this.JSGeneratorFileExtension);

			var macroList = new ArrayList(macros);

			if (macroList.Count > 0)
			{
				var libPropValue = props.GetProperty(RuntimeConstants.VM_LIBRARY);

				if (libPropValue is ICollection)
				{
					macroList.AddRange((ICollection) libPropValue);
				}
				else if (libPropValue is string)
				{
					macroList.Add(libPropValue);
				}

				props.AddProperty(RuntimeConstants.VM_LIBRARY, macroList);
			}

			props.AddProperty(RuntimeConstants.VM_LIBRARY_AUTORELOAD, true);
		}
		private void SetLoaderPath(ExtendedProperties properties)
		{
			string loaderPath = "";
			// TODO: Solve multiple loader path problem in NVelocity
			if (Template.FileName == "")
			{
				loaderPath = BaseFolder;
			}
			else
			{
				loaderPath = Path.GetDirectoryName(Template.GetFullPath());
				if (loaderPath.IndexOf(BaseFolder) < 0 && loaderPath != BaseFolder)
				{
					loaderPath = BaseFolder + "," + loaderPath;
				}
				else if (loaderPath != BaseFolder)
				{
					loaderPath += "," + BaseFolder;
				}
			}
			// HACK: Setting loader path to base folder until loader problem is solved
			//loaderPath = BaseFolder;
			//System.Diagnostics.Debug.WriteLine("NVeleocity:loaderPath=" + loaderPath);
			if (properties.Contains("file.resource.loader.path"))
			{
				properties["file.resource.loader.path"] = loaderPath;
			}
			else
			{
				properties.AddProperty("file.resource.loader.path", loaderPath);
			}
		}
        /// <summary>
        /// 初始话NVelocity模块
        /// </summary>
        public void Init(string templatDir)
        {
            // 创建VelocityEngine实例对象
            velocity = new VelocityEngine();

            // 使用设置初始化VelocityEngine
            ExtendedProperties props = new ExtendedProperties();
            props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, HttpContext.Current.Server.MapPath(templatDir));
            //props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, Path.GetDirectoryName(HttpContext.Current.Request.PhysicalPath));
            props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
            props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");

            // 模板的缓存设置
            props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE, true);              //是否缓存
            props.AddProperty("file.resource.loader.modificationCheckInterval", (Int64)30);    //缓存时间(秒)

            velocity.Init(props);

            // 为模板变量赋值
            context = new VelocityContext();
        }
 /// <summary>
 /// Sets internal properties of the Velocity engine.
 /// </summary>
 /// <param name="properties">The velocity engine extended properties.</param>
 protected virtual void SetupVelocityEngine(ExtendedProperties properties)
 {
     properties.AddProperty("file.resource.loader.path", Path.GetDirectoryName(templateDirectory));
     properties.AddProperty("directive.parse.max.depth", 100);
 }