예제 #1
0
        /// <summary>
        /// 缓存模板对象
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public NVelocity.Template GetTemplate(string templateFile)
        {
            CacheProvider cache = CacheProvider.GetCacheService();

            templatePath = templatePath.Replace("\\", "").Replace(":", "").Replace("_", "");
            // string xpath = String.Format("/Template/{0}/{1}", templatePath, templateFile);
            string xpath = String.Format("/Template/{0}", templateFile);

            NVelocity.Template template = (NVelocity.Template)cache.RetrieveObject(xpath);
            if (template == null)
            {
                //VelocityEngine velocity = new VelocityEngine();
                //ExtendedProperties props = new ExtendedProperties();
                //props.AddProperty(RuntimeConstants.RESOURCE_LOADER, "file");
                //props.AddProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, templatePath);
                //props.AddProperty(RuntimeConstants.INPUT_ENCODING, "utf-8");
                //props.AddProperty(RuntimeConstants.OUTPUT_ENCODING, "utf-8");
                //velocity.Init(props);
                template = velocity.GetTemplate(templateFile);

                if (template == null)
                {
                    throw new NullReferenceException("模板目录不存在。");
                }

                cache.AddObject(xpath, template, templateCacheTime);
            }
            return(template);
        }