/// <summary> /// Converts a UfDataNode structure into a very basic form HTML. /// </summary> /// <param name="node">Node</param> /// <param name="formatDescriber">Microformat format describer object</param> /// <returns>HTML string</returns> public string Convert(UfDataNode node, UfFormatDescriber formatDescriber) { string output = string.Empty; StringWriter stringWriter = new StringWriter(); UfElementDescriber elementDescriber = formatDescriber.BaseElement; using (XhtmlTextWriter writer = new XhtmlTextWriter(stringWriter)) { writer.WriteBeginTag("div"); writer.WriteAttribute("class", "microformats"); writer.Write(HtmlTextWriter.TagRightChar); foreach (UfDataNode child in node.Nodes) { writer.WriteLine(); AddNode(child, elementDescriber, writer); } writer.WriteEndTag("div"); writer.WriteLine(); } return(stringWriter.ToString()); }
public UfElementDescriber this[string name] { get { UfElementDescriber elementDescriber = null; for (int i = 0; i < this.InnerList.Count; i++) { UfElementDescriber testNode = (UfElementDescriber)this.InnerList[i]; if (testNode.Name == name) { return(testNode); } } return(elementDescriber); } }
public static UfFormatDescriber Bookmark() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "bookmark"; uFormat.Description = "Bookmark"; uFormat.Type = UfFormatDescriber.FormatTypes.Elemental; UfElementDescriber uFElement = new UfElementDescriber(); uFElement.Name = "bookmark"; uFElement.AllowedTags.Add("a"); uFElement.AllowedTags.Add("link"); uFElement.Attribute = "rel"; uFElement.Type = UfElementDescriber.PropertyTypes.UrlText; uFormat.BaseElement = uFElement; uFElement.AttributeValues.Add(new UfAttributeValueDescriber("bookmark")); return uFormat; }
private void AddChildNodes(UfDataNode xNode, UfDataNode node, UfElementDescriber ufElement) { //if (!string.IsNullOrEmpty(node.ElementId)) //{ // xNode.Nodes.Add("id", node.ElementId); //} if (ufElement.AttributeValues.Count > 0) { // If its a rel or rev uf based on attribute values, just copy it // UfDataNode xNodeChild = xNode.Nodes.Append(node.Name, node.Value); foreach (UfDataNode childNode in node.Nodes) { xNode.Nodes.Add(childNode.Name, childNode.Value, childNode.SourceUrl, childNode.RepresentativeNode); } } foreach (UfElementDescriber childElement in ufElement.Elements) { // Loop orginal data tree foreach (UfDataNode childNode in node.Nodes) { // If node name = element describer name if (childNode.Name == childElement.Name || childNode.Name == childElement.CompoundName) { // If element can have multiples call the AppendArrayList method if (childElement.Multiples) { UfDataNode xChild = xNode.Nodes.Append(childNode.Name, childNode.Value, childNode.SourceUrl, childNode.RepresentativeNode); AddChildNodes(xChild, childNode, childElement); } else { int index = xNode.Nodes.Add(childNode.Name, childNode.Value, childNode.SourceUrl, childNode.RepresentativeNode); UfDataNode xChild = xNode.Nodes[index]; AddChildNodes(xChild, childNode, childElement); } } } } }
public static UfFormatDescriber Tag() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "tag"; uFormat.Description = "Tag"; uFormat.Type = UfFormatDescriber.FormatTypes.Elemental; UfElementDescriber uFElement = new UfElementDescriber(); uFElement.Name = "tag"; uFElement.Multiples = true; uFElement.AllowedTags.Add("a"); uFElement.AllowedTags.Add("link"); uFElement.Attribute = "rel"; uFElement.Type = UfElementDescriber.PropertyTypes.UrlTextTag; uFormat.BaseElement = uFElement; uFElement.AttributeValues.Add(new UfAttributeValueDescriber("tag")); return uFormat; }
public static UfFormatDescriber VoteLinks() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "votelinks"; uFormat.Description = "Vote Links"; uFormat.Type = UfFormatDescriber.FormatTypes.Elemental; UfElementDescriber uFElement = new UfElementDescriber(); uFElement.AllowedTags.Add("a"); uFElement.AllowedTags.Add("link"); uFElement.Attribute = "rel"; uFElement.Type = UfElementDescriber.PropertyTypes.UrlTextAttribute; uFormat.BaseElement = uFElement; uFElement.AttributeValues.Add(new UfAttributeValueDescriber("vote-for", "vote-abstain vote-against")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("vote-against", "vote-abstain vote-for")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("vote-abstain", "vote-for vote-against")); return uFormat; }
public void Remove(UfElementDescriber aElement) { InnerList.Remove(aElement); }
public static UfFormatDescriber NoFollow() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "nofollow"; uFormat.Description = "Stops search engines following links"; uFormat.Type = UfFormatDescriber.FormatTypes.Elemental; UfElementDescriber uFElement = new UfElementDescriber(); uFElement.Name = "nofollow"; uFElement.AllowedTags.Add("a"); uFElement.AllowedTags.Add("link"); uFElement.Attribute = "rel"; uFElement.Type = UfElementDescriber.PropertyTypes.UrlText; uFormat.BaseElement = uFElement; uFElement.AttributeValues.Add(new UfAttributeValueDescriber("nofollow")); return uFormat; }
public int IndexOf(UfElementDescriber aElement) { return(InnerList.IndexOf(aElement)); }
private void ParseUfElementValue(HtmlNode baseNode, UfElementDescriber ufElement, UfDataNode ufData) { // Create a single data node for whatever data insertion is needed. UfDataNode ufd = new UfDataNode(); if(ufElement.CompoundName != string.Empty) ufd.ParentNodeNames = ufData.ParentNodeNames + ufElement.CompoundName + " "; else ufd.ParentNodeNames = ufData.ParentNodeNames + ufElement.Name + " "; ufd.ElementId = GetAttributeValue(baseNode, "id"); // A parent node in the data schema if (ufElement.Elements.Count > 0) { if (ufElement.CompoundName == string.Empty) { // Add a emtpy structural node ufd.Name = ufElement.Name; } else { // This is for compound structures, ie reviewer in hreview is a hcard // Need to find a second attribute value to do this HtmlAttribute att = baseNode.Attributes[ufElement.CompoundAttribute]; if (att != null) { if (UfHelpers.FindAttributeValue(att.Value.ToLower(), ufElement.CompoundName)) { // Add a emtpy structural node using compound name ufd.Name = ufElement.CompoundName; } } } // Recursion through the dom structure foreach (UfElementDescriber ufChildElement in ufElement.Elements) ParseUfElement(baseNode, ufChildElement, ufd, false); } // A value needs to be found if (ufElement.Type != UfElementDescriber.PropertyTypes.None) { // Find child nodes with "value" or "value-title" classes HtmlNodeCollection valueNodes = null; HtmlNodeCollection valueTitleNodes = null; // The value pattern if (ufElement.Elements["value"] == null && ufElement.Name != "value") { valueNodes = baseNode.SelectNodes(".//*[contains(concat(' ', @class, ' '),' value ')]"); } // The value-title pattern is only allow for some property types ie dates // or name properties ie type, duration, geo, latitude and longitude if (ufElement.Type == UfElementDescriber.PropertyTypes.Date || ufElement.Name == "type" || ufElement.Name == "duration" || ufElement.Name == "geo" || ufElement.Name == "latitude" || ufElement.Name == "longitude") { valueTitleNodes = baseNode.SelectNodes(".//*[contains(concat(' ', @class, ' '),' value-title ')]"); } if (ufElement.Type == UfElementDescriber.PropertyTypes.UrlTextAttribute || ufElement.Type == UfElementDescriber.PropertyTypes.UrlTextTag || ufElement.Type == UfElementDescriber.PropertyTypes.UrlText) { string text = UfHelpers.HtmlToText(baseNode, false); string link = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "href"), this.baseUrl, url); string att = GetAttributeValue(baseNode, ufElement.Attribute); ufd.Name = ufElement.Name; UfDataNode ufd1 = new UfDataNode(); UfDataNode ufd2 = new UfDataNode(); UfDataNode ufd3 = new UfDataNode(); ufd1.Name = "text"; ufd1.Value = text; ufd.Nodes.Add(ufd1); ufd2.Name = "link"; ufd2.Value = link; ufd.Nodes.Add(ufd2); // Add the attribute value used for XFN like structures if (ufElement.Type == UfElementDescriber.PropertyTypes.UrlTextAttribute) { ufd3.Name = ufElement.Attribute; ufd3.Value = att; ufd.Nodes.Add(ufd3); } // Add the tag element of the url if (ufElement.Type == UfElementDescriber.PropertyTypes.UrlTextTag) { ufd3.Name = "tag"; ufd3.Value = UfHelpers.GetTagFromUrl(link); ufd.Nodes.Add(ufd3); } if (ufElement.CompoundName == string.Empty) { ufData.Nodes.Add(ufd); } else { HtmlAttribute att1 = baseNode.Attributes[ufElement.CompoundAttribute]; if (att1 != null) { if (UfHelpers.FindAttributeValue(att1.Value.ToLower(), ufElement.CompoundName)) { ufd.Name = ufElement.CompoundName; ufData.Nodes.Add(ufd); } } } } // The value excerpting pattern else if (valueNodes != null) { string text = string.Empty ; foreach (HtmlNode node in valueNodes) { if (node.Name == "img" || node.Name == "area") { if (ufElement.Type == UfElementDescriber.PropertyTypes.Date) text += GetAttributeValue(node, "title").Replace(" ", "") + " "; else text += GetAttributeValue(node, "title"); } else if (node.Name == "abbr") { if (ufElement.Type == UfElementDescriber.PropertyTypes.Date) text += GetAttributeValue(node, "title").Replace(" ", "") + " "; else text += GetAttributeValue(node, "title"); } else { if (ufElement.Type == UfElementDescriber.PropertyTypes.Date) text += UfHelpers.HtmlToText(node, false).Replace(" ", "") + " "; else text += UfHelpers.HtmlToText(node, false) + " "; } } if(ufElement.Type == UfElementDescriber.PropertyTypes.Date) { // Take the fagmented bits and create a true ISODateTime string ISODateTime isoDateTime = new ISODateTime(); text = isoDateTime.ParseUFFragmented(text); } ufd.Name = ufElement.Name; ufd.Value = text.Trim(); AddNewDateNode(baseNode, ufData, ufd, ufElement); } // The value-title excerpting pattern else if (valueTitleNodes != null) { string text = GetAttributeValue(valueTitleNodes[0], "title"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Url from "a" or "link" else if ((baseNode.Name == "a" || baseNode.Name == "link") && GetAttributeValue(baseNode, "href") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Url) { string link = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "href"), this.baseUrl, url); ufd.Name = ufElement.Name; ufd.Value = link; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Url from "img" else if ((baseNode.Name == "img" || baseNode.Name == "area") && GetAttributeValue(baseNode, "src") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Url) { string link = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "src"), this.baseUrl, url); ufd.Name = ufElement.Name; ufd.Value = link; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Email from "a" or "link" else if (baseNode.Name == "a" && GetAttributeValue(baseNode, "href") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Email) { string address = UfHelpers.CleanEmailAddress(GetAttributeValue(baseNode, "href")); ufd.Name = ufElement.Name; ufd.Value = address; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Tel from "object" else if (baseNode.Name == "object" && (GetAttributeValue(baseNode, "data") != "") && ufElement.Name == "tel") { UfHelpers.TelOptimization(ufd, GetAttributeValue(baseNode, "data")); AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Date from "time" else if (baseNode.Name == "time" && GetAttributeValue(baseNode, "datetime") != "" && ufElement.Type == UfElementDescriber.PropertyTypes.Date) { string text = GetAttributeValue(baseNode, "datetime"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Date from "abbr" else if (baseNode.Name == "abbr" && GetAttributeValue(baseNode, "title") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Date) { string text = GetAttributeValue(baseNode, "title"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text from "abbr" else if (baseNode.Name == "abbr" || baseNode.Name == "acronym" && GetAttributeValue(baseNode, "title") != string.Empty) { string text = GetAttributeValue(baseNode, "title"); ufd.Name = ufElement.Name; // This is for geo been used as a location in hcalandar if (ufElement.CompoundName != string.Empty) ufd.Name = ufElement.CompoundName; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text from "input" else if (baseNode.Name == "input" && GetAttributeValue(baseNode, "value") != string.Empty) { string text = GetAttributeValue(baseNode, "value"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Tel from "area" else if (baseNode.Name == "area" && (GetAttributeValue(baseNode, "href") != "") && ufElement.Name == "tel") { UfHelpers.TelOptimization(ufd, GetAttributeValue(baseNode, "href")); AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text and url from "area" else if (baseNode.Name == "area" && (GetAttributeValue(baseNode, "href") != string.Empty || GetAttributeValue(baseNode, "alt") != string.Empty)) { if ((ufElement.Type == UfElementDescriber.PropertyTypes.Url || ufElement.Type == UfElementDescriber.PropertyTypes.Email) && GetAttributeValue(baseNode, "href") != string.Empty) { string text = GetAttributeValue(baseNode, "href"); if (ufElement.Type == UfElementDescriber.PropertyTypes.Email) text = UfHelpers.CleanEmailAddress(text); if (ufElement.Type == UfElementDescriber.PropertyTypes.Url) text = UfHelpers.GetAbsoluteUrl(text, this.baseUrl, url); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } else if (GetAttributeValue(baseNode, "alt") != string.Empty) { string text = GetAttributeValue(baseNode, "alt"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } } // Url/Image from "object" else if (baseNode.Name == "object" && GetAttributeValue(baseNode, "data") != string.Empty && (ufElement.Type == UfElementDescriber.PropertyTypes.Url || ufElement.Type == UfElementDescriber.PropertyTypes.Image)) { string text = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "data"), this.baseUrl, url); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Image from "img" or "area" else if ((baseNode.Name == "img" || baseNode.Name == "area") && GetAttributeValue(baseNode, "src") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Image) { string text = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "src"), this.baseUrl, url); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text from "img" longdesc attribute else if (baseNode.Name == "img" && GetAttributeValue(baseNode, "longdesc") != string.Empty) { string text = GetAttributeValue(baseNode, "longdesc"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); ; } // Text from "img" alt attribute else if (baseNode.Name == "img" && GetAttributeValue(baseNode, "alt") != string.Empty) { string text = GetAttributeValue(baseNode, "alt"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text for type/value structures with no found children else if (ufElement.NodeType == UfElementDescriber.StructureTypes.TypeValuePair) { // if no chidren nodes ie type/value are found use text // the calls for a children node type and value are alway both thier parent if (ufd.Nodes.Count == 0) { // Add text from node value string text = UfHelpers.HtmlToText(baseNode, false); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } else { // Add child type/value pair ufd.Name = ufElement.Name; AddNewDateNode(baseNode, ufData, ufd, ufElement); } } // Text from Html node collect else if (ufElement.Type == UfElementDescriber.PropertyTypes.FormattedText) { string text = UfHelpers.HtmlToText(baseNode, true); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } else { // Text from node value //string text = FindValuePattern(baseNode, ufElement); //if(text == string.Empty) // text = HtmlToText(baseNode, false); string text = UfHelpers.HtmlToText(baseNode, false); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } } else { AddNewDateNode(baseNode, ufData, ufd, ufElement); } }
private void ParseUfElementValue(HtmlNode baseNode, UfElementDescriber ufElement, UfDataNode ufData) { // Create a single data node for whatever data insertion is needed. UfDataNode ufd = new UfDataNode(); if (ufElement.CompoundName != string.Empty) { ufd.ParentNodeNames = ufData.ParentNodeNames + ufElement.CompoundName + " "; } else { ufd.ParentNodeNames = ufData.ParentNodeNames + ufElement.Name + " "; } ufd.ElementId = GetAttributeValue(baseNode, "id"); // A parent node in the data schema if (ufElement.Elements.Count > 0) { if (ufElement.CompoundName == string.Empty) { // Add a emtpy structural node ufd.Name = ufElement.Name; } else { // This is for compound structures, ie reviewer in hreview is a hcard // Need to find a second attribute value to do this HtmlAttribute att = baseNode.Attributes[ufElement.CompoundAttribute]; if (att != null) { if (UfHelpers.FindAttributeValue(att.Value.ToLower(), ufElement.CompoundName)) { // Add a emtpy structural node using compound name ufd.Name = ufElement.CompoundName; } } } // Recursion through the dom structure foreach (UfElementDescriber ufChildElement in ufElement.Elements) { ParseUfElement(baseNode, ufChildElement, ufd, false); } } // A value needs to be found if (ufElement.Type != UfElementDescriber.PropertyTypes.None) { // Find child nodes with "value" or "value-title" classes HtmlNodeCollection valueNodes = null; HtmlNodeCollection valueTitleNodes = null; // The value pattern if (ufElement.Elements["value"] == null && ufElement.Name != "value") { valueNodes = baseNode.SelectNodes(".//*[contains(concat(' ', @class, ' '),' value ')]"); } // The value-title pattern is only allow for some property types ie dates // or name properties ie type, duration, geo, latitude and longitude if (ufElement.Type == UfElementDescriber.PropertyTypes.Date || ufElement.Name == "type" || ufElement.Name == "duration" || ufElement.Name == "geo" || ufElement.Name == "latitude" || ufElement.Name == "longitude") { valueTitleNodes = baseNode.SelectNodes(".//*[contains(concat(' ', @class, ' '),' value-title ')]"); } if (ufElement.Type == UfElementDescriber.PropertyTypes.UrlTextAttribute || ufElement.Type == UfElementDescriber.PropertyTypes.UrlTextTag || ufElement.Type == UfElementDescriber.PropertyTypes.UrlText) { string text = UfHelpers.HtmlToText(baseNode, false); string link = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "href"), this.baseUrl, url); string att = GetAttributeValue(baseNode, ufElement.Attribute); ufd.Name = ufElement.Name; UfDataNode ufd1 = new UfDataNode(); UfDataNode ufd2 = new UfDataNode(); UfDataNode ufd3 = new UfDataNode(); ufd1.Name = "text"; ufd1.Value = text; ufd.Nodes.Add(ufd1); ufd2.Name = "link"; ufd2.Value = link; ufd.Nodes.Add(ufd2); // Add the attribute value used for XFN like structures if (ufElement.Type == UfElementDescriber.PropertyTypes.UrlTextAttribute) { ufd3.Name = ufElement.Attribute; ufd3.Value = att; ufd.Nodes.Add(ufd3); } // Add the tag element of the url if (ufElement.Type == UfElementDescriber.PropertyTypes.UrlTextTag) { ufd3.Name = "tag"; ufd3.Value = UfHelpers.GetTagFromUrl(link); ufd.Nodes.Add(ufd3); } if (ufElement.CompoundName == string.Empty) { ufData.Nodes.Add(ufd); } else { HtmlAttribute att1 = baseNode.Attributes[ufElement.CompoundAttribute]; if (att1 != null) { if (UfHelpers.FindAttributeValue(att1.Value.ToLower(), ufElement.CompoundName)) { ufd.Name = ufElement.CompoundName; ufData.Nodes.Add(ufd); } } } } // The value excerpting pattern else if (valueNodes != null) { string text = string.Empty; foreach (HtmlNode node in valueNodes) { if (node.Name == "img" || node.Name == "area") { if (ufElement.Type == UfElementDescriber.PropertyTypes.Date) { text += GetAttributeValue(node, "title").Replace(" ", "") + " "; } else { text += GetAttributeValue(node, "title"); } } else if (node.Name == "abbr") { if (ufElement.Type == UfElementDescriber.PropertyTypes.Date) { text += GetAttributeValue(node, "title").Replace(" ", "") + " "; } else { text += GetAttributeValue(node, "title"); } } else { if (ufElement.Type == UfElementDescriber.PropertyTypes.Date) { text += UfHelpers.HtmlToText(node, false).Replace(" ", "") + " "; } else { text += UfHelpers.HtmlToText(node, false) + " "; } } } if (ufElement.Type == UfElementDescriber.PropertyTypes.Date) { // Take the fagmented bits and create a true ISODateTime string ISODateTime isoDateTime = new ISODateTime(); text = isoDateTime.ParseUFFragmented(text); } ufd.Name = ufElement.Name; ufd.Value = text.Trim(); AddNewDateNode(baseNode, ufData, ufd, ufElement); } // The value-title excerpting pattern else if (valueTitleNodes != null) { string text = GetAttributeValue(valueTitleNodes[0], "title"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Url from "a" or "link" else if ((baseNode.Name == "a" || baseNode.Name == "link") && GetAttributeValue(baseNode, "href") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Url) { string link = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "href"), this.baseUrl, url); ufd.Name = ufElement.Name; ufd.Value = link; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Url from "img" else if ((baseNode.Name == "img" || baseNode.Name == "area") && GetAttributeValue(baseNode, "src") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Url) { string link = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "src"), this.baseUrl, url); ufd.Name = ufElement.Name; ufd.Value = link; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Email from "a" or "link" else if (baseNode.Name == "a" && GetAttributeValue(baseNode, "href") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Email) { string address = UfHelpers.CleanEmailAddress(GetAttributeValue(baseNode, "href")); ufd.Name = ufElement.Name; ufd.Value = address; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Tel from "object" else if (baseNode.Name == "object" && (GetAttributeValue(baseNode, "data") != "") && ufElement.Name == "tel") { UfHelpers.TelOptimization(ufd, GetAttributeValue(baseNode, "data")); AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Date from "time" else if (baseNode.Name == "time" && GetAttributeValue(baseNode, "datetime") != "" && ufElement.Type == UfElementDescriber.PropertyTypes.Date) { string text = GetAttributeValue(baseNode, "datetime"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Date from "abbr" else if (baseNode.Name == "abbr" && GetAttributeValue(baseNode, "title") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Date) { string text = GetAttributeValue(baseNode, "title"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text from "abbr" else if (baseNode.Name == "abbr" || baseNode.Name == "acronym" && GetAttributeValue(baseNode, "title") != string.Empty) { string text = GetAttributeValue(baseNode, "title"); ufd.Name = ufElement.Name; // This is for geo been used as a location in hcalandar if (ufElement.CompoundName != string.Empty) { ufd.Name = ufElement.CompoundName; } ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text from "input" else if (baseNode.Name == "input" && GetAttributeValue(baseNode, "value") != string.Empty) { string text = GetAttributeValue(baseNode, "value"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Tel from "area" else if (baseNode.Name == "area" && (GetAttributeValue(baseNode, "href") != "") && ufElement.Name == "tel") { UfHelpers.TelOptimization(ufd, GetAttributeValue(baseNode, "href")); AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text and url from "area" else if (baseNode.Name == "area" && (GetAttributeValue(baseNode, "href") != string.Empty || GetAttributeValue(baseNode, "alt") != string.Empty)) { if ((ufElement.Type == UfElementDescriber.PropertyTypes.Url || ufElement.Type == UfElementDescriber.PropertyTypes.Email) && GetAttributeValue(baseNode, "href") != string.Empty) { string text = GetAttributeValue(baseNode, "href"); if (ufElement.Type == UfElementDescriber.PropertyTypes.Email) { text = UfHelpers.CleanEmailAddress(text); } if (ufElement.Type == UfElementDescriber.PropertyTypes.Url) { text = UfHelpers.GetAbsoluteUrl(text, this.baseUrl, url); } ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } else if (GetAttributeValue(baseNode, "alt") != string.Empty) { string text = GetAttributeValue(baseNode, "alt"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } } // Url/Image from "object" else if (baseNode.Name == "object" && GetAttributeValue(baseNode, "data") != string.Empty && (ufElement.Type == UfElementDescriber.PropertyTypes.Url || ufElement.Type == UfElementDescriber.PropertyTypes.Image)) { string text = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "data"), this.baseUrl, url); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Image from "img" or "area" else if ((baseNode.Name == "img" || baseNode.Name == "area") && GetAttributeValue(baseNode, "src") != string.Empty && ufElement.Type == UfElementDescriber.PropertyTypes.Image) { string text = UfHelpers.GetAbsoluteUrl(GetAttributeValue(baseNode, "src"), this.baseUrl, url); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text from "img" longdesc attribute else if (baseNode.Name == "img" && GetAttributeValue(baseNode, "longdesc") != string.Empty) { string text = GetAttributeValue(baseNode, "longdesc"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement);; } // Text from "img" alt attribute else if (baseNode.Name == "img" && GetAttributeValue(baseNode, "alt") != string.Empty) { string text = GetAttributeValue(baseNode, "alt"); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } // Text for type/value structures with no found children else if (ufElement.NodeType == UfElementDescriber.StructureTypes.TypeValuePair) { // if no chidren nodes ie type/value are found use text // the calls for a children node type and value are alway both thier parent if (ufd.Nodes.Count == 0) { // Add text from node value string text = UfHelpers.HtmlToText(baseNode, false); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } else { // Add child type/value pair ufd.Name = ufElement.Name; AddNewDateNode(baseNode, ufData, ufd, ufElement); } } // Text from Html node collect else if (ufElement.Type == UfElementDescriber.PropertyTypes.FormattedText) { string text = UfHelpers.HtmlToText(baseNode, true); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } else { // Text from node value //string text = FindValuePattern(baseNode, ufElement); //if(text == string.Empty) // text = HtmlToText(baseNode, false); string text = UfHelpers.HtmlToText(baseNode, false); ufd.Name = ufElement.Name; ufd.Value = text; AddNewDateNode(baseNode, ufData, ufd, ufElement); } } else { AddNewDateNode(baseNode, ufData, ufd, ufElement); } }
private void AddChildNodes(UfDataNode xNode, UfDataNode node, UfElementDescriber ufElement) { //if (!string.IsNullOrEmpty(node.ElementId)) //{ // xNode.Nodes.Add("id", node.ElementId); //} if (ufElement.AttributeValues.Count > 0) { // If its a rel or rev uf based on attribute values, just copy it // UfDataNode xNodeChild = xNode.Nodes.Append(node.Name, node.Value); foreach (UfDataNode childNode in node.Nodes) xNode.Nodes.Add(childNode.Name, childNode.Value, childNode.SourceUrl, childNode.RepresentativeNode); } foreach (UfElementDescriber childElement in ufElement.Elements) { // Loop orginal data tree foreach (UfDataNode childNode in node.Nodes) { // If node name = element describer name if (childNode.Name == childElement.Name || childNode.Name == childElement.CompoundName) { // If element can have multiples call the AppendArrayList method if (childElement.Multiples) { UfDataNode xChild = xNode.Nodes.Append(childNode.Name, childNode.Value, childNode.SourceUrl, childNode.RepresentativeNode); AddChildNodes(xChild, childNode, childElement); } else { int index = xNode.Nodes.Add(childNode.Name, childNode.Value, childNode.SourceUrl, childNode.RepresentativeNode); UfDataNode xChild = xNode.Nodes[index]; AddChildNodes(xChild, childNode, childElement); } } } } }
public void Insert(int index, UfElementDescriber newElement) { InnerList.Insert(index, newElement); }
public int IndexOf(UfElementDescriber aElement) { return InnerList.IndexOf(aElement); }
public bool Contains(UfElementDescriber aElement) { return InnerList.Contains(aElement); }
public int Add(UfElementDescriber newElement) { return InnerList.Add(newElement); }
//----------------------------------------------------------------------- public static UfFormatDescriber Xfn() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "xfn"; uFormat.Description = "XHTML Friends Network, describes realtionships"; uFormat.Type = UfFormatDescriber.FormatTypes.Elemental; UfElementDescriber uFElement = new UfElementDescriber(); uFElement.Name = "xfn"; uFElement.AllowedTags.Add("a"); uFElement.AllowedTags.Add("link"); uFElement.Attribute = "rel"; uFElement.Type = UfElementDescriber.PropertyTypes.UrlTextAttribute; uFormat.BaseElement = uFElement; uFElement.AttributeValues.Add(new UfAttributeValueDescriber("met", "")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("co-worker", "")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("colleague", "")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("muse", "")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("crush", "")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("date", "")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("sweetheart", "")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("co-resident", "neighbor")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("neighbor", "co-resident")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("child", "parent sibling spouse kin")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("parent", "child sibling spouse kin")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("sibling", "child parent spouse kin")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("spouse", "child parent sibling kin")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("kin", "child parent sibling spouse")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("contact", "acquaintance friend")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("acquaintance", "contact friend")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("friend", "contact friend")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("me", "contact acquaintance friend met co-worker colleague co-resident neighbor child parent sibling spouse kin muse crush date sweetheart")); return uFormat; }
public bool Contains(UfElementDescriber aElement) { return(InnerList.Contains(aElement)); }
public static UfFormatDescriber XFolk() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "xFolk"; uFormat.Description = "xFolk"; uFormat.Type = UfFormatDescriber.FormatTypes.Compound; uFormat.BaseElement = new UfElementDescriber("xfolkentry", false, true, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("taggedlink", true, false, UfElementDescriber.PropertyTypes.UrlText)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("description", false, true, UfElementDescriber.PropertyTypes.Text)); UfElementDescriber uFElement = new UfElementDescriber(); uFElement.Name = "tag"; uFElement.AllowedTags.Add("a"); uFElement.AllowedTags.Add("link"); uFElement.Attribute = "rel"; uFElement.Type = UfElementDescriber.PropertyTypes.UrlTextTag; uFElement.AttributeValues.Add(new UfAttributeValueDescriber("tag")); uFormat.BaseElement.Elements.Add(uFElement); return uFormat; }
/// <summary> /// Adds a new data node to the tree /// </summary> /// <param name="ufData">Parent node</param> /// <param name="ufNewDataNode">Node to be added</param> /// <param name="ufElement">The uF element describer</param> private void AddNewDateNode(HtmlNode baseNode, UfDataNode ufData, UfDataNode ufNewDataNode, UfElementDescriber ufElement) { if (IsDuplicateNode(ufData, ufNewDataNode) == false) { ufNewDataNode.OuterHtml = baseNode.OuterHtml; // This function deal both with the concatenation of multiple values // and the validation of multiple flag // If the structure is a value/type pair change the insert point if (ufElement.Elements["value"] != null && ufElement.Elements["type"] != null) { // Add to child value node UfDataNode ufdatanode = new UfDataNode("value", ufNewDataNode.Value); ufNewDataNode.Nodes.Add(ufdatanode); ufNewDataNode.Value = ""; } // Concatenation of values if (ufElement.ConcatenateValues) { // Create a new node or add to the existing one if (ufData.Nodes[ufNewDataNode.Name] == null) ufData.Nodes.Add(ufNewDataNode); else ufData.Nodes[ufNewDataNode.Name].Value += ufNewDataNode.Value; } else if (ufElement.Multiples == false) { // Singluar - only take first instance if (ufData.Nodes[ufNewDataNode.Name] == null) ufData.Nodes.Add(ufNewDataNode); } else if (ufElement.Multiples == true) { // Multiples ufData.Nodes.Add(ufNewDataNode); } } }
private void ParseUfElement(HtmlNode baseNode, UfElementDescriber ufElement, UfDataNode ufData, bool ufTopLevel) { // Select nodes with required attribute: class, rel or rev HtmlNodeCollection nodes = baseNode.SelectNodes(".//@" + ufElement.Attribute); if (nodes != null) { foreach (HtmlNode node in nodes) { // Load the attribute class, rel or rev HtmlAttribute att = node.Attributes[ufElement.Attribute]; HtmlAttribute compoundAtt = node.Attributes[ufElement.CompoundAttribute]; if (att != null) { // We are dealing with elemental uf like XFN if (ufElement.AttributeValues.Count > 0) { bool found = false; // Search for a mulitple attribute values ie friend or contact in rel foreach (UfAttributeValueDescriber avd in ufElement.AttributeValues) { if (UfHelpers.FindAttributeValue(att.Value.ToLower(), avd.Name)) { found = true; } } if (found) { // Adds the Html from which uf is parsed // ufData.OuterHtml = node.OuterHtml; ParseUfElementValue(node, ufElement, ufData); } } else { bool found = false; // Search for a single attribute values ie hcard in class if (UfHelpers.FindAttributeValue(att.Value.ToLower(), ufElement.Name) && ufElement.CompoundName == string.Empty) { found = true; } // Search for a dual attribute values // This is for compound structures, ie reviewer in hreview which is a hcard if (UfHelpers.FindAttributeValue(att.Value.ToLower(), ufElement.Name) && UfHelpers.FindAttributeValue(compoundAtt.Value.ToLower(), ufElement.CompoundName)) { found = true; } if (found) { if (HasCompound(baseNode, node.ParentNode, false) == false || ufElement.RootElement == true) { HtmlNodeCollection includeRefNodes = null; includeRefNodes = node.SelectNodes(".//a[@class[contains(.,'include')]]"); if (includeRefNodes != null) { foreach (HtmlNode includeRefNode in includeRefNodes) { string link = GetAttributeValue(includeRefNode, "href"); if (link.StartsWith("#")) { link = link.Replace("#", ""); HtmlNodeCollection includeNodes = node.SelectNodes("//*[@id='" + link + "']"); if (includeNodes != null && includeNodes.Count > 0) { node.AppendChild(HtmlNode.CreateNode("<div>" + includeNodes[0].OuterHtml + "</div>")); } } } } includeRefNodes = node.SelectNodes(".//object[@class[contains(.,'include')]]"); if (includeRefNodes != null) { foreach (HtmlNode includeRefNode in includeRefNodes) { string link = GetAttributeValue(includeRefNode, "data"); if (link.StartsWith("#")) { link = link.Replace("#", ""); HtmlNodeCollection includeNodes = node.SelectNodes("//*[@id='" + link + "']"); if (includeNodes != null && includeNodes.Count > 0) { node.AppendChild(HtmlNode.CreateNode("<div>" + includeNodes[0].OuterHtml + "</div>")); } } } } // For TD // Finds table head include pattern and appends node collection if (node.Name == "td" && GetAttributeValue(node, "headers") != string.Empty) { string link = GetAttributeValue(node, "headers"); string[] itemArray = new string[1]; itemArray[0] = link; if (link.IndexOf(' ') > -1) { itemArray = link.Split(' '); } for (int i = 0; i < itemArray.Length; i++) { HtmlNodeCollection includeNodes = null; includeNodes = this.startNode.SelectNodes("//node()[@id='" + itemArray[i].Trim() + "']"); if (includeNodes != null && includeNodes.Count > 0) { // Appends fresh node to avoid overload issues foreach (HtmlNode childNode in includeNodes) { node.AppendChild(HtmlNode.CreateNode("<div>" + childNode.OuterHtml + "</div>")); } } } } // For TR // Finds table head include pattern and appends node collection if (node.Name == "tr") { foreach (HtmlNode child in node.ChildNodes) { if (child.Name == "td" && GetAttributeValue(child, "headers") != string.Empty) { string link = GetAttributeValue(child, "headers"); string[] itemArray = new string[1]; itemArray[0] = link; if (link.IndexOf(' ') > -1) { itemArray = link.Split(' '); } for (int i = 0; i < itemArray.Length; i++) { HtmlNodeCollection includeNodes = null; includeNodes = this.startNode.SelectNodes("//node()[@id='" + itemArray[i].Trim() + "']"); if (includeNodes != null && includeNodes.Count > 0) { // Appends fresh node to avoid overload issues foreach (HtmlNode childNode in includeNodes) { child.AppendChild(HtmlNode.CreateNode("<div>" + childNode.OuterHtml + "</div>")); } } } } } } // Adds the Html from which uf is parsed foreach (HtmlNode childNode in node.ChildNodes) { ufData.OuterHtml += childNode.OuterHtml; } // Recursion if (ufElement.Multiples || ufElement.ConcatenateValues) { ParseUfElementValue(node, ufElement, ufData); } else // Dont add a second data node for a format decription that does not support either // multiples or concatenation of values if (ufData.Nodes.Exists(ufElement.Name) == false) { ParseUfElementValue(node, ufElement, ufData); } } } } } } } }
public int Add(UfElementDescriber newElement) { return(InnerList.Add(newElement)); }
/// <summary> /// Adds a new data node to the tree /// </summary> /// <param name="ufData">Parent node</param> /// <param name="ufNewDataNode">Node to be added</param> /// <param name="ufElement">The uF element describer</param> private void AddNewDateNode(HtmlNode baseNode, UfDataNode ufData, UfDataNode ufNewDataNode, UfElementDescriber ufElement) { if (IsDuplicateNode(ufData, ufNewDataNode) == false) { ufNewDataNode.OuterHtml = baseNode.OuterHtml; // This function deal both with the concatenation of multiple values // and the validation of multiple flag // If the structure is a value/type pair change the insert point if (ufElement.Elements["value"] != null && ufElement.Elements["type"] != null) { // Add to child value node UfDataNode ufdatanode = new UfDataNode("value", ufNewDataNode.Value); ufNewDataNode.Nodes.Add(ufdatanode); ufNewDataNode.Value = ""; } // Concatenation of values if (ufElement.ConcatenateValues) { // Create a new node or add to the existing one if (ufData.Nodes[ufNewDataNode.Name] == null) { ufData.Nodes.Add(ufNewDataNode); } else { ufData.Nodes[ufNewDataNode.Name].Value += ufNewDataNode.Value; } } else if (ufElement.Multiples == false) { // Singluar - only take first instance if (ufData.Nodes[ufNewDataNode.Name] == null) { ufData.Nodes.Add(ufNewDataNode); } } else if (ufElement.Multiples == true) { // Multiples ufData.Nodes.Add(ufNewDataNode); } } }
public static UfFormatDescriber ItemLicense() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "item-license"; uFormat.Description = "item-license used in hNews hEntry item"; uFormat.Type = UfFormatDescriber.FormatTypes.Elemental; UfElementDescriber uFElement = new UfElementDescriber(); uFElement.Name = "item-license"; uFElement.AllowedTags.Add("a"); uFElement.AllowedTags.Add("link"); uFElement.Attribute = "rel"; uFElement.Type = UfElementDescriber.PropertyTypes.UrlText; uFormat.BaseElement = uFElement; uFElement.AttributeValues.Add(new UfAttributeValueDescriber("item-license")); return uFormat; }
private void AddNode(UfDataNode node, UfElementDescriber elementDescriber, XhtmlTextWriter writer) { if (node.Name != string.Empty) { indentNum++; writer.Indent = indentNum; UfElementDescriber currentDescriber = elementDescriber; foreach (UfElementDescriber childElementDescriber in elementDescriber.Elements) { if (node.Name == childElementDescriber.Name || node.Name == childElementDescriber.CompoundName) { currentDescriber = childElementDescriber; } } if (currentDescriber.Attribute == "class") { writer.WriteBeginTag("div"); if (currentDescriber.CompoundName == "") { writer.WriteAttribute("class", node.Name); } else { writer.WriteAttribute("class", node.Name + " " + currentDescriber.Name); } if (!string.IsNullOrEmpty(node.ElementId)) { writer.WriteAttribute("id", node.ElementId); } writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEncodedText(node.Value); foreach (UfDataNode child in node.Nodes) { writer.WriteLine(); AddNode(child, currentDescriber, writer); } if (node.Name != string.Empty) { writer.WriteEndTag("div"); writer.WriteLine(); } } if (currentDescriber.Attribute == "rel") { writer.WriteBeginTag("a"); writer.WriteAttribute("href", node.DescendantValue("link")); writer.WriteAttribute("rel", node.Name); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEncodedText(node.DescendantValue("text")); writer.WriteEndTag("a"); writer.WriteLine(); } indentNum--; writer.Indent = indentNum; } }
public static UfFormatDescriber Me() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "me"; uFormat.Description = "The finds rel=me without rest of xfn"; uFormat.Type = UfFormatDescriber.FormatTypes.Elemental; UfElementDescriber uFElement = new UfElementDescriber(); uFElement.Name = "me"; uFElement.AllowedTags.Add("a"); uFElement.AllowedTags.Add("link"); uFElement.Attribute = "rel"; uFElement.Type = UfElementDescriber.PropertyTypes.UrlText; uFormat.BaseElement = uFElement; uFElement.AttributeValues.Add(new UfAttributeValueDescriber("me", "")); return uFormat; }
private void ParseUfElement(HtmlNode baseNode, UfElementDescriber ufElement, UfDataNode ufData, bool ufTopLevel) { // Select nodes with required attribute: class, rel or rev HtmlNodeCollection nodes = baseNode.SelectNodes(".//@" + ufElement.Attribute ); if (nodes != null) { foreach (HtmlNode node in nodes) { // Load the attribute class, rel or rev HtmlAttribute att = node.Attributes[ufElement.Attribute]; HtmlAttribute compoundAtt = node.Attributes[ufElement.CompoundAttribute]; if (att != null) { // We are dealing with elemental uf like XFN if (ufElement.AttributeValues.Count > 0) { bool found = false; // Search for a mulitple attribute values ie friend or contact in rel foreach (UfAttributeValueDescriber avd in ufElement.AttributeValues) { if (UfHelpers.FindAttributeValue(att.Value.ToLower(), avd.Name)) found = true; } if (found) { // Adds the Html from which uf is parsed // ufData.OuterHtml = node.OuterHtml; ParseUfElementValue(node, ufElement, ufData); } } else { bool found = false; // Search for a single attribute values ie hcard in class if (UfHelpers.FindAttributeValue(att.Value.ToLower(), ufElement.Name) && ufElement.CompoundName == string.Empty) found = true; // Search for a dual attribute values // This is for compound structures, ie reviewer in hreview which is a hcard if (UfHelpers.FindAttributeValue(att.Value.ToLower(), ufElement.Name) && UfHelpers.FindAttributeValue(compoundAtt.Value.ToLower(), ufElement.CompoundName)) found = true; if (found) { if (HasCompound(baseNode, node.ParentNode, false) == false || ufElement.RootElement == true) { HtmlNodeCollection includeRefNodes = null; includeRefNodes = node.SelectNodes(".//a[@class[contains(.,'include')]]"); if (includeRefNodes != null) { foreach (HtmlNode includeRefNode in includeRefNodes) { string link = GetAttributeValue(includeRefNode, "href"); if (link.StartsWith("#")) { link = link.Replace("#", ""); HtmlNodeCollection includeNodes = node.SelectNodes("//*[@id='" + link + "']"); if (includeNodes != null && includeNodes.Count > 0) node.AppendChild(HtmlNode.CreateNode("<div>" + includeNodes[0].OuterHtml + "</div>")); } } } includeRefNodes = node.SelectNodes(".//object[@class[contains(.,'include')]]"); if (includeRefNodes != null) { foreach (HtmlNode includeRefNode in includeRefNodes) { string link = GetAttributeValue(includeRefNode, "data"); if (link.StartsWith("#")) { link = link.Replace("#", ""); HtmlNodeCollection includeNodes = node.SelectNodes("//*[@id='" + link + "']"); if (includeNodes != null && includeNodes.Count > 0) node.AppendChild(HtmlNode.CreateNode("<div>" + includeNodes[0].OuterHtml + "</div>")); } } } // For TD // Finds table head include pattern and appends node collection if (node.Name == "td" && GetAttributeValue(node, "headers") != string.Empty) { string link = GetAttributeValue(node, "headers"); string[] itemArray = new string[1]; itemArray[0] = link; if (link.IndexOf(' ') > -1) itemArray = link.Split(' '); for (int i = 0; i < itemArray.Length; i++) { HtmlNodeCollection includeNodes = null; includeNodes = this.startNode.SelectNodes("//node()[@id='" + itemArray[i].Trim() + "']"); if (includeNodes != null && includeNodes.Count > 0) { // Appends fresh node to avoid overload issues foreach (HtmlNode childNode in includeNodes) node.AppendChild(HtmlNode.CreateNode("<div>" + childNode.OuterHtml + "</div>")); } } } // For TR // Finds table head include pattern and appends node collection if (node.Name == "tr") { foreach (HtmlNode child in node.ChildNodes) { if (child.Name == "td" && GetAttributeValue(child, "headers") != string.Empty) { string link = GetAttributeValue(child, "headers"); string[] itemArray = new string[1]; itemArray[0] = link; if (link.IndexOf(' ') > -1) itemArray = link.Split(' '); for (int i = 0; i < itemArray.Length; i++) { HtmlNodeCollection includeNodes = null; includeNodes = this.startNode.SelectNodes("//node()[@id='" + itemArray[i].Trim() + "']"); if (includeNodes != null && includeNodes.Count > 0) { // Appends fresh node to avoid overload issues foreach (HtmlNode childNode in includeNodes) child.AppendChild(HtmlNode.CreateNode("<div>" + childNode.OuterHtml + "</div>")); } } } } } // Adds the Html from which uf is parsed foreach (HtmlNode childNode in node.ChildNodes) ufData.OuterHtml += childNode.OuterHtml; // Recursion if (ufElement.Multiples || ufElement.ConcatenateValues) ParseUfElementValue(node, ufElement, ufData); else // Dont add a second data node for a format decription that does not support either // multiples or concatenation of values if (ufData.Nodes.Exists(ufElement.Name) == false) ParseUfElementValue(node, ufElement, ufData); } } } } } } }
//----------------------------------------------------------------------- public static UfFormatDescriber NextPrevious() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "nextprevious"; uFormat.Description = "The rel next previous design pattern"; uFormat.Type = UfFormatDescriber.FormatTypes.Compound; UfElementDescriber uFElement = new UfElementDescriber(); uFElement.Name = "nextprevious"; uFElement.AllowedTags.Add("a"); uFElement.AllowedTags.Add("link"); uFElement.Attribute = "rel"; uFElement.Type = UfElementDescriber.PropertyTypes.UrlTextAttribute; uFormat.BaseElement = uFElement; uFElement.AttributeValues.Add(new UfAttributeValueDescriber("next", "")); uFElement.AttributeValues.Add(new UfAttributeValueDescriber("prev", "")); return uFormat; }
private void AddNode(UfDataNode node, UfElementDescriber elementDescriber, XhtmlTextWriter writer) { if (node.Name != string.Empty) { indentNum++; writer.Indent = indentNum; UfElementDescriber currentDescriber = elementDescriber; foreach (UfElementDescriber childElementDescriber in elementDescriber.Elements) { if (node.Name == childElementDescriber.Name || node.Name == childElementDescriber.CompoundName) { currentDescriber = childElementDescriber; } } if (currentDescriber.Attribute == "class") { writer.WriteBeginTag("div"); if (currentDescriber.CompoundName == "") writer.WriteAttribute("class", node.Name); else writer.WriteAttribute("class", node.Name + " " + currentDescriber.Name); if (!string.IsNullOrEmpty(node.ElementId)) writer.WriteAttribute("id", node.ElementId); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEncodedText(node.Value); foreach (UfDataNode child in node.Nodes) { writer.WriteLine(); AddNode(child, currentDescriber, writer); } if (node.Name != string.Empty) { writer.WriteEndTag("div"); writer.WriteLine(); } } if (currentDescriber.Attribute == "rel") { writer.WriteBeginTag("a"); writer.WriteAttribute("href", node.DescendantValue("link")); writer.WriteAttribute("rel", node.Name); writer.Write(HtmlTextWriter.TagRightChar); writer.WriteEncodedText(node.DescendantValue("text")); writer.WriteEndTag("a"); writer.WriteLine(); } indentNum--; writer.Indent = indentNum; } }