/// <summary> /// Initializes the supplied <see cref="RssChannel"/> optional entities using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>. /// </summary> /// <param name="channel">The <see cref="RssChannel"/> to be filled.</param> /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the channel XML data.</param> /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param> /// <exception cref="ArgumentNullException">The <paramref name="channel"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> private static void FillChannelOptionals(RssChannel channel, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { Guard.ArgumentNotNull(channel, "channel"); Guard.ArgumentNotNull(navigator, "navigator"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); XPathNavigator copyrightNavigator = navigator.SelectSingleNode("copyright", manager); XPathNavigator managingEditorNavigator = navigator.SelectSingleNode("managingEditor", manager); XPathNavigator webMasterNavigator = navigator.SelectSingleNode("webMaster", manager); XPathNavigator ratingNavigator = navigator.SelectSingleNode("rating", manager); XPathNavigator publicationNavigator = navigator.SelectSingleNode("pubDate", manager); XPathNavigator lastBuildDateNavigator = navigator.SelectSingleNode("lastBuildDate", manager); XPathNavigator textInputNavigator = navigator.SelectSingleNode("textInput", manager); if (copyrightNavigator != null) { channel.Copyright = copyrightNavigator.Value; } if (managingEditorNavigator != null) { channel.ManagingEditor = managingEditorNavigator.Value; } if (webMasterNavigator != null) { channel.Webmaster = webMasterNavigator.Value; } if (ratingNavigator != null) { channel.Rating = ratingNavigator.Value; } if (publicationNavigator != null) { DateTime publicationDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate)) { channel.PublicationDate = publicationDate; } } if (lastBuildDateNavigator != null) { DateTime lastBuildDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(lastBuildDateNavigator.Value, out lastBuildDate)) { channel.LastBuildDate = lastBuildDate; } } if (textInputNavigator != null) { channel.TextInput = new RssTextInput(); Rss091SyndicationResourceAdapter.FillTextInput(channel.TextInput, textInputNavigator, manager, settings); } }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="OpmlHead"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="OpmlHead"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="OpmlHead"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNavigator titleNavigator = source.SelectSingleNode("title"); XPathNavigator dateCreatedNavigator = source.SelectSingleNode("dateCreated"); XPathNavigator dateModifiedNavigator = source.SelectSingleNode("dateModified"); XPathNavigator expansionStateNavigator = source.SelectSingleNode("expansionState"); XPathNavigator verticalScrollStateNavigator = source.SelectSingleNode("vertScrollState"); if (titleNavigator != null) { this.Title = titleNavigator.Value; wasLoaded = true; } if (dateCreatedNavigator != null) { DateTime createdOn; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(dateCreatedNavigator.Value, out createdOn)) { this.CreatedOn = createdOn; wasLoaded = true; } } if (dateModifiedNavigator != null) { DateTime modifiedOn; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(dateModifiedNavigator.Value, out modifiedOn)) { this.ModifiedOn = modifiedOn; wasLoaded = true; } } OpmlOwner owner = new OpmlOwner(); if (owner.Load(source)) { this.Owner = owner; } if (expansionStateNavigator != null && !String.IsNullOrEmpty(expansionStateNavigator.Value)) { if (expansionStateNavigator.Value.Contains(",")) { string[] expansionStates = expansionStateNavigator.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string expansionState in expansionStates) { int state; if (Int32.TryParse(expansionState.Trim(), System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out state)) { this.ExpansionState.Add(state); wasLoaded = true; } } } else { int expansionState; if (Int32.TryParse(expansionStateNavigator.Value, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out expansionState)) { this.ExpansionState.Add(expansionState); wasLoaded = true; } } } if (verticalScrollStateNavigator != null) { int verticalScrollState; if (Int32.TryParse(verticalScrollStateNavigator.Value, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out verticalScrollState)) { this.VerticalScrollState = verticalScrollState; wasLoaded = true; } } OpmlWindow window = new OpmlWindow(); if (window.Load(source)) { this.Window = window; } return(wasLoaded); }
/// <summary> /// Loads this <see cref="OpmlOutline"/> using attributes defined on the supplied <see cref="XPathNavigator"/>. /// </summary> /// <returns><b>true</b> if the <see cref="OpmlOutline"/> was initialized using the supplied <paramref name="attribute"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="attribute"/> to be positioned on the XML element that represents a <see cref="OpmlOutline"/> attribute. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="attribute"/> is a null reference (Nothing in Visual Basic).</exception> private bool LoadAttribute(XPathNavigator attribute) { bool wasLoaded = false; Guard.ArgumentNotNull(attribute, "attribute"); if (String.IsNullOrEmpty(attribute.Value)) { return(false); } if (String.Compare(attribute.Name, "text", StringComparison.OrdinalIgnoreCase) == 0) { this.Text = attribute.Value; wasLoaded = true; } else if (String.Compare(attribute.Name, "type", StringComparison.OrdinalIgnoreCase) == 0) { this.ContentType = attribute.Value; wasLoaded = true; } else if (String.Compare(attribute.Name, "isComment", StringComparison.OrdinalIgnoreCase) == 0) { bool isComment; if (Boolean.TryParse(attribute.Value, out isComment)) { this.IsCommented = isComment; wasLoaded = true; } } else if (String.Compare(attribute.Name, "isBreakpoint", StringComparison.OrdinalIgnoreCase) == 0) { bool isBreakpoint; if (Boolean.TryParse(attribute.Value, out isBreakpoint)) { this.HasBreakpoint = isBreakpoint; wasLoaded = true; } } else if (String.Compare(attribute.Name, "created", StringComparison.OrdinalIgnoreCase) == 0) { DateTime created; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(attribute.Value, out created)) { this.CreatedOn = created; wasLoaded = true; } } else if (String.Compare(attribute.Name, "category", StringComparison.OrdinalIgnoreCase) == 0) { if (attribute.Value.Contains(",")) { string[] categories = attribute.Value.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string category in categories) { this.Categories.Add(category); } } else { this.Categories.Add(attribute.Value); } wasLoaded = true; } else { if (!this.Attributes.ContainsKey(attribute.Name)) { this.Attributes.Add(attribute.Name, attribute.Value); wasLoaded = true; } } return(wasLoaded); }
/// <summary> /// Loads this <see cref="RssItem"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param> /// <returns><b>true</b> if the <see cref="RssItem"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="RssItem"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = new XmlNamespaceManager(source.NameTable); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNavigator authorNavigator = source.SelectSingleNode("author", manager); XPathNavigator commentsNavigator = source.SelectSingleNode("comments", manager); XPathNavigator descriptionNavigator = source.SelectSingleNode("description", manager); XPathNavigator guidNavigator = source.SelectSingleNode("guid", manager); XPathNavigator linkNavigator = source.SelectSingleNode("link", manager); XPathNavigator publicationNavigator = source.SelectSingleNode("pubDate", manager); XPathNavigator sourceNavigator = source.SelectSingleNode("source", manager); XPathNavigator titleNavigator = source.SelectSingleNode("title", manager); XPathNodeIterator categoryIterator = source.Select("category", manager); XPathNodeIterator enclosureIterator = source.Select("enclosure", manager); //------------------------------------------------------------ // Load required/common item elements //------------------------------------------------------------ if (titleNavigator != null) { this.Title = titleNavigator.Value; wasLoaded = true; } if (descriptionNavigator != null) { this.Description = descriptionNavigator.Value; wasLoaded = true; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { this.Link = link; wasLoaded = true; } } //------------------------------------------------------------ // Load optional item elements //------------------------------------------------------------ if (authorNavigator != null) { this.Author = authorNavigator.Value; wasLoaded = true; } if (commentsNavigator != null) { Uri comments; if (Uri.TryCreate(commentsNavigator.Value, UriKind.RelativeOrAbsolute, out comments)) { this.Comments = comments; wasLoaded = true; } } if (guidNavigator != null) { RssGuid guid = new RssGuid(); if (guid.Load(guidNavigator, settings)) { this.Guid = guid; wasLoaded = true; } } if (publicationNavigator != null) { DateTime publicationDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate)) { this.PublicationDate = publicationDate; wasLoaded = true; } } if (sourceNavigator != null) { RssSource sourceFeed = new RssSource(); if (sourceFeed.Load(sourceNavigator, settings)) { this.Source = sourceFeed; wasLoaded = true; } } //------------------------------------------------------------ // Load item collection elements //------------------------------------------------------------ if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { RssCategory category = new RssCategory(); if (category.Load(categoryIterator.Current, settings)) { this.Categories.Add(category); } } } if (enclosureIterator != null && enclosureIterator.Count > 0) { while (enclosureIterator.MoveNext()) { RssEnclosure enclosure = new RssEnclosure(); if (enclosure.Load(enclosureIterator.Current, settings)) { this.Enclosures.Add(enclosure); } } } //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(this); return(wasLoaded); }
/// <summary> /// Loads this <see cref="RssItem"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param> /// <returns><b>true</b> if the <see cref="RssItem"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="RssItem"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); XmlNamespaceManager manager = new XmlNamespaceManager(source.NameTable); XPathNavigator authorNavigator = source.SelectSingleNode("author", manager); XPathNavigator commentsNavigator = source.SelectSingleNode("comments", manager); XPathNavigator descriptionNavigator = source.SelectSingleNode("description", manager); XPathNavigator guidNavigator = source.SelectSingleNode("guid", manager); XPathNavigator linkNavigator = source.SelectSingleNode("link", manager); XPathNavigator publicationNavigator = source.SelectSingleNode("pubDate", manager); XPathNavigator sourceNavigator = source.SelectSingleNode("source", manager); XPathNavigator titleNavigator = source.SelectSingleNode("title", manager); XPathNodeIterator categoryIterator = source.Select("category", manager); XPathNodeIterator enclosureIterator = source.Select("enclosure", manager); if (titleNavigator != null) { this.Title = titleNavigator.Value; wasLoaded = true; } if (descriptionNavigator != null) { this.Description = descriptionNavigator.Value; wasLoaded = true; } if (linkNavigator != null) { Uri link; if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link)) { this.Link = link; wasLoaded = true; } } if (authorNavigator != null) { this.Author = authorNavigator.Value; wasLoaded = true; } if (commentsNavigator != null) { Uri comments; if (Uri.TryCreate(commentsNavigator.Value, UriKind.RelativeOrAbsolute, out comments)) { this.Comments = comments; wasLoaded = true; } } if (guidNavigator != null) { RssGuid guid = new RssGuid(); if (guid.Load(guidNavigator)) { this.Guid = guid; wasLoaded = true; } } if (publicationNavigator != null) { DateTime publicationDate; if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate)) { this.PublicationDate = publicationDate; wasLoaded = true; } } if (sourceNavigator != null) { RssSource sourceFeed = new RssSource(); if (sourceFeed.Load(sourceNavigator)) { this.Source = sourceFeed; wasLoaded = true; } } if (categoryIterator != null && categoryIterator.Count > 0) { while (categoryIterator.MoveNext()) { RssCategory category = new RssCategory(); if (category.Load(categoryIterator.Current)) { this.Categories.Add(category); } } } if (enclosureIterator != null && enclosureIterator.Count > 0) { while (enclosureIterator.MoveNext()) { RssEnclosure enclosure = new RssEnclosure(); if (enclosure.Load(enclosureIterator.Current)) { this.Enclosures.Add(enclosure); } } } return(wasLoaded); }