private void OnLinkTag(HTMLParser instance, string tag) { HashMap attrMap = instance.ParseAttributes(tag); if ((string)attrMap ["rel"] == "alternate" && ((string)attrMap ["type"] == "application/rss+xml" || (string)attrMap ["type"] == "application/atom+xml")) { string href = (string)attrMap ["href"]; if (href != null) { string url; try { url = new Uri(_baseUri, href).ToString(); } catch (UriFormatException) { return; } if (!HttpReader.IsSupportedProtocol(url)) { return; } _candidateURLs.Push(10, url); _candidateURLSet.Add(url); _candidateHintTexts [url] = attrMap ["title"]; } } }
private void OnHeaderTag(HTMLParser instance, string tag) { _inHeader = true; HashMap attrMap = instance.ParseAttributes(tag); if ((_id = (string)attrMap["id"]) == null) { _id = string.Empty; } }
public void Attributes() { using (HTMLParser parser = CreateParser("")) { HashMap hashMap = parser.ParseAttributes("link rel=\"stylesheet\" HRef=\"/styles-site.css\" type = 'text/css' /"); Assert.AreEqual(3, hashMap.Count); Assert.AreEqual("stylesheet", hashMap["rel"]); Assert.AreEqual("/styles-site.css", hashMap["href"]); Assert.AreEqual("text/css", hashMap["type"]); } }
private void LinkHandler(HTMLParser instance, string tag) { if (_currentIndexedRes != null && instance.InHeading) { HashMap attributes = instance.ParseAttributes(tag); string rel = (string)attributes["rel"]; if (rel != null && rel.ToLower() == "shortcut icon") { new ResourceProxy(_currentIndexedRes).SetPropAsync("FaviconUrl", attributes["href"]); } } }
private void OnLinkTag(HTMLParser instance, string tag) { _inLink = true; HashMap attrMap = instance.ParseAttributes(tag); if ((_url = (string)attrMap["href"]) == null) { _url = string.Empty; } if ((_id = (string)attrMap["id"]) == null) { _id = string.Empty; } _isFeed = attrMap["feedurl"] != null; }
private void OnATag(HTMLParser instance, string tag) { if (instance.InScript) { return; } HashMap attrMap = instance.ParseAttributes(tag); string href = (string)attrMap ["href"]; if (href == null) { return; } if (href.StartsWith("feed:")) { href = "http:" + href.Substring(5); } Uri hrefUri; try { hrefUri = new Uri(_baseUri, href); } catch (Exception) { // sometimes generic exceptions are thrown from Uri constructor (see OM-9323) return; } string hrefUriString; try { /* * OM-12523. * System.UriFormatException: Invalid URI: The hostname could not be parsed. * at System.Uri.CreateHostStringHelper(String str, UInt16 idx, UInt16 end, Flags& flags, String& scopeId) * at System.Uri.CreateHostString() * at System.Uri.EnsureHostString(Boolean allowDnsOptimization) * at System.Uri.GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat) * at System.Uri.ToString() */ hrefUriString = hrefUri.ToString(); } catch (System.UriFormatException) { return; } if (!HttpReader.IsSupportedProtocol(hrefUriString)) { return; } bool sameServer = (String.Compare(_baseUri.Host, hrefUri.Host, true) == 0); int pos = href.LastIndexOf("."); string ext = (pos < 0) ? "" : href.Substring(pos).ToLower(); int priority = 0; if (ext == ".rss" || ext == ".rdf" || ext == ".xml") { priority = sameServer ? 9 : 7; } else { href = href.ToLower(); if (href.IndexOf("rss") >= 0 || href.IndexOf("rdf") >= 0 || href.IndexOf("xml") >= 0) { priority = sameServer ? 8 : 6; } } if (priority != 0) { if (!_candidateURLSet.Contains(hrefUriString)) { _lastCandidateURL = hrefUriString; _candidateURLSet.Add(_lastCandidateURL); _candidateURLs.Push(priority, _lastCandidateURL); } } }