/// <summary> /// 标签处理虚方法 /// </summary> /// <param name="urlInfo"></param> /// <param name="site"></param> /// <param name="skin"></param> /// <param name="page"></param> /// <param name="pageCode"></param> public virtual void Parse(MaUrl urlInfo, IMaSite site, IMaSkin skin, MaPage page, ref StringBuilder pageCode) { if (string.IsNullOrEmpty(m_tagRegexStr)) { throw new Exception("解析表情出错,当前类没有标签匹配字符串串,请给[TagRegexStr]赋值"); } //查询的正则表达式 Regex re = new Regex(m_tagRegexStr, RegexOptions.IgnoreCase); MatchCollection matches = re.Matches(pageCode.ToString()); foreach (Match var in matches) { MaTag _maTag = new MaTag(var.Value, urlInfo); ParseTag(urlInfo, site, skin, page, ref pageCode, _maTag); } }
/// <summary> /// 默认模板替换函数 /// </summary> /// <param name="urlInfo"></param> /// <param name="site"></param> /// <param name="skin"></param> /// <param name="page"></param> /// <param name="pageCode"></param> /// <param name="tag"></param> public override void ParseTag(Page.MaUrl urlInfo, IMaSite site, IMaSkin skin, Page.MaPage page, ref StringBuilder pageCode, MaTag tag) { //模板名称 string _tName = tag["tmp"]; string _templateStr; if (!skin.TryGetTemplate(_tName, out _templateStr)) { _templateStr = "<!--获取模板文件[" + _tName + "]出错-->"; throw new Exception("获取模板文件[" + _tName + "]出错,【" + urlInfo.ToString() + "】"); } pageCode = pageCode.Replace(tag.TagStr, _templateStr); }
/// <summary> /// 标签处理抽象函数 /// </summary> /// <param name="urlInfo"></param> /// <param name="site"></param> /// <param name="skin"></param> /// <param name="page"></param> /// <param name="pageCode"></param> /// <param name="tag"></param> public abstract void ParseTag(MaUrl urlInfo, IMaSite site, IMaSkin skin, MaPage page, ref StringBuilder pageCode, MaTag tag);