/// <summary>
        /// Initializes the supplied <see cref="RssEnclosure"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>.
        /// </summary>
        /// <param name="enclosure">The <see cref="RssEnclosure"/> to be filled.</param>
        /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the enclosure 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="enclosure"/> 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 FillEnclosure(RssEnclosure enclosure, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(enclosure, "enclosure");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract enclosure information
            //------------------------------------------------------------
            if (navigator.HasAttributes)
            {
                string urlAttribute     = navigator.GetAttribute("url", String.Empty);
                string lengthAttribute  = navigator.GetAttribute("length", String.Empty);
                string typeAttribute    = navigator.GetAttribute("type", String.Empty);

                Uri url;
                if (Uri.TryCreate(urlAttribute, UriKind.RelativeOrAbsolute, out url))
                {
                    enclosure.Url           = url;
                }

                long length;
                if (Int64.TryParse(lengthAttribute, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out length))
                {
                    enclosure.Length        = length;
                }

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    enclosure.ContentType   = typeAttribute;
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings);
            adapter.Fill(enclosure);
        }
        /// <summary>
        /// Creates a <see cref="AtomTextConstruct"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <returns>A <see cref="AtomTextConstruct"/> instance initialized using the supplied <paramref name="source"/>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a Atom 0.3 Content construct.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> 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 AtomTextConstruct CreateTextContent(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            AtomTextConstruct content   = new AtomTextConstruct();

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract common attributes information
            //------------------------------------------------------------
            AtomUtility.FillCommonObjectAttributes(content, source);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string modeAttribute    = source.GetAttribute("mode", String.Empty);
                if (!String.IsNullOrEmpty(modeAttribute))
                {
                    if (String.Compare(modeAttribute, "base64", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        content.TextType    = AtomTextConstructType.Text;
                    }
                    else if (String.Compare(modeAttribute, "escaped", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        content.TextType    = AtomTextConstructType.Html;
                    }
                    else if (String.Compare(modeAttribute, "xml", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        content.TextType    = AtomTextConstructType.Xhtml;
                    }
                    else
                    {
                        content.TextType    = AtomTextConstructType.Text;
                    }
                }
            }

            if (content.TextType == AtomTextConstructType.Xhtml)
            {
                XPathNavigator xhtmlDivNavigator    = source.SelectSingleNode("xhtml:div", manager);
                if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value))
                {
                    content.Content = xhtmlDivNavigator.Value;
                }
                else if (!String.IsNullOrEmpty(source.Value))
                {
                    content.Content = source.Value;
                }
            }
            else if (!String.IsNullOrEmpty(source.Value))
            {
                content.Content     = source.Value;
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(content, manager);

            return content;
        }
        /// <summary>
        /// Modifies the <see cref="AtomFeed"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="AtomFeed"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(AtomFeed resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = Atom03SyndicationResourceAdapter.CreateNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator feedNavigator    = this.Navigator.SelectSingleNode("atom:feed", manager);

            if (feedNavigator != null)
            {
                AtomUtility.FillCommonObjectAttributes(resource, feedNavigator);

                XPathNavigator idNavigator          = feedNavigator.SelectSingleNode("atom:id", manager);
                XPathNavigator titleNavigator       = feedNavigator.SelectSingleNode("atom:title", manager);
                XPathNavigator modifiedNavigator    = feedNavigator.SelectSingleNode("atom:modified", manager);

                if (idNavigator != null)
                {
                    resource.Id = new AtomId();
                    resource.Id.Load(idNavigator, this.Settings);
                }

                if (titleNavigator != null)
                {
                    resource.Title  = Atom03SyndicationResourceAdapter.CreateTextContent(titleNavigator, manager, this.Settings);
                }

                if (modifiedNavigator != null)
                {
                    DateTime updatedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(modifiedNavigator.Value, out updatedOn))
                    {
                        resource.UpdatedOn  = updatedOn;
                    }
                }

                Atom03SyndicationResourceAdapter.FillFeedOptionals(resource, feedNavigator, manager, this.Settings);
                Atom03SyndicationResourceAdapter.FillFeedCollections(resource, feedNavigator, manager, this.Settings);

                SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(feedNavigator, this.Settings);
                adapter.Fill(resource, manager);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads this <see cref="RssChannel"/> 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="RssChannel"/> 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="RssChannel"/>.
        /// </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);
            manager.AddNamespace("atom", "http://www.w3.org/2005/Atom");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNavigator descriptionNavigator     = source.SelectSingleNode("description", manager);
            XPathNavigator linkNavigator            = source.SelectSingleNode("link", manager);
            XPathNavigator titleNavigator           = source.SelectSingleNode("title", manager);

            //------------------------------------------------------------
            //	Load required channel information
            //------------------------------------------------------------
            if (descriptionNavigator != null && !String.IsNullOrEmpty(descriptionNavigator.Value))
            {
                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 (titleNavigator != null && !String.IsNullOrEmpty(titleNavigator.Value))
            {
                this.Title          = titleNavigator.Value;
                wasLoaded           = true;
            }

            //------------------------------------------------------------
            //	Load optional channel information
            //------------------------------------------------------------
            if (this.LoadOptionals(source, manager, settings))
            {
                wasLoaded   = true;
            }

            //------------------------------------------------------------
            //	Load channel collections information
            //------------------------------------------------------------
            if (this.LoadCollections(source, manager, settings))
            {
                wasLoaded   = true;
            }

            //------------------------------------------------------------
            //	Load optional RSS Profile channel information
            //------------------------------------------------------------
            if (this.LoadProfile(source, manager, settings))
            {
                wasLoaded   = true;
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
        /// <summary>
        /// Creates a <see cref="AtomGenerator"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <returns>A <see cref="AtomGenerator"/> instance initialized using the supplied <paramref name="source"/>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a Atom 0.3 generator element.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> 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 AtomGenerator CreateGenerator(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            AtomGenerator generator = new AtomGenerator();

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract common attributes information
            //------------------------------------------------------------
            AtomUtility.FillCommonObjectAttributes(generator, source);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if(source.HasAttributes)
            {
                string urlAttribute     = source.GetAttribute("url", String.Empty);
                string versionAttribute = source.GetAttribute("version", String.Empty);

                if (!String.IsNullOrEmpty(urlAttribute))
                {
                    Uri uri;
                    if (Uri.TryCreate(urlAttribute, UriKind.RelativeOrAbsolute, out uri))
                    {
                        generator.Uri   = uri;
                    }
                }

                if (!String.IsNullOrEmpty(versionAttribute))
                {
                    generator.Version   = versionAttribute;
                }
            }

            if (!String.IsNullOrEmpty(source.Value))
            {
                generator.Content       = source.Value;
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(generator, manager);

            return generator;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads this <see cref="OpmlOutline"/> 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="OpmlOutline"/> 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="OpmlOutline"/>.
        /// </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");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                XPathNavigator attributesNavigator = source.CreateNavigator();
                if (attributesNavigator.MoveToFirstAttribute())
                {
                    //------------------------------------------------------------
                    //	Extract first attribute
                    //------------------------------------------------------------
                    if (this.LoadAttribute(attributesNavigator))
                    {
                        wasLoaded       = true;
                    }

                    //------------------------------------------------------------
                    //	Enumerate through additional attributes
                    //------------------------------------------------------------
                    while (attributesNavigator.MoveToNextAttribute())
                    {
                        if (this.LoadAttribute(attributesNavigator))
                        {
                            wasLoaded   = true;
                        }
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator outlinesIterator = source.Select("outline");
                if (outlinesIterator != null && outlinesIterator.Count > 0)
                {
                    while (outlinesIterator.MoveNext())
                    {
                        OpmlOutline outline = new OpmlOutline();
                        if (outline.Load(outlinesIterator.Current, settings))
                        {
                            this.Outlines.Add(outline);
                            wasLoaded   = true;
                        }
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
        /// <summary>
        /// Modifies the <see cref="ApmlDocument"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="ApmlDocument"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(ApmlDocument resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = ApmlUtility.CreateNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator headNavigator    = this.Navigator.SelectSingleNode("apml:APML/apml:Head", manager);
            if (headNavigator != null)
            {
                resource.Head.Load(headNavigator, this.Settings);
            }

            XPathNavigator bodyNavigator    = this.Navigator.SelectSingleNode("apml:APML/apml:Body", manager);
            if (bodyNavigator != null)
            {
                if (bodyNavigator.HasAttributes)
                {
                    string defaultProfileAttribute  = bodyNavigator.GetAttribute("defaultprofile", String.Empty);
                    if (!String.IsNullOrEmpty(defaultProfileAttribute))
                    {
                        resource.DefaultProfileName = defaultProfileAttribute;
                    }
                }

                XPathNodeIterator profileIterator   = bodyNavigator.Select("apml:Profile", manager);
                if (profileIterator != null && profileIterator.Count > 0)
                {
                    int counter = 0;
                    while (profileIterator.MoveNext())
                    {
                        ApmlProfile profile = new ApmlProfile();
                        counter++;

                        if (profile.Load(profileIterator.Current, this.Settings))
                        {
                            if (this.Settings.RetrievalLimit != 0 && counter > this.Settings.RetrievalLimit)
                            {
                                break;
                            }

                            ((Collection<ApmlProfile>)resource.Profiles).Add(profile);
                        }
                    }
                }

                XPathNodeIterator applicationIterator   = bodyNavigator.Select("apml:Applications/apml:Application", manager);
                if (applicationIterator != null && applicationIterator.Count > 0)
                {
                    while (applicationIterator.MoveNext())
                    {
                        ApmlApplication application = new ApmlApplication();
                        if (application.Load(applicationIterator.Current, this.Settings))
                        {
                            resource.Applications.Add(application);
                        }
                    }
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(this.Navigator.SelectSingleNode("apml:APML", manager), this.Settings);
            adapter.Fill(resource, manager);
        }
        /// <summary>
        /// Modifies the <see cref="RssFeed"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="RssFeed"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(RssFeed resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = new XmlNamespaceManager(this.Navigator.NameTable);
            manager.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            manager.AddNamespace("rss", "http://my.netscape.com/rdf/simple/0.9/");

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator channelNavigator     = this.Navigator.SelectSingleNode("rdf:RDF/rss:channel", manager);
            if (channelNavigator != null)
            {
                Rss090SyndicationResourceAdapter.FillChannel(resource.Channel, channelNavigator, manager, this.Settings);
            }

            XPathNavigator imageNavigator       = this.Navigator.SelectSingleNode("rdf:RDF/rss:image", manager);
            if (imageNavigator != null)
            {
                resource.Channel.Image          = new RssImage();
                Rss090SyndicationResourceAdapter.FillImage(resource.Channel.Image, imageNavigator, manager, this.Settings);
            }

            XPathNavigator textInputNavigator   = this.Navigator.SelectSingleNode("rdf:RDF/rss:textinput", manager);
            if (textInputNavigator != null)
            {
                resource.Channel.TextInput      = new RssTextInput();
                Rss090SyndicationResourceAdapter.FillTextInput(resource.Channel.TextInput, textInputNavigator, manager, this.Settings);
            }

            XPathNodeIterator itemIterator      = this.Navigator.Select("rdf:RDF/rss:item", manager);
            if (itemIterator != null && itemIterator.Count > 0)
            {
                int counter = 0;
                while (itemIterator.MoveNext())
                {
                    RssItem item = new RssItem();
                    counter++;

                    if (this.Settings.RetrievalLimit != 0 && counter > this.Settings.RetrievalLimit)
                    {
                        break;
                    }

                    XPathNavigator titleNavigator   = itemIterator.Current.SelectSingleNode("rss:title", manager);
                    XPathNavigator linkNavigator    = itemIterator.Current.SelectSingleNode("rss:link", manager);

                    if (titleNavigator != null)
                    {
                        item.Title      = titleNavigator.Value;
                    }
                    if (linkNavigator != null)
                    {
                        Uri link;
                        if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                        {
                            item.Link   = link;
                        }
                    }

                    SyndicationExtensionAdapter itemExtensionAdapter    = new SyndicationExtensionAdapter(itemIterator.Current, this.Settings);
                    itemExtensionAdapter.Fill(item, manager);

                    ((Collection<RssItem>)resource.Channel.Items).Add(item);
                }
            }

            SyndicationExtensionAdapter feedExtensionAdapter    = new SyndicationExtensionAdapter(this.Navigator.SelectSingleNode("rdf:RDF", manager), this.Settings);
            feedExtensionAdapter.Fill(resource, manager);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Loads this <see cref="ApmlProfile"/> 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="ApmlProfile"/> 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="ApmlProfile"/>.
        /// </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");

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string nameAttribute    = source.GetAttribute("name", String.Empty);
                if (!String.IsNullOrEmpty(nameAttribute))
                {
                    this.Name   = nameAttribute;
                    wasLoaded   = true;
                }
            }

            if(source.HasChildren)
            {
                XPathNavigator implicitDataNavigator    = source.SelectSingleNode("apml:ImplicitData", manager);
                XPathNavigator explicitDataNavigator    = source.SelectSingleNode("apml:ExplicitData", manager);

                if (implicitDataNavigator != null)
                {
                    XPathNodeIterator conceptsIterator  = implicitDataNavigator.Select("apml:Concepts/apml:Concept", manager);
                    if (conceptsIterator != null && conceptsIterator.Count > 0)
                    {
                        while (conceptsIterator.MoveNext())
                        {
                            ApmlConcept concept = new ApmlConcept();
                            if (concept.Load(conceptsIterator.Current, settings))
                            {
                                this.ImplicitConcepts.Add(concept);
                                wasLoaded       = true;
                            }
                        }
                    }

                    XPathNodeIterator sourcesIterator   = implicitDataNavigator.Select("apml:Sources/apml:Source", manager);
                    if (sourcesIterator != null && sourcesIterator.Count > 0)
                    {
                        while (sourcesIterator.MoveNext())
                        {
                            ApmlSource attentionSource  = new ApmlSource();
                            if (attentionSource.Load(sourcesIterator.Current, settings))
                            {
                                this.ImplicitSources.Add(attentionSource);
                                wasLoaded               = true;
                            }
                        }
                    }
                }

                if (explicitDataNavigator != null)
                {
                    XPathNodeIterator conceptsIterator  = explicitDataNavigator.Select("apml:Concepts/apml:Concept", manager);
                    if (conceptsIterator != null && conceptsIterator.Count > 0)
                    {
                        while (conceptsIterator.MoveNext())
                        {
                            ApmlConcept concept = new ApmlConcept();
                            if (concept.Load(conceptsIterator.Current, settings))
                            {
                                this.ExplicitConcepts.Add(concept);
                                wasLoaded       = true;
                            }
                        }
                    }

                    XPathNodeIterator sourcesIterator   = explicitDataNavigator.Select("apml:Sources/apml:Source", manager);
                    if (sourcesIterator != null && sourcesIterator.Count > 0)
                    {
                        while (sourcesIterator.MoveNext())
                        {
                            ApmlSource attentionSource  = new ApmlSource();
                            if (attentionSource.Load(sourcesIterator.Current, settings))
                            {
                                this.ExplicitSources.Add(attentionSource);
                                wasLoaded               = true;
                            }
                        }
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssChannel"/> 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 FillChannel(RssChannel channel, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(channel, "channel");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Load required channel information
            //------------------------------------------------------------
            XPathNavigator descriptionNavigator = navigator.SelectSingleNode("rss:description", manager);
            XPathNavigator linkNavigator        = navigator.SelectSingleNode("rss:link", manager);
            XPathNavigator titleNavigator       = navigator.SelectSingleNode("rss:title", manager);

            if (descriptionNavigator != null && !String.IsNullOrEmpty(descriptionNavigator.Value))
            {
                channel.Description = descriptionNavigator.Value;
            }

            if (linkNavigator != null)
            {
                Uri link;
                if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                {
                    channel.Link    = link;
                }
            }

            if (titleNavigator != null && !String.IsNullOrEmpty(titleNavigator.Value))
            {
                channel.Title       = titleNavigator.Value;
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings);
            adapter.Fill(channel);
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssImage"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>.
        /// </summary>
        /// <param name="image">The <see cref="RssImage"/> to be filled.</param>
        /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the image 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="image"/> 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 FillImage(RssImage image, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(image, "image");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract image information
            //------------------------------------------------------------
            XPathNavigator linkNavigator    = navigator.SelectSingleNode("rss:link", manager);
            XPathNavigator titleNavigator   = navigator.SelectSingleNode("rss:title", manager);
            XPathNavigator urlNavigator     = navigator.SelectSingleNode("rss:url", manager);

            if (linkNavigator != null)
            {
                Uri link;
                if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                {
                    image.Link      = link;
                }
            }

            if (titleNavigator != null)
            {
                if (!String.IsNullOrEmpty(titleNavigator.Value))
                {
                    image.Title     = titleNavigator.Value;
                }
            }

            if (urlNavigator != null)
            {
                Uri url;
                if (Uri.TryCreate(urlNavigator.Value, UriKind.RelativeOrAbsolute, out url))
                {
                    image.Url       = url;
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings);
            adapter.Fill(image);
        }
        /// <summary>
        /// Modifies the <see cref="OpmlDocument"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="OpmlDocument"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(OpmlDocument resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = new XmlNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator documentNavigator    = this.Navigator.SelectSingleNode("opml", manager);
            if (documentNavigator != null)
            {
                XPathNavigator headNavigator    = documentNavigator.SelectSingleNode("head", manager);
                if (headNavigator != null)
                {
                    resource.Head.Load(headNavigator, this.Settings);
                }

                XPathNodeIterator outlineIterator   = documentNavigator.Select("body/outline", manager);
                if (outlineIterator != null && outlineIterator.Count > 0)
                {
                    int counter = 0;
                    while (outlineIterator.MoveNext())
                    {
                        OpmlOutline outline = new OpmlOutline();
                        counter++;

                        if (outline.Load(outlineIterator.Current, this.Settings))
                        {
                            if (this.Settings.RetrievalLimit != 0 && counter > this.Settings.RetrievalLimit)
                            {
                                break;
                            }

                            ((Collection<OpmlOutline>)resource.Outlines).Add(outline);
                        }
                    }
                }

                SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(documentNavigator, this.Settings);
                adapter.Fill(resource, manager);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Loads this <see cref="ApmlSource"/> 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="ApmlSource"/> 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="ApmlSource"/>.
        /// </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");

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string keyAttribute     = source.GetAttribute("key", String.Empty);
                string nameAttribute    = source.GetAttribute("name", String.Empty);
                string valueAttribute   = source.GetAttribute("value", String.Empty);
                string typeAttribute    = source.GetAttribute("type", String.Empty);
                string fromAttribute    = source.GetAttribute("from", String.Empty);
                string updatedAttribute = source.GetAttribute("updated", String.Empty);

                if (!String.IsNullOrEmpty(keyAttribute))
                {
                    this.Key    = keyAttribute;
                    wasLoaded   = true;
                }

                if (!String.IsNullOrEmpty(nameAttribute))
                {
                    this.Name   = nameAttribute;
                    wasLoaded   = true;
                }

                if (!String.IsNullOrEmpty(valueAttribute))
                {
                    decimal value;
                    if (Decimal.TryParse(valueAttribute, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out value))
                    {
                        if (value >= Decimal.MinusOne && value <= Decimal.One)
                        {
                            this.Value  = value;
                            wasLoaded   = true;
                        }
                    }
                }

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    this.MimeType   = typeAttribute;
                    wasLoaded       = true;
                }

                if (!String.IsNullOrEmpty(fromAttribute))
                {
                    this.From   = fromAttribute;
                    wasLoaded   = true;
                }

                if (!String.IsNullOrEmpty(updatedAttribute))
                {
                    DateTime updatedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedAttribute, out updatedOn))
                    {
                        this.UpdatedOn  = updatedOn;
                        wasLoaded       = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator authorIterator    = source.Select("apml:Author", manager);

                if (authorIterator != null && authorIterator.Count > 0)
                {
                    while (authorIterator.MoveNext())
                    {
                        ApmlAuthor author = new ApmlAuthor();
                        if (author.Load(authorIterator.Current, settings))
                        {
                            this.Authors.Add(author);
                            wasLoaded   = true;
                        }
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssItem"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>.
        /// </summary>
        /// <param name="item">The <see cref="RssItem"/> to be filled.</param>
        /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the item 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="item"/> 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 FillItem(RssItem item, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(item, "item");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract item information
            //------------------------------------------------------------
            XPathNavigator titleNavigator       = navigator.SelectSingleNode("title", manager);
            XPathNavigator linkNavigator        = navigator.SelectSingleNode("link", manager);
            XPathNavigator descriptionNavigator = navigator.SelectSingleNode("description", manager);
            XPathNavigator sourceNavigator      = navigator.SelectSingleNode("source", manager);
            XPathNodeIterator enclosureIterator = navigator.Select("enclosure", manager);
            XPathNodeIterator categoryIterator  = navigator.Select("category", manager);

            if (titleNavigator != null)
            {
                item.Title          = titleNavigator.Value;
            }

            if (descriptionNavigator != null)
            {
                item.Description    = descriptionNavigator.Value;
            }

            if (linkNavigator != null)
            {
                Uri link;
                if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                {
                    item.Link       = link;
                }
            }

            if (sourceNavigator != null)
            {
                item.Source             = new RssSource();

                if (sourceNavigator.HasAttributes)
                {
                    string urlAttribute = sourceNavigator.GetAttribute("url", String.Empty);
                    Uri url;
                    if (Uri.TryCreate(urlAttribute, UriKind.RelativeOrAbsolute, out url))
                    {
                        item.Source.Url = url;
                    }
                }

                if(!String.IsNullOrEmpty(sourceNavigator.Value))
                {
                    item.Source.Title   = sourceNavigator.Value;
                }
            }

            if (enclosureIterator != null && enclosureIterator.Count > 0)
            {
                while (enclosureIterator.MoveNext())
                {
                    RssEnclosure enclosure  = new RssEnclosure();
                    Rss092SyndicationResourceAdapter.FillEnclosure(enclosure, enclosureIterator.Current, manager, settings);

                    item.Enclosures.Add(enclosure);
                }
            }

            if (categoryIterator != null && categoryIterator.Count > 0)
            {
                while (categoryIterator.MoveNext())
                {
                    RssCategory category    = new RssCategory();
                    Rss092SyndicationResourceAdapter.FillCategory(category, categoryIterator.Current, manager, settings);

                    item.Categories.Add(category);
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings);
            adapter.Fill(item);
        }
        /// <summary>
        /// Modifies the <see cref="RssFeed"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="RssFeed"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(RssFeed resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = new XmlNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator feedNavigator    = this.Navigator.SelectSingleNode("rss", manager);

            if (feedNavigator != null)
            {
                XPathNavigator channelNavigator = feedNavigator.SelectSingleNode("channel", manager);
                if (channelNavigator != null)
                {
                    Rss091SyndicationResourceAdapter.FillChannel(resource.Channel, channelNavigator, manager, this.Settings);
                }

                SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(feedNavigator, this.Settings);
                adapter.Fill(resource, manager);
            }
        }
        /// <summary>
        /// Modifies the <see cref="AtomServiceDocument"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="AtomServiceDocument"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(AtomServiceDocument resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator documentNavigator    = this.Navigator.SelectSingleNode("app:service", manager);
            if (documentNavigator != null)
            {
                AtomUtility.FillCommonObjectAttributes(resource, documentNavigator);

                if (documentNavigator.HasChildren)
                {
                    XPathNodeIterator workspaceIterator = documentNavigator.Select("app:workspace", manager);

                    if (workspaceIterator != null && workspaceIterator.Count > 0)
                    {
                        while (workspaceIterator.MoveNext())
                        {
                            AtomWorkspace workspace = new AtomWorkspace();
                            if (workspace.Load(workspaceIterator.Current, this.Settings))
                            {
                                resource.AddWorkspace(workspace);
                            }
                        }
                    }
                }

                SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(documentNavigator, this.Settings);
                adapter.Fill(resource, manager);
            }
        }
        /// <summary>
        /// Modifies the <see cref="BlogMLDocument"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="BlogMLDocument"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(BlogMLDocument resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = BlogMLUtility.CreateNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator blogNavigator = this.Navigator.SelectSingleNode("blog:blog", manager);
            if (blogNavigator != null)
            {
                if(blogNavigator.HasAttributes)
                {
                    string dateCreatedAttribute = blogNavigator.GetAttribute("date-created", String.Empty);
                    string rootUrlAttribute     = blogNavigator.GetAttribute("root-url", String.Empty);

                    if (!String.IsNullOrEmpty(dateCreatedAttribute))
                    {
                        DateTime createdOn;
                        if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateCreatedAttribute, out createdOn))
                        {
                            resource.GeneratedOn    = createdOn;
                        }
                    }

                    if (!String.IsNullOrEmpty(rootUrlAttribute))
                    {
                        Uri rootUrl;
                        if (Uri.TryCreate(rootUrlAttribute, UriKind.RelativeOrAbsolute, out rootUrl))
                        {
                            resource.RootUrl    = rootUrl;
                        }
                    }
                }

                if (blogNavigator.HasChildren)
                {
                    XPathNavigator titleNavigator       = blogNavigator.SelectSingleNode("blog:title", manager);
                    XPathNavigator subtitleNavigator    = blogNavigator.SelectSingleNode("blog:sub-title", manager);

                    if (titleNavigator != null)
                    {
                        BlogMLTextConstruct title   = new BlogMLTextConstruct();
                        if (title.Load(titleNavigator))
                        {
                            resource.Title          = title;
                        }
                    }

                    if (subtitleNavigator != null)
                    {
                        BlogMLTextConstruct subtitle    = new BlogMLTextConstruct();
                        if (subtitle.Load(subtitleNavigator))
                        {
                            resource.Subtitle           = subtitle;
                        }
                    }

                    BlogML20SyndicationResourceAdapter.FillDocumentCollections(resource, blogNavigator, manager, this.Settings);
                }

                SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(blogNavigator, this.Settings);
                adapter.Fill(resource, manager);
            }
        }
        /// <summary>
        /// Modifies the <see cref="AtomCategoryDocument"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="AtomCategoryDocument"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(AtomCategoryDocument resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator documentNavigator    = this.Navigator.SelectSingleNode("app:categories", manager);
            if (documentNavigator != null)
            {
                AtomUtility.FillCommonObjectAttributes(resource, documentNavigator);

                if (documentNavigator.HasChildren)
                {
                    if (documentNavigator.HasAttributes)
                    {
                        string fixedAttribute   = documentNavigator.GetAttribute("fixed", String.Empty);
                        string schemeAttribute  = documentNavigator.GetAttribute("scheme", String.Empty);
                        string hrefAttribute    = documentNavigator.GetAttribute("href", String.Empty);

                        if (!String.IsNullOrEmpty(fixedAttribute))
                        {
                            if (String.Compare(fixedAttribute, "yes", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                resource.IsFixed    = true;
                            }
                            else if (String.Compare(fixedAttribute, "no", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                resource.IsFixed    = false;
                            }
                        }

                        if (!String.IsNullOrEmpty(schemeAttribute))
                        {
                            Uri scheme;
                            if (Uri.TryCreate(schemeAttribute, UriKind.RelativeOrAbsolute, out scheme))
                            {
                                resource.Scheme     = scheme;
                            }
                        }

                        if (!String.IsNullOrEmpty(hrefAttribute))
                        {
                            Uri href;
                            if (Uri.TryCreate(hrefAttribute, UriKind.RelativeOrAbsolute, out href))
                            {
                                resource.Uri        = href;
                            }
                        }
                    }

                    if (documentNavigator.HasChildren)
                    {
                        XPathNodeIterator categoryIterator = documentNavigator.Select("atom:category", manager);

                        if (categoryIterator != null && categoryIterator.Count > 0)
                        {
                            while (categoryIterator.MoveNext())
                            {
                                AtomCategory category   = new AtomCategory();
                                if (category.Load(categoryIterator.Current, this.Settings))
                                {
                                    resource.AddCategory(category);
                                }
                            }
                        }
                    }
                }

                SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(documentNavigator, this.Settings);
                adapter.Fill(resource, manager);
            }
        }
        /// <summary>
        /// Modifies the <see cref="RsdDocument"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="RsdDocument"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(RsdDocument resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager     = RsdUtility.CreateNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator serviceNavigator = RsdUtility.SelectSafeSingleNode(this.Navigator, "rsd:rsd/rsd:service", manager);

            if (serviceNavigator == null)
            {
                //  dasBlog places an empty default XML namespace on the <service> element, this is a hack/compromise
                serviceNavigator    = RsdUtility.SelectSafeSingleNode(this.Navigator, "rsd:rsd/service", manager);
            }

            if (serviceNavigator != null)
            {
                XPathNavigator engineNameNavigator      = RsdUtility.SelectSafeSingleNode(serviceNavigator, "rsd:engineName", manager);
                XPathNavigator engineLinkNavigator      = RsdUtility.SelectSafeSingleNode(serviceNavigator, "rsd:engineLink", manager);
                XPathNavigator homePageLinkNavigator    = RsdUtility.SelectSafeSingleNode(serviceNavigator, "rsd:homePageLink", manager);
                XPathNodeIterator apiIterator           = RsdUtility.SelectSafe(serviceNavigator, "rsd:apis/rsd:api", manager);

                if (engineNameNavigator != null && !String.IsNullOrEmpty(engineNameNavigator.Value))
                {
                    resource.EngineName     = engineNameNavigator.Value;
                }

                if (engineLinkNavigator != null)
                {
                    Uri link;
                    if (Uri.TryCreate(engineLinkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                    {
                        resource.EngineLink = link;
                    }
                }

                if (homePageLinkNavigator != null)
                {
                    Uri homepage;
                    if (Uri.TryCreate(homePageLinkNavigator.Value, UriKind.RelativeOrAbsolute, out homepage))
                    {
                        resource.Homepage   = homepage;
                    }
                }

                if (apiIterator != null && apiIterator.Count > 0)
                {
                    int counter = 0;
                    while (apiIterator.MoveNext())
                    {
                        RsdApplicationInterface api = new RsdApplicationInterface();
                        counter++;

                        Uri link;
                        string rpcLinkAttribute = apiIterator.Current.GetAttribute("rpcLink", String.Empty);
                        if (Uri.TryCreate(rpcLinkAttribute, UriKind.RelativeOrAbsolute, out link))
                        {
                            api.Link    = link;
                        }

                        if (api.Load(apiIterator.Current, this.Settings) || api.Link != null)
                        {
                            if (this.Settings.RetrievalLimit != 0 && counter > this.Settings.RetrievalLimit)
                            {
                                break;
                            }

                            ((Collection<RsdApplicationInterface>)resource.Interfaces).Add(api);
                        }
                    }
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(RsdUtility.SelectSafeSingleNode(this.Navigator, "rsd:rsd", manager), this.Settings);
            adapter.Fill(resource, manager);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Loads this <see cref="ApmlApplication"/> 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="ApmlApplication"/> 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="ApmlApplication"/>.
        /// </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");

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = BlogMLUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract common attributes information
            //------------------------------------------------------------
            if (BlogMLUtility.FillCommonObject(this, source, settings))
            {
                wasLoaded   = true;
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if(source.HasAttributes)
            {
                string postUrlAttribute = source.GetAttribute("post-url", String.Empty);
                string typeAttribute    = source.GetAttribute("type", String.Empty);
                string viewsAttribute   = source.GetAttribute("views", String.Empty);

                if (!String.IsNullOrEmpty(postUrlAttribute))
                {
                    Uri url;
                    if (Uri.TryCreate(postUrlAttribute, UriKind.RelativeOrAbsolute, out url))
                    {
                        this.Url    = url;
                        wasLoaded   = true;
                    }
                }

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    BlogMLPostType type = BlogMLPost.PostTypeByName(typeAttribute);
                    if (type != BlogMLPostType.None)
                    {
                        this.PostType   = type;
                        wasLoaded       = true;
                    }
                }

                if (!String.IsNullOrEmpty(viewsAttribute))
                {
                    this.Views  = viewsAttribute;
                    wasLoaded   = true;
                }
            }

            if (source.HasChildren)
            {
                XPathNavigator contentNavigator     = source.SelectSingleNode("blog:content", manager);
                XPathNavigator postNameNavigator    = source.SelectSingleNode("blog:post-name", manager);
                XPathNavigator excerptNavigator     = source.SelectSingleNode("blog:excerpt", manager);

                if (contentNavigator != null)
                {
                    BlogMLTextConstruct content = new BlogMLTextConstruct();
                    if (content.Load(contentNavigator, settings))
                    {
                        this.Content    = content;
                        wasLoaded       = true;
                    }
                }

                if (postNameNavigator != null)
                {
                    BlogMLTextConstruct name    = new BlogMLTextConstruct();
                    if (name.Load(postNameNavigator, settings))
                    {
                        this.Name   = name;
                        wasLoaded   = true;
                    }
                }

                if (excerptNavigator != null)
                {
                    BlogMLTextConstruct excerpt = new BlogMLTextConstruct();
                    if (excerpt.Load(excerptNavigator, settings))
                    {
                        this.Excerpt    = excerpt;
                        wasLoaded       = true;
                    }
                }

                if (BlogMLPost.FillPostCollections(this, source, manager, settings))
                {
                    wasLoaded   = true;
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Loads this <see cref="BlogMLAuthor"/> 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="BlogMLAuthor"/> 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="BlogMLAuthor"/>.
        /// </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");

            //------------------------------------------------------------
            //	Attempt to extract common attributes information
            //------------------------------------------------------------
            if (BlogMLUtility.FillCommonObject(this, source, settings))
            {
                wasLoaded   = true;
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if(source.HasAttributes)
            {
                string emailAttribute   = source.GetAttribute("email", String.Empty);

                if (!String.IsNullOrEmpty(emailAttribute))
                {
                    this.EmailAddress   = emailAttribute;
                    wasLoaded           = true;
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssChannel"/> 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 FillChannel(RssChannel channel, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(channel, "channel");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Load required channel information
            //------------------------------------------------------------
            XPathNavigator descriptionNavigator = navigator.SelectSingleNode("description", manager);
            XPathNavigator linkNavigator        = navigator.SelectSingleNode("link", manager);
            XPathNavigator titleNavigator       = navigator.SelectSingleNode("title", manager);
            XPathNavigator languageNavigator    = navigator.SelectSingleNode("language", manager);

            if (descriptionNavigator != null && !String.IsNullOrEmpty(descriptionNavigator.Value))
            {
                channel.Description = descriptionNavigator.Value;
            }

            if (linkNavigator != null)
            {
                Uri link;
                if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                {
                    channel.Link    = link;
                }
            }

            if (titleNavigator != null && !String.IsNullOrEmpty(titleNavigator.Value))
            {
                channel.Title       = titleNavigator.Value;
            }

            if (languageNavigator != null && !String.IsNullOrEmpty(languageNavigator.Value))
            {
                try
                {
                    CultureInfo language    = new CultureInfo(languageNavigator.Value);
                    channel.Language        = language;
                }
                catch (ArgumentException)
                {
                    System.Diagnostics.Trace.TraceWarning("Rss091SyndicationResourceAdapter unable to determine CultureInfo with a name of {0}.", languageNavigator.Value);
                }
            }

            XPathNavigator imageNavigator   = navigator.SelectSingleNode("image", manager);
            if (imageNavigator != null)
            {
                channel.Image               = new RssImage();
                Rss091SyndicationResourceAdapter.FillImage(channel.Image, imageNavigator, manager, settings);
            }

            //------------------------------------------------------------
            //	Load channel optional information
            //------------------------------------------------------------
            Rss091SyndicationResourceAdapter.FillChannelOptionals(channel, navigator, manager, settings);

            //------------------------------------------------------------
            //	Load channel collections
            //------------------------------------------------------------
            Rss091SyndicationResourceAdapter.FillChannelCollections(channel, navigator, manager, settings);

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings);
            adapter.Fill(channel);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Loads this <see cref="RssImage"/> 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="RssImage"/> 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="RssImage"/>.
        /// </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");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            wasLoaded   = this.Load(source);

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssChannel"/> collection 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 FillChannelCollections(RssChannel channel, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(channel, "channel");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Extract channel collections information
            //------------------------------------------------------------
            XPathNodeIterator skipDaysIterator  = navigator.Select("skipDays/day", manager);
            XPathNodeIterator skipHoursIterator = navigator.Select("skipHours/hour", manager);
            XPathNodeIterator itemIterator      = navigator.Select("item", manager);

            if (skipDaysIterator != null && skipDaysIterator.Count > 0)
            {
                while (skipDaysIterator.MoveNext())
                {
                    if (!String.IsNullOrEmpty(skipDaysIterator.Current.Value))
                    {
                        try
                        {
                            DayOfWeek day = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), skipDaysIterator.Current.Value, true);
                            if (!channel.SkipDays.Contains(day))
                            {
                                channel.SkipDays.Add(day);
                            }
                        }
                        catch (ArgumentException)
                        {
                            System.Diagnostics.Trace.TraceWarning("Rss091SyndicationResourceAdapter unable to determine DayOfWeek with a name of {0}.", skipDaysIterator.Current.Value);
                        }
                    }
                }
            }

            if (skipHoursIterator != null && skipHoursIterator.Count > 0)
            {
                while (skipHoursIterator.MoveNext())
                {
                    int hour;
                    if (Int32.TryParse(skipHoursIterator.Current.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out hour))
                    {
                        hour    = hour - 1; // Convert to zero-based range

                        if (!channel.SkipHours.Contains(hour) && (hour >= 0 && hour <= 23))
                        {
                            channel.SkipHours.Add(hour);
                        }
                        else
                        {
                            System.Diagnostics.Trace.TraceWarning("Rss091SyndicationResourceAdapter unable to add duplicate or out-of-range skip hour with a value of {0}.", hour);
                        }
                    }
                }
            }

            if (itemIterator != null && itemIterator.Count > 0)
            {
                int counter = 0;
                while (itemIterator.MoveNext())
                {
                    RssItem item = new RssItem();
                    counter++;

                    if (settings.RetrievalLimit != 0 && counter > settings.RetrievalLimit)
                    {
                        break;
                    }

                    XPathNavigator titleNavigator       = itemIterator.Current.SelectSingleNode("title", manager);
                    XPathNavigator linkNavigator        = itemIterator.Current.SelectSingleNode("link", manager);
                    XPathNavigator descriptionNavigator = itemIterator.Current.SelectSingleNode("description", manager);

                    if (titleNavigator != null)
                    {
                        item.Title          = titleNavigator.Value;
                    }

                    if (descriptionNavigator != null)
                    {
                        item.Description    = descriptionNavigator.Value;
                    }

                    if (linkNavigator != null)
                    {
                        Uri link;
                        if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                        {
                            item.Link       = link;
                        }
                    }

                    SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(itemIterator.Current, settings);
                    adapter.Fill(item);

                    ((Collection<RssItem>)channel.Items).Add(item);
                }
            }
        }
        /// <summary>
        /// Creates a <see cref="AtomPersonConstruct"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <returns>A <see cref="AtomPersonConstruct"/> instance initialized using the supplied <paramref name="source"/>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a Atom 0.3 Person construct.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> 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 AtomPersonConstruct CreatePerson(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            AtomPersonConstruct person  = new AtomPersonConstruct();

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract common attributes information
            //------------------------------------------------------------
            AtomUtility.FillCommonObjectAttributes(person, source);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNavigator nameNavigator    = source.SelectSingleNode("atom:name", manager);
            XPathNavigator urlNavigator     = source.SelectSingleNode("atom:url", manager);
            XPathNavigator emailNavigator   = source.SelectSingleNode("atom:email", manager);

            if (nameNavigator != null)
            {
                person.Name         = nameNavigator.Value;
            }

            if (urlNavigator != null)
            {
                Uri uri;
                if (Uri.TryCreate(urlNavigator.Value, UriKind.RelativeOrAbsolute, out uri))
                {
                    person.Uri      = uri;
                }
            }

            if (emailNavigator != null)
            {
                person.EmailAddress = emailNavigator.Value;
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(person, manager);

            return person;
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssImage"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>.
        /// </summary>
        /// <param name="image">The <see cref="RssImage"/> to be filled.</param>
        /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the image 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="image"/> 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 FillImage(RssImage image, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(image, "image");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract image information
            //------------------------------------------------------------
            XPathNavigator linkNavigator    = navigator.SelectSingleNode("link", manager);
            XPathNavigator titleNavigator   = navigator.SelectSingleNode("title", manager);
            XPathNavigator urlNavigator     = navigator.SelectSingleNode("url", manager);

            XPathNavigator descriptionNavigator = navigator.SelectSingleNode("description", manager);
            XPathNavigator heightNavigator      = navigator.SelectSingleNode("height", manager);
            XPathNavigator widthNavigator       = navigator.SelectSingleNode("width", manager);

            if (linkNavigator != null)
            {
                Uri link;
                if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                {
                    image.Link      = link;
                }
            }
            if (titleNavigator != null)
            {
                if (!String.IsNullOrEmpty(titleNavigator.Value))
                {
                    image.Title     = titleNavigator.Value;
                }
            }
            if (urlNavigator != null)
            {
                Uri url;
                if (Uri.TryCreate(urlNavigator.Value, UriKind.RelativeOrAbsolute, out url))
                {
                    image.Url       = url;
                }
            }

            if (descriptionNavigator != null)
            {
                image.Description   = descriptionNavigator.Value;
            }
            if (heightNavigator != null)
            {
                int height;
                if (Int32.TryParse(heightNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out height))
                {
                    image.Height    = height < RssImage.HeightMaximum ? height : RssImage.HeightMaximum;
                }
            }
            if (widthNavigator != null)
            {
                int width;
                if (Int32.TryParse(widthNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out width))
                {
                    image.Width     = width < RssImage.WidthMaximum ? width : RssImage.WidthMaximum;
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings);
            adapter.Fill(image);
        }
        /// <summary>
        /// Modifies the <see cref="AtomEntry"/> to match the supplied <see cref="XPathNavigator"/> data source.
        /// </summary>
        /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents an Atom 0.3 element.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> 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 FillEntry(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(entry, "entry");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            AtomUtility.FillCommonObjectAttributes(entry, source);

            XPathNavigator idNavigator          = source.SelectSingleNode("atom:id", manager);
            XPathNavigator titleNavigator       = source.SelectSingleNode("atom:title", manager);
            XPathNavigator modifiedNavigator    = source.SelectSingleNode("atom:modified", manager);

            if (idNavigator != null)
            {
                entry.Id            = new AtomId();
                entry.Id.Load(idNavigator, settings);
            }

            if (titleNavigator != null)
            {
                entry.Title         = Atom03SyndicationResourceAdapter.CreateTextContent(titleNavigator, manager, settings);
            }

            if (modifiedNavigator != null)
            {
                DateTime updatedOn;
                if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(modifiedNavigator.Value, out updatedOn))
                {
                    entry.UpdatedOn = updatedOn;
                }
            }

            Atom03SyndicationResourceAdapter.FillEntryOptionals(entry, source, manager, settings);
            Atom03SyndicationResourceAdapter.FillEntryCollections(entry, source, manager, settings);

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(entry, manager);
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssTextInput"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>.
        /// </summary>
        /// <param name="textInput">The <see cref="RssTextInput"/> to be filled.</param>
        /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the text input 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="textInput"/> 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 FillTextInput(RssTextInput textInput, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(textInput, "textInput");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract text input information
            //------------------------------------------------------------
            XPathNavigator descriptionNavigator = navigator.SelectSingleNode("description", manager);
            XPathNavigator linkNavigator        = navigator.SelectSingleNode("link", manager);
            XPathNavigator nameNavigator        = navigator.SelectSingleNode("name", manager);
            XPathNavigator titleNavigator       = navigator.SelectSingleNode("title", manager);

            if (descriptionNavigator != null)
            {
                if (!String.IsNullOrEmpty(descriptionNavigator.Value))
                {
                    textInput.Description   = descriptionNavigator.Value;
                }
            }
            if (linkNavigator != null)
            {
                Uri link;
                if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                {
                    textInput.Link          = link;
                }
            }
            if (nameNavigator != null)
            {
                if (!String.IsNullOrEmpty(nameNavigator.Value))
                {
                    textInput.Name          = nameNavigator.Value;
                }
            }
            if (titleNavigator != null)
            {
                if (!String.IsNullOrEmpty(titleNavigator.Value))
                {
                    textInput.Title         = titleNavigator.Value;
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings);
            adapter.Fill(textInput);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Loads this <see cref="ApmlApplication"/> 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="ApmlApplication"/> 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="ApmlApplication"/>.
        /// </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");

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = BlogMLUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract common attributes information
            //------------------------------------------------------------
            if (BlogMLUtility.FillCommonObject(this, source, settings))
            {
                wasLoaded   = true;
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if(source.HasAttributes)
            {
                string userNameAttribute    = source.GetAttribute("user-name", String.Empty);
                string userEmailAttribute   = source.GetAttribute("user-email", String.Empty);
                string userUrlAttribute     = source.GetAttribute("user-url", String.Empty);

                if (!String.IsNullOrEmpty(userNameAttribute))
                {
                    this.UserName   = userNameAttribute;
                    wasLoaded       = true;
                }

                if (!String.IsNullOrEmpty(userEmailAttribute))
                {
                    this.UserEmailAddress   = userEmailAttribute;
                    wasLoaded               = true;
                }

                if (!String.IsNullOrEmpty(userUrlAttribute))
                {
                    Uri url;
                    if (Uri.TryCreate(userUrlAttribute, UriKind.RelativeOrAbsolute, out url))
                    {
                        this.UserUrl    = url;
                        wasLoaded       = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNavigator contentNavigator = source.SelectSingleNode("blog:content", manager);
                if (contentNavigator != null)
                {
                    BlogMLTextConstruct content = new BlogMLTextConstruct();
                    if (content.Load(contentNavigator))
                    {
                        this.Content    = content;
                        wasLoaded       = true;
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssCloud"/> using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>.
        /// </summary>
        /// <param name="cloud">The <see cref="RssCloud"/> to be filled.</param>
        /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the cloud 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 of the <see cref="RssFeed"/>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="cloud"/> 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 FillCloud(RssCloud cloud, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNull(cloud, "cloud");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract category information
            //------------------------------------------------------------
            if (navigator.HasAttributes)
            {
                string domainAttribute              = navigator.GetAttribute("domain", String.Empty);
                string portAttribute                = navigator.GetAttribute("port", String.Empty);
                string pathAttribute                = navigator.GetAttribute("path", String.Empty);
                string registerProcedureAttribute   = navigator.GetAttribute("registerProcedure", String.Empty);
                string protocolAttribute            = navigator.GetAttribute("protocol", String.Empty);

                if (!String.IsNullOrEmpty(domainAttribute))
                {
                    cloud.Domain            = domainAttribute;
                }

                if (!String.IsNullOrEmpty(portAttribute))
                {
                    int port;
                    if (Int32.TryParse(portAttribute, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out port))
                    {
                        cloud.Port          = port;
                    }
                }

                if (!String.IsNullOrEmpty(pathAttribute))
                {
                    cloud.Path              = pathAttribute;
                }

                if (!String.IsNullOrEmpty(registerProcedureAttribute))
                {
                    cloud.RegisterProcedure = registerProcedureAttribute;
                }

                if (!String.IsNullOrEmpty(protocolAttribute))
                {
                    RssCloudProtocol protocol   = RssCloud.CloudProtocolByName(protocolAttribute);
                    if (protocol != RssCloudProtocol.None)
                    {
                        cloud.Protocol      = protocol;
                    }
                }
            }

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(navigator, settings);
            adapter.Fill(cloud);
        }