protected override void TagCreator() { XhtmlElement tag = null; if (this.HasLinkForPart)///当Part本身有连接时的处理 { tag = this.ParentXhtmlElement.OwnerPage.CreateXhtmlA(); XhtmlTags.A tagA = (XhtmlTags.A)tag; tagA.Builder("", "", Xhtml.Target._blank, 0, 'a'); this.ParentXhtmlElement.AppendChild(tag); } if (tag == null)///当为Null时,即为该Part没有设置链接 { tag = this.ParentXhtmlElement; } switch (this.SnipPartType) { case SnipPartType.Static: ///静态Part的生成,比较简单 case SnipPartType.Navigation: ///导航Part的生成实际上与静态Part没有区别 #region 针对静态Part的值生成部份Html代码 { if (!string.IsNullOrEmpty(this.CDataValue)) { StringBuilder sb = new StringBuilder(); sb.Append(TempCDataTag.CDataTag).Append(this.CDataValue).Append(TempCDataTag.CDataTag); XhtmlElement htmlele = tag.OwnerPage.CreateXhtmlCData(sb.ToString()); tag.AppendChild(htmlele); } break; } #endregion case SnipPartType.List: base.TagCreator(); break; case SnipPartType.ListBox: base.TagCreator(); break; case SnipPartType.Box: base.TagCreator(); break; case SnipPartType.Path: base.TagCreator(); break; case SnipPartType.Attribute: ///定制特性的SnipPart { this.AttributeTagCreator(tag); break; } case SnipPartType.None: default: break; }//switch this.XhtmlElement = tag; }
/// <summary> /// 设置本节点在生成Xhtml时的标签,默认是div /// </summary> protected virtual void TagCreator() { XhtmlSection ownerPage = (XhtmlSection)this._ParentXhtmlElement.OwnerPage; this._XhtmlElement = ownerPage.CreateXhtmlDiv(); this._ParentXhtmlElement.AppendChild(this._XhtmlElement); }
public void CanBeParsedFromLocalFiles() { const string path = @".\Files\arstechnica.html"; var fileInfo = new System.IO.FileInfo(path); Assert.IsTrue(fileInfo.Exists); var location = new Uri(fileInfo.FullName); var xhtml = XhtmlElement.Parse(location); MakeDocumentAssertions(xhtml); }
private void AttributeTagCreator(XhtmlElement tag) { if (string.IsNullOrEmpty(this.AttributeName)) { return; } PropertyInfo pi = PageAttributeService.GetPropertyInfo(this.AttributeName, this.PageXmlDocument.GetType()); object outvalue = pi.GetValue(this.PageXmlDocument, null); if (outvalue == null)///当通过定制特性取出值为空时 { return; } string outObjType = outvalue.GetType().FullName; switch (outObjType) { case "System.String": { XhtmlTags.P ptag = tag.OwnerPage.CreateXhtmlP(); ptag.AppendText((string)outvalue); tag.AppendChild(ptag); break; } case "System.String[]": { XhtmlTags.Ul ultag = tag.OwnerPage.CreateXhtmlUl(); foreach (string str in (Array)outvalue) { XhtmlTags.Li liTag = tag.OwnerPage.CreateXhtmlLi(); liTag.AppendText(str); ultag.AppendChild(liTag); } tag.AppendChild(ultag); break; } case "Jeelu.DepartmentData": { DepartmentData ddata = (DepartmentData)outvalue; ///Todo:lukan,2008-7-3 12:39:30, ///严重的漏设计项目,联系人众多的属性用户不能设计显示方式 XhtmlTags.P ptag = tag.OwnerPage.CreateXhtmlP(); ptag.AppendText("(DepartmentData)outvalue!"); tag.AppendChild(ptag); break; } case "System.Single": { XhtmlTags.P ptag = tag.OwnerPage.CreateXhtmlP(); ptag.AppendText(outvalue.ToString()); tag.AppendChild(ptag); break; } case "Jeelu.ProductImageData": { break; } case "Jeelu.SimplusD.ItemCollection": { //Jeelu.SimplusD.ItemCollection break; } default: Debug.Fail(outObjType + " is Error Dispose Type!"); break; } //switch (outObjType) } //private void AttributeTagCreator
/// <summary> /// 根据当前节点的特性来设置该节点 /// </summary> protected virtual void MarkXhtmlElement(PageSection pageSection) { switch (pageSection) { case PageSection.MainPage: { _XhtmlElement = new XhtmlSection(); string tmpltFullFile = this.ToHtmlHelper.TmpltRelativeUrl; XhtmlElement tag = _XhtmlElement.CreateXhtmlCommentShtml (tmpltFullFile + this.SdsiteElement.TmpltId + Utility.Const.ShtmlFileExt); _XhtmlElement.AppendChild(tag); this._isAlreadyToMainPageHtml = true; break; } case PageSection.Head: { _HeadXhtmlElement = new XhtmlSection(); #region Title XhtmlTagElement title = _HeadXhtmlElement.CreateXhtmlTitle(); title.InnerText = this.Title; _HeadXhtmlElement.AppendChild(title); #endregion #region keywords XhtmlAtts.Name name; StringBuilder sb; XhtmlAtts.Content content; if (!(this.PageKeywords == null)) { name = new XhtmlAtts.Name("keywords"); sb = new StringBuilder(); foreach (string str in this.PageKeywords) { sb.Append(str).Append(','); } content = new XhtmlAtts.Content(sb.ToString().TrimEnd(',')); XhtmlTagElement keyword = _HeadXhtmlElement.CreateXhtmlMeta(name, content); _HeadXhtmlElement.AppendChild(keyword); } #endregion #region description name = new XhtmlAtts.Name("description"); content = new XhtmlAtts.Content(this.PageSummary); XhtmlTagElement description = _HeadXhtmlElement.CreateXhtmlMeta(name, content); _HeadXhtmlElement.AppendChild(description); #endregion this._isAlreadyToHeadHtml = true; break; } case PageSection.Content: { SdsiteXmlDocument doc = (SdsiteXmlDocument)this.SdsiteElement.OwnerAnyDocument; string tmpltId = this.SdsiteElement.TmpltId; TmpltXmlDocument tmplt = doc.GetTmpltDocumentById(this.SdsiteElement.TmpltId); XhtmlSection ele = (XhtmlSection)tmplt.GetContentSnipEle().XhtmlElement; if (ele == null) { SnipXmlElement snip = tmplt.GetContentSnipEle(); snip.MarkXhtmlElement(this); ele = (XhtmlSection)tmplt.GetContentSnipEle().XhtmlElement; } _ContentXhtmlElement = ele; this._isAlreadyToContentHtml = true; break; } case PageSection.None: default: break; } }
/// <summary> /// 根据当前模板的特性来设置该节点 /// </summary> protected virtual void MarkXhtmlElement() { XhtmlPage ownerPage = (XhtmlPage)this._ParentXhtmlElement.OwnerPage; //<meta http-equiv="Expires" content="Fri, 26 Mar 1999 23:59:59 GMT"> //<meta http-equiv="pragma" content="no-cache"> //<meta name="Author" content="Apple Inc."> //<meta name="Keywords" content="Apple"> //<link rel="home" href="http://www.apple.com/"> //<link rel="alternate" type="application/rss+xml" title="RSS" href="http://images.apple.com/main/rss/hotnews/hotnews.rss"> //<link rel="index" href="http://www.apple.com/find/sitemap.html"> #region Meta: Content-Type XhtmlAtts.Http_equiv httpEquiv = new XhtmlAtts.Http_equiv(Xhtml.Http_equiv.content_type); XhtmlAtts.Content content = new XhtmlAtts.Content("text/html; charset=utf-8"); XhtmlTagElement contentType = ownerPage.CreateXhtmlMeta(httpEquiv, content); ownerPage.Head.AppendChild(contentType); #endregion //<!--#include virtual="http://ssi.jeelu.com/GetHtml.cgi?domain=$SERVER_ADDR&dir=$DOCUMENT_URI&filename=asdfads"--> SdCgiObject cgi = new SdCgiObject(CgiPlace.Head); ownerPage.Head.AppendChild(ownerPage.CreateXhtmlCommentShtml(cgi)); #region Meta: Power #if !DEBUG string version = Application.ProductVersion; XhtmlAtts.Name name = new XhtmlAtts.Name("Generator"); content = new XhtmlAtts.Content("网站360°: v" + version + ",http://www.SimplusD.com"); XhtmlTagElement power = ownerPage.CreateXhtmlMeta(name, content); ownerPage.Head.AppendChild(power); #endif #endregion XhtmlElement mainElement = ownerPage.CreateXhtmlDiv(); this._XhtmlElement.AppendChild(mainElement); #region 辩别生成效果 #if DEBUG mainElement.SetAttribute("name", "tmplt"); #endif #endregion /// this.GetRectsElement().ChildNodes[0]是指的rects节点下的第一个节点,一般是rect /// 按照SimplusD的规则,这个节点有仅有一个rect节点 XmlNode firstNode = null; if (this.GetRectsElement().ChildNodes[0] is SnipXmlElement) { firstNode = this.GetRectsElement();///当一个模板里只有一个页面片时的特殊情况处理 } else { firstNode = this.GetRectsElement().ChildNodes[0]; } foreach (XmlNode node in firstNode.ChildNodes)///遍历子节点,通过Element的继承关系递归 { if (node.NodeType != XmlNodeType.Element) { continue; } if (node is ToHtmlXmlElement)///当节点是继承自ToHtmlXmlElement,即可以生成页面 { ToHtmlXmlElement htmlNode = (ToHtmlXmlElement)node; htmlNode.ParentXhtmlElement = mainElement; ///下一级节点的父节点即为本节点 htmlNode.ToHtml(); ///调用下一级节点的ToHtml } } this._isAlreadyToHtml = true;///已经ToHtml的标记 }