/// <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(); }
/// <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()); }
/// <summary> /// Load and parse a Html string. /// </summary> /// <param name="htmlString">Html string</param> /// <param name="url">A Url for relative path operations</param> /// <param name="formatDescriber">The microformat format describer</param> public void Load(string htmlString, string url, UfFormatDescriber formatDescriber) { // Temp fix xhtml strict issue htmlString = htmlString.Replace("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">", ""); htmlString = htmlString.Replace("<meta content=\"text/html; charset => utf-8\" http-equiv=\"Content-Type\" />", ""); HtmlDocument document = new HtmlDocument(); document.LoadHtml(htmlString); this.Load(document, url, formatDescriber); }
public static UfFormatDescriber Assert() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "assert"; uFormat.Description = "An Assert, part of a test fixture"; uFormat.BaseElement = new UfElementDescriber("assert", false, true, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("test", false, false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("result", false, false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("comment", false, false, true, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
/// <summary> /// Loads a single Html pages and does a microformat parse /// </summary> /// <param name="url">The Url of the webpage to be pasred</param> /// <param name="formatDescriber">A format describer for microformat to be parsed</param> public void Load(string url, UfFormatDescriber formatDescriber) { this.formatDescriber = formatDescriber; try { if (url != string.Empty) { // Check for issues with url url = url.Trim(); url = HttpUtility.UrlDecode(url); UfWebPage webPage = LoadHtmlDoc(url); if (webPage != null) { Url urlReport = new Url(); urlReport.Address = webPage.Url; urlReport.Status = webPage.StatusCode; parsedUrls.Add(urlReport); DateTime started = DateTime.Now; if (webPage.StatusCode == 200 && webPage.Html != null) { ParseUf(webPage.Html, url, formatDescriber, false, urlReport); } if (webPage.StatusCode != 200) { throw (new Exception("Could not load url: " + url + " " + webPage.StatusCode)); } DateTime ended = DateTime.Now; urlReport.LoadTime = ended.Subtract(started); Urls.Add(urlReport); } } else { throw (new Exception("No Url given")); } } catch (Exception ex) { if (ex.Message != string.Empty) { throw (new Exception(ex.Message)); } else { throw (new Exception("Could not load Url: " + url)); } } }
//----------------------------------------------------------------------- public static UfFormatDescriber Competency() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "competency"; uFormat.Description = "Part of draft hResume spec"; uFormat.BaseElement = new UfElementDescriber("competency", false, false, UfElementDescriber.PropertyTypes.None); UfFormatDescriber ski = Tag(); ski.BaseElement.CompoundName = "skill"; ski.BaseElement.CompoundAttribute = "class"; uFormat.BaseElement.Elements.Add(ski.BaseElement); uFormat.BaseElement.Elements.Add(new UfElementDescriber("proficiency", false, false, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
// Parse uf private void ParseUf(HtmlDocument htmlDoc, string url, UfFormatDescriber format, bool multiples, Url urlReport) { UfParse ufparse = new UfParse(); ufparse.Load(htmlDoc, url, format); if (multiples) { data.Nodes.Add(ufparse.Data); } else { data = ufparse.Data; } urlReport.HtmlPageTitle = ufparse.HtmlPageTitle; }
/// <summary> /// Converts a UfDataNode structure into JSON /// </summary> /// <param name="node">Node</param> /// <param name="formatDescriber">Microformat format describer object</param> /// <returns>JSON string</returns> public string Convert(UfDataNode node, UfFormatDescriber formatDescriber) { foreach (UfDataNode childNode in node.Nodes) { if (childNode.Name == formatDescriber.BaseElement.Name) { UfDataNode xChild = tree.Nodes.Append(childNode.Name, childNode.Value, childNode.SourceUrl, childNode.RepresentativeNode); if (childNode.Nodes.Count > 0) { AddChildNodes(xChild, childNode, formatDescriber.BaseElement); } } } //string output = "// UfXtract \n"; string output = ""; if (callBack != string.Empty) { output += callBack + "( "; } output += "{\"microformats\": {"; foreach (UfDataNode childNode in tree.Nodes) { output += BuildDataString(childNode, true, false); } if (tree.Nodes.Count > 0) { output = output.Substring(0, output.Length - 2); } output += AddUfErrors(); output += AddReporting(node); // End whole block output += "}}"; if (callBack != string.Empty) { output += " )"; } return(output); }
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; }
public static UfFormatDescriber Adr() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "adr"; uFormat.Description = "Address"; uFormat.Type = UfFormatDescriber.FormatTypes.Compound; uFormat.BaseElement = new UfElementDescriber("adr", false, true, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("type", false, true, "work,home,pref,postal,dom,intl")); uFormat.BaseElement.Elements.Add(new UfElementDescriber("post-office-box", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("extended-address", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("street-address", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("locality", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("region", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("postal-code", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("country-name", false, false, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
//----------------------------------------------------------------------- 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 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; }
// This currently not used because of issue with type/value public static UfFormatDescriber Ingredient() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "Ingredient"; uFormat.Description = "An ingredient"; uFormat.BaseElement = new UfElementDescriber("ingredient", true, true, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("value", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("type", false, false, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
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; }
//----------------------------------------------------------------------- /// <summary> /// Load and parse a Html string. /// </summary> /// <param name="htmlString">Html string</param> /// <param name="url">A Url for relative path operations</param> /// <param name="formatDescriber">The microformat format describer</param> public void Load(string htmlString, UfFormatDescriber formatDescriber) { Load(htmlString, "", formatDescriber); }
/// <summary> /// Converts a UfDataNode structure into JSON /// </summary> /// <param name="node">Node</param> /// <param name="formatDescriber">Microformat format describer object</param> /// <returns>JSON string</returns> public string Convert(UfDataNode node, UfFormatDescriber formatDescriber) { foreach (UfDataNode childNode in node.Nodes) { if (childNode.Name == formatDescriber.BaseElement.Name) { UfDataNode xChild = tree.Nodes.Append(childNode.Name, childNode.Value, childNode.SourceUrl, childNode.RepresentativeNode); if (childNode.Nodes.Count > 0) AddChildNodes(xChild, childNode, formatDescriber.BaseElement); } } //string output = "// UfXtract \n"; string output = ""; if( callBack != string.Empty) output += callBack + "( "; output += "{\"microformats\": {"; foreach (UfDataNode childNode in tree.Nodes) output += BuildDataString(childNode, true, false); if (tree.Nodes.Count > 0) output = output.Substring(0, output.Length - 2); output += AddUfErrors(); output += AddReporting( node ); // End whole block output += "}}"; if (callBack != string.Empty) output += " )"; return output; }
public static UfFormatDescriber RRule() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "rrule"; uFormat.Description = "Recurring durations and dates"; uFormat.BaseElement = new UfElementDescriber("rrule", false, false, UfElementDescriber.PropertyTypes.Text); uFormat.BaseElement.Elements.Add(new UfElementDescriber("freq", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("count", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("interval", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("until", false, false, UfElementDescriber.PropertyTypes.Date)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("bysecond", false, false, UfElementDescriber.PropertyTypes.Number)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("byminute", false, false, UfElementDescriber.PropertyTypes.Number)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("bymonthday", false, false, UfElementDescriber.PropertyTypes.Number)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("byyearday", false, false, UfElementDescriber.PropertyTypes.Number)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("byweekno", false, false, UfElementDescriber.PropertyTypes.Number)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("bymonth", false, false, UfElementDescriber.PropertyTypes.Number)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("byday", false, false, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
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; }
public static UfFormatDescriber Output() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "output"; uFormat.Description = "The output, part of a test fixture"; uFormat.BaseElement = new UfElementDescriber("output", false, true, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("url", false, false, true, UfElementDescriber.PropertyTypes.Url)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("type", false, false, true, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
public static UfFormatDescriber Org() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "org"; uFormat.Description = "Organization"; uFormat.BaseElement = new UfElementDescriber("org", true, false, UfElementDescriber.PropertyTypes.Text); uFormat.BaseElement.Elements.Add(new UfElementDescriber("organization-name", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("organization-unit", false, false, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
// This currently not used because of issue with type/value public static UfFormatDescriber Nutrition() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "Nutrition"; uFormat.Description = "An nutrition"; uFormat.BaseElement = new UfElementDescriber("nutrition", true, false, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("value", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("type", false, false, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
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 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; }
private static UfFormatDescriber BaseHCard() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "hCard"; uFormat.Description = "hCard"; uFormat.Type = UfFormatDescriber.FormatTypes.Compound; uFormat.BaseElement = new UfElementDescriber("vcard", false, true, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("fn", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(Name().BaseElement); uFormat.BaseElement.Elements.Add(Adr().BaseElement); uFormat.BaseElement.Elements.Add(Email().BaseElement); uFormat.BaseElement.Elements.Add(Tel().BaseElement); UfFormatDescriber cat = Tag(); cat.BaseElement.CompoundName = "category"; cat.BaseElement.CompoundAttribute = "class"; uFormat.BaseElement.Elements.Add(cat.BaseElement); UfFormatDescriber org = Org(); org.BaseElement.Multiples = true; uFormat.BaseElement.Elements.Add(org.BaseElement); UfFormatDescriber geo = Geo(); geo.BaseElement.Multiples = false; uFormat.BaseElement.Elements.Add(geo.BaseElement); //uFormat.BaseElement.Elements.Add(new UfElementDescriber("agent", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("bday", false, false, UfElementDescriber.PropertyTypes.Date)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("class", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("key", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("label", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("logo", false, true, UfElementDescriber.PropertyTypes.Image)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("mailer", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("nickname", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("note", false, true, UfElementDescriber.PropertyTypes.FormattedText)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("photo", false, true, UfElementDescriber.PropertyTypes.Image)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("rev", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("role", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("sort-string", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("sound", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("title", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("tz", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("uid", false, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("url", false, true, UfElementDescriber.PropertyTypes.Url)); return uFormat; }
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; }
/// <summary> /// Converts a UfDataNode structure into JSON /// </summary> /// <param name="node">Node</param> /// <param name="formatDescriber">Microformat format describer object</param> /// <param name="callBack">JSONP callback function name to wrap JSON object</param> /// <returns>JSON string</returns> public string Convert(UfDataNode node, UfFormatDescriber formatDescriber, string callBack) { this.callBack = callBack; this.callBack = this.callBack.Replace("(", "").Replace(")", "").Trim(); return Convert(node, formatDescriber); }
/// <summary> /// Load and parse a Html document. /// </summary> /// <param name="document">HtmlAgilityPack Htmldocument object</param> /// <param name="formatDescriber">The microformat format describer</param> public void Load(HtmlDocument document, UfFormatDescriber formatDescriber) { Load(document, "", formatDescriber); }
/// <summary> /// Load and parse a Html document. /// </summary> /// <param name="document">HtmlAgilityPack Htmldocument object</param> /// <param name="url">The source Url of the document</param> /// <param name="formatDescriber">The microformat format describer</param> public void Load(HtmlDocument document, string url, UfFormatDescriber formatDescriber) { if (document == null) { throw new ArgumentNullException("document"); } this.url = url; this.formatDescriber = formatDescriber; this.document = document; // Add in the whole html string from the page into the top data node data.OuterHtml = this.document.DocumentNode.OuterHtml; HtmlNodeCollection nodes; this.baseUrl = FindDocumentNodeAttributeValue("//html", "xml:base"); this.baseUrl = FindDocumentNodeAttributeValue("//body", "xml:base"); this.baseUrl = FindDocumentNodeAttributeValue("//base", "href"); // Find the html page title nodes = this.document.DocumentNode.SelectNodes("//title"); if (nodes != null) { foreach (HtmlNode node in nodes) { this.htmlPageTitle = node.InnerText; } } // Start with document node this.startNode = document.DocumentNode; //// Find any fragment select //// <a name="profile"> html nodes </a> if (url != "") { Uri uri = new Uri(url); string frag = uri.Fragment; if (frag != string.Empty) { try { // A name based fragment selection nodes = this.document.DocumentNode.SelectNodes("//a[@name='" + frag.Replace("#", "") + "']"); if (nodes != null) { this.startNode = nodes[0]; } else { // ID based fragment selection nodes = this.document.DocumentNode.SelectNodes("//*[@id='" + frag.Replace("#", "") + "']"); this.startNode = nodes[0]; } } catch (Exception ex) { throw new Exception("Could not find name fragment" + frag); } } } // Starts recursion ParseUfElement(this.startNode, this.FormatDescriber.BaseElement, this.Data, true); UfHelpers.RunNodeOptimization(this.Data); }
/// <summary> /// Converts a UfDataNode structure into JSON /// </summary> /// <param name="node">Node</param> /// <param name="formatDescriber">Microformat format describer object</param> /// <param name="callBack">JSONP callback function name to wrap JSON object</param> /// <returns>JSON string</returns> public string Convert(UfDataNode node, UfFormatDescriber formatDescriber, string callBack) { this.callBack = callBack; this.callBack = this.callBack.Replace("(", "").Replace(")", "").Trim(); return(Convert(node, formatDescriber)); }
public static UfFormatDescriber TestSuite() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "test-suite"; uFormat.Description = "The structure of a test suite containing a number of test fixtures"; uFormat.Type = UfFormatDescriber.FormatTypes.Compound; uFormat.BaseElement = new UfElementDescriber("test-suite", true, true, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(Test().BaseElement); 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 static UfFormatDescriber Tel() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "tel"; uFormat.Description = "Telephone"; uFormat.BaseElement = new UfElementDescriber("tel", false, true, UfElementDescriber.PropertyTypes.Text); uFormat.BaseElement.NodeType = UfElementDescriber.StructureTypes.TypeValuePair; uFormat.BaseElement.Elements.Add(new UfElementDescriber("type", false, true, "voice,home,msg,work,pref,fax,cell,video,pager,bbs,modem,car,isdn,pcs")); uFormat.BaseElement.Elements.Add(new UfElementDescriber("value", false, false, true, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
public static UfFormatDescriber Name() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "n"; uFormat.Description = "Name"; uFormat.Type = UfFormatDescriber.FormatTypes.Compound; uFormat.BaseElement = new UfElementDescriber("n", false, false, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("type", false, true, "intl,postal,parcel,work,dom,home,pref")); uFormat.BaseElement.Elements.Add(new UfElementDescriber("honorific-prefix", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("given-name", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("additional-name", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("family-name", false, true, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("honorific-suffix", false, true, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
public static UfFormatDescriber Test() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "test"; uFormat.Description = "The location of a test fixture"; uFormat.BaseElement = new UfElementDescriber("test", false, true, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("format", true, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("url", false, false, true, UfElementDescriber.PropertyTypes.Url)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("description", false, false, true, UfElementDescriber.PropertyTypes.Text)); return uFormat; }
/// <summary> /// Load and parse a Html document. /// </summary> /// <param name="document">HtmlAgilityPack Htmldocument object</param> /// <param name="url">The source Url of the document</param> /// <param name="formatDescriber">The microformat format describer</param> public void Load(HtmlDocument document, string url, UfFormatDescriber formatDescriber) { if (document == null) throw new ArgumentNullException("document"); this.url = url; this.formatDescriber = formatDescriber; this.document = document; // Add in the whole html string from the page into the top data node data.OuterHtml = this.document.DocumentNode.OuterHtml; HtmlNodeCollection nodes; this.baseUrl = FindDocumentNodeAttributeValue("//html", "xml:base"); this.baseUrl = FindDocumentNodeAttributeValue("//body", "xml:base"); this.baseUrl = FindDocumentNodeAttributeValue("//base", "href"); // Find the html page title nodes = this.document.DocumentNode.SelectNodes("//title"); if (nodes != null) foreach (HtmlNode node in nodes) this.htmlPageTitle = node.InnerText; // Start with document node this.startNode = document.DocumentNode; //// Find any fragment select //// <a name="profile"> html nodes </a> if (url != "") { Uri uri = new Uri(url); string frag = uri.Fragment; if (frag != string.Empty) { try { // A name based fragment selection nodes = this.document.DocumentNode.SelectNodes("//a[@name='" + frag.Replace("#", "") + "']"); if (nodes != null) { this.startNode = nodes[0]; } else { // ID based fragment selection nodes = this.document.DocumentNode.SelectNodes("//*[@id='" + frag.Replace("#", "") + "']"); this.startNode = nodes[0]; } } catch (Exception ex) { throw new Exception("Could not find name fragment" + frag); } } } // Starts recursion ParseUfElement(this.startNode, this.FormatDescriber.BaseElement, this.Data, true); UfHelpers.RunNodeOptimization(this.Data); }
public static UfFormatDescriber TestFixture() { UfFormatDescriber uFormat = new UfFormatDescriber(); uFormat.Name = "test-fixture"; uFormat.Description = "A test fixture"; uFormat.Type = UfFormatDescriber.FormatTypes.Compound; uFormat.BaseElement = new UfElementDescriber("test-fixture", true, true, UfElementDescriber.PropertyTypes.None); uFormat.BaseElement.Elements.Add(new UfElementDescriber("summary", true, true, UfElementDescriber.PropertyTypes.FormattedText)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("description", false, true, UfElementDescriber.PropertyTypes.FormattedText)); uFormat.BaseElement.Elements.Add(new UfElementDescriber("format", true, false, UfElementDescriber.PropertyTypes.Text)); uFormat.BaseElement.Elements.Add(Output().BaseElement); uFormat.BaseElement.Elements.Add(Assert().BaseElement); UfFormatDescriber history = HCalendar(); history.BaseElement.CompoundName = "history"; history.BaseElement.CompoundAttribute = "class"; uFormat.BaseElement.Elements.Add(history.BaseElement); UfFormatDescriber author = HCard(); author.BaseElement.CompoundName = "author"; author.BaseElement.CompoundAttribute = "class"; uFormat.BaseElement.Elements.Add(author.BaseElement); return uFormat; }