internal static void FilledInTagList(string tagdef, ArrayList tagList, IResourceDependency res) { int idxBegin = 0, idxEnd = 0; idxBegin = tagdef.IndexOf("#}"); idxEnd = tagdef.LastIndexOf("{#"); tagdef = tagdef.Substring(idxBegin + 2, idxEnd - idxBegin - 2).Trim(); Regex regEx = new Regex(TagBase.TagDefinitionPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); idxBegin = idxEnd = 0; MatchCollection mc = regEx.Matches(tagdef, idxBegin); HtmlTextTag htmlTag = null; while (mc.Count > 0) { Match m = mc[0]; idxEnd = m.Index; if (idxEnd > idxBegin) { htmlTag = new HtmlTextTag(tagdef.Substring(idxBegin, idxEnd - idxBegin)); tagList.Add(htmlTag); } TagBase tag = new TagBase(m.Value, m.Index, ref tagdef); //Util.Debug(tag.Category); if (tag.Category == TagCategory.AutoTag) { AutoItem item = AutoItem.Parse(tag); if (res.GetType() == typeof(PagerTag)) { item.CallerTag = (PagerTag)res; } tagList.Add(item); } else if (tag.Category == TagCategory.DefineTag) { //数据库标签定义格式为 {#%FieldName%#} if (res != null) { htmlTag = new HtmlTextTag(res.GetDefinition(tag.OuterDefineText).ToString()); tagList.Add(htmlTag); } } else if (tag.Category == TagCategory.CustomTag) { #region 数据定义标签内包含数据定义标签 DbStoredCustomTag dbTag = DbStoredCustomTag.Parse(tag); dbTag.SetResourceDependency(res); if (dbTag.IsExist == true) { htmlTag = new HtmlTextTag(dbTag.GetTagValue().ToString()); tagList.Add(htmlTag); } #endregion } else if (tag.Category == TagCategory.SystemTag) { string pageURLKey = ",FirstUrl,PreUrl,NextUrl,LastUrl,CurUrl,"; string tagName = tag.TagName.Trim('$'); if (pageURLKey.IndexOf("," + tagName + ",", StringComparison.InvariantCultureIgnoreCase) != -1) { tagName = tagName.ToLower(); PageUrl url = new PageUrl(tag.OuterDefineText); url.IsAutoItem = (res != null && res.GetType() == typeof(AutoItem)); url.SetResourceDependency(res); switch (tagName) { case "firsturl": url.UrlCategory = PageUrlCategory.FirstPage; break; case "preurl": url.UrlCategory = PageUrlCategory.PrePage; break; case "nexturl": url.UrlCategory = PageUrlCategory.NextPage; break; case "lasturl": url.UrlCategory = PageUrlCategory.LastPage; break; case "cururl": url.UrlCategory = PageUrlCategory.ThisPage; break; default: url.UrlCategory = PageUrlCategory.ThisPage; break; } tagList.Add(url); } else { SystemTag sys = new SystemTag(tag.OuterDefineText); //Util.Debug(false, res.GetType().ToString()); sys.SetResourceDependency(res); tagList.Add(sys); } } else { tagList.Add(tag); } //Util.Debug(false, "#####\n" + tag.OuterDefineText + "\n#####"); //TagList.Add(tag); idxBegin = tag.DefinedIndexEnd; mc = regEx.Matches(tagdef, idxBegin); } if (idxBegin < tagdef.Length) { htmlTag = new HtmlTextTag(tagdef.Substring(idxBegin)); tagList.Add(htmlTag); } }
/// <summary> /// 解析模板内容 /// </summary> public void SetTaggedObjectCollection(string tptContent) { StringBuilder sb = new StringBuilder(tptContent.Length); Regex regEx = new Regex(TagBase.TagDefinitionPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); int idxBegin = 0, idxEnd = 0; //Util.Debug(false, "------------------------begin---------------"); MatchCollection mc = regEx.Matches(tptContent, idxBegin); while (mc.Count > 0) { Match m = mc[0]; idxEnd = m.Index; if (idxEnd > idxBegin) { //Util.Debug(false, tptContent.Substring(idxBegin, idxEnd - idxBegin)); sb.Append(tptContent.Substring(idxBegin, idxEnd - idxBegin)); } TagBase tag = new TagBase(m.Value, m.Index, ref tptContent); //Util.Debug(false, "#####\n" + tag.OuterDefineText + " " + tag.Category.ToString() + "\n#####"); //OleDbHelper.AppendToFile("~/debug.log", "parse Tag..." + tag.OuterDefineText + " \r\n " + tag.Category.ToString() + Environment.NewLine + Environment.NewLine); #region 处理标签内容 if (tag.Category == TagCategory.CustomTag) { DbStoredCustomTag dbTag = DbStoredCustomTag.Parse(tag); dbTag.SetResourceDependency(this.GetResourceDependency()); //Util.Debug(false, "tpp: " + this.GetResourceDependency() + dbTag.OuterDefineText); if (dbTag.IsExist == true) { dbTag.Caller = this; sb.Append(dbTag.GetTagValue()); if (!this.TagTrack.ContainsKey("B" + dbTag.IDentity)) { this.TagTrack.Add("B" + dbTag.IDentity, dbTag.PublishDate.ToString("yyyyMMddHHmmss")); } } } else if (tag.Category == TagCategory.DataListTag) { //{#List:Repeater#} ListTag list = ListTag.Parse(tag, this.GetResourceDependency()); //OleDbHelper.AppendToFile("~/debug.log", System.Environment.NewLine + " Res:" // + this.GetResourceDependency().ToString()); if (this.GeneratorListContent == true) { #region 直接获取列表标签内容 if (list.GetPageCount() < 2) { sb.Append(list.GetTagValue()); } else { string pagedAliaContent = (string.IsNullOrEmpty(list.IDentity)) ? new Guid().ToString() : list.IDentity; SetDynamicPagedAlia(pagedAliaContent, list); sb.Append(pagedAliaContent); } #endregion } else { //设置列表标签占位符号 string pagedAliaContent = (string.IsNullOrEmpty(list.IDentity)) ? new Guid().ToString() : list.IDentity; SetDynamicPagedAlia(pagedAliaContent, list); sb.Append(pagedAliaContent); } } else if (tag.Category == TagCategory.PagerTag) { //{#Pager#} PagerTag pager = PagerTag.Parse(tag); string pagerAlia = (string.IsNullOrEmpty(pager.IDentity)) ? new Guid().ToString() : pager.IDentity; SetDynamicPagerDependency(pagerAlia, pager); sb.Append(pagerAlia); } else if (tag.Category == TagCategory.ServerTag) { //服务端标签定义格式为 } else if (tag.Category == TagCategory.SystemTag) { //系统标签(函数)定义格式为 {#$ $#} {# ... () ... #} // 系统标签: {#$this.PrimaryNews["Content"]$#} if (tag.OuterDefineText.StartsWith("{#$this.") && this._resDependency != null) { sb.Append(this.GetResourceDependency().GetDefinition(tag.OuterDefineText)); } else { SystemTag sysTag = new SystemTag(tag.TagDefinition); sysTag.SetResourceDependency(GetResourceDependency()); sb.Append(sysTag.ToString()); } //Util.Debug(false, tag.OuterDefineText); //OleDbHelper.AppendToFile("~/log.txt", tag.OuterDefineText); } else if (tag.Category == TagCategory.DefineTag) { //数据库标签定义格式为 {#%FieldName%#} if (this._resDependency != null) { //Util.Debug(false, tag.OuterDefineText); sb.Append(this.GetResourceDependency().GetDefinition(tag.OuterDefineText)); } } #endregion idxBegin = tag.DefinedIndexEnd; //Util.Debug(false, tptContent.Substring(idxBegin, 5)); //Util.Debug(m.Value); mc = regEx.Matches(tptContent, idxBegin); } if (idxBegin < tptContent.Length) { sb.Append(tptContent.Substring(idxBegin)); //Util.Debug(false, tptContent.Substring(idxBegin)); } this.ParsedResult = sb.ToString(); //Util.Debug(false, "------------------------End---------------"); //OleDbHelper.SetTextFileContent(@"~/@docs/temp.html", "utf-8", // HtmlTextGenerator.GetRightHtmlText("/templet/1/", sb.ToString())); }