/// <summary> /// 开始解析标签数据 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="tagStack">标签堆栈</param> /// <param name="text"></param> /// <param name="match"></param> /// <param name="isClosedTag">是否闭合标签</param> /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns> internal override bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack <Tag> tagStack, string text, ref Match match, bool isClosedTag) { //将自身加入到宿主的子模板列表中 ownerTemplate.ChildTemplates.Add(this); //加入到标签容器的元素列表中 container.AppendChild(this); if (!string.IsNullOrEmpty(this.File)) { //修正文件地址 this.File = Utility.ResolveFilePath(this.Parent, this.File); if (System.IO.File.Exists(this.File)) { //增加到依赖文件列表 this.OwnerTemplate.AddFileDependency(this.File); //读取文件数据进行解析 new TemplateDocument(this, System.IO.File.ReadAllText(this.File, this.Charset), ownerTemplate.OwnerDocument.DocumentConfig); } } //非闭合标签则查找结束标签 if (!isClosedTag) { this.ProcessEndTag(this, this, tagStack, text, ref match); } //因为已处理EndTag.所以不需要外部继续再处理 return(false); }
/// <summary> /// 拷贝自身数据对某个新对象上 /// </summary> /// <param name="tag"></param> protected virtual void CopyTo(Tag tag) { tag.Id = this.Id; tag.Name = this.Name; foreach (var att in this.Attributes) { tag.Attributes.Add(att.Clone(tag.OwnerTemplate)); } foreach (Element element in this.InnerElements) { tag.AppendChild(element.Clone(tag.OwnerTemplate)); } }
/// <summary> /// 构建变量标签元素 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="match"></param> internal static VariableTag CreateVariableTag(Template ownerTemplate, Tag container, Match match) { string prefix; Variable variable = CreateVariable(ownerTemplate, match, out prefix); VariableIdentity variableId = new VariableIdentity(ownerTemplate, variable, prefix); //变量标签元素则需要缓存表达式的值 VariableExpression varExp = CreateVariableExpression(variableId, match, true); VariableTag tag = new VariableTag(ownerTemplate, varExp); //解析属性列表 ParseElementAttributes(tag, match); container.AppendChild(tag); return tag; }
/// <summary> /// 开始解析标签数据 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="tagStack">标签堆栈</param> /// <param name="text"></param> /// <param name="match"></param> /// <param name="isClosedTag">是否闭合标签</param> /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns> internal override bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack <Tag> tagStack, string text, ref Match match, bool isClosedTag) { if (this.VarExpression == null) { throw new ParserException(string.Format("{0}标签中缺少var属性", this.TagName)); } if (this.Values.Count == 0) { throw new ParserException(string.Format("{0}标签中缺少value属性", this.TagName)); } //闭合标签则不进行数据处理 if (!isClosedTag) { container.AppendChild(this); } return(!isClosedTag); }
/// <summary> /// 构建文本节点元素 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="text"></param> /// <param name="offset"></param> /// <param name="length"></param> internal static void CreateTextNode(Template ownerTemplate, Tag container, string text, int offset, int length) { if (length > 0) { string content = text.Substring(offset, length); if (ownerTemplate.OwnerDocument.DocumentConfig != null && ownerTemplate.OwnerDocument.DocumentConfig.CompressText) { //压缩文本 content = Utility.CompressText(content); } if (content.Length > 0) { //不建立空行文本节点 if(content.TrimStart('\r','\n','\t').Length != 0) container.AppendChild(new TextNode(ownerTemplate, content)); } } }
/// <summary> /// 开始解析标签数据 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="tagStack">标签堆栈</param> /// <param name="text"></param> /// <param name="match"></param> /// <param name="isClosedTag">是否闭合标签</param> /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns> internal override bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack<Tag> tagStack, string text, ref Match match, bool isClosedTag) { container.AppendChild(this); if (!string.IsNullOrEmpty(this.File)) { //修正文件地址 this.File = Utility.ResolveFilePath(this.Parent, this.File); if (System.IO.File.Exists(this.File)) { //增加到依赖文件列表 this.OwnerTemplate.AddFileDependency(this.File); //解析数据 new TemplateDocument(ownerTemplate, this, System.IO.File.ReadAllText(this.File, this.Charset), ownerTemplate.OwnerDocument.DocumentConfig); } } return !isClosedTag; }
/// <summary> /// 开始解析标签数据 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="tagStack">标签堆栈</param> /// <param name="text"></param> /// <param name="match"></param> /// <param name="isClosedTag">是否闭合标签</param> /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns> internal override bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack <Tag> tagStack, string text, ref Match match, bool isClosedTag) { container.AppendChild(this); if (!string.IsNullOrEmpty(this.File)) { //修正文件地址 this.File = Utility.ResolveFilePath(this.Parent, this.File); if (System.IO.File.Exists(this.File)) { //增加到依赖文件列表 this.OwnerTemplate.AddFileDependency(this.File); //解析数据 new TemplateDocument(ownerTemplate, this, System.IO.File.ReadAllText(this.File, this.Charset), ownerTemplate.OwnerDocument.DocumentConfig); } } return(!isClosedTag); }
/// <summary> /// 开始解析标签数据 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="tagStack">标签堆栈</param> /// <param name="text"></param> /// <param name="match"></param> /// <param name="isClosedTag">是否闭合标签</param> /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns> internal virtual bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack <Tag> tagStack, string text, ref Match match, bool isClosedTag) { container.AppendChild(this); return(!isClosedTag); }
/// <summary> /// 开始解析标签数据 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="tagStack">标签堆栈</param> /// <param name="text"></param> /// <param name="match"></param> /// <param name="isClosedTag">是否闭合标签</param> /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns> internal virtual bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack<Tag> tagStack, string text, ref Match match, bool isClosedTag) { container.AppendChild(this); return !isClosedTag; }
/// <summary> /// 开始解析标签数据 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="tagStack">标签堆栈</param> /// <param name="text"></param> /// <param name="match"></param> /// <param name="isClosedTag">是否闭合标签</param> /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns> internal override bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack<Tag> tagStack, string text, ref Match match, bool isClosedTag) { if (this.VarExpression == null) throw new ParserException(string.Format("{0}标签中缺少var属性", this.TagName)); if (this.Values.Count == 0) throw new ParserException(string.Format("{0}标签中缺少value属性", this.TagName)); //闭合标签则不进行数据处理 if (!isClosedTag) { container.AppendChild(this); } return !isClosedTag; }
/// <summary> /// 开始解析标签数据 /// </summary> /// <param name="ownerTemplate">宿主模板</param> /// <param name="container">标签的容器</param> /// <param name="tagStack">标签堆栈</param> /// <param name="text"></param> /// <param name="match"></param> /// <param name="isClosedTag">是否闭合标签</param> /// <returns>如果需要继续处理EndTag则返回true.否则请返回false</returns> internal override bool ProcessBeginTag(Template ownerTemplate, Tag container, Stack<Tag> tagStack, string text, ref Match match, bool isClosedTag) { //将自身加入到宿主的子模板列表中 ownerTemplate.ChildTemplates.Add(this); //加入到标签容器的元素列表中 container.AppendChild(this); if (!string.IsNullOrEmpty(this.File)) { //修正文件地址 this.File = Utility.ResolveFilePath(this.Parent, this.File); if (System.IO.File.Exists(this.File)) { //增加到依赖文件列表 this.OwnerTemplate.AddFileDependency(this.File); //读取文件数据进行解析 new TemplateDocument(this, System.IO.File.ReadAllText(this.File, this.Charset), ownerTemplate.OwnerDocument.DocumentConfig); } } //非闭合标签则查找结束标签 if (!isClosedTag) { this.ProcessEndTag(this, this, tagStack, text, ref match); } //因为已处理EndTag.所以不需要外部继续再处理 return false; }