コード例 #1
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="AtomPersonConstruct"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="AtomPersonConstruct"/> 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="AtomPersonConstruct"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

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

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

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

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

            if (nameNavigator != null)
            {
                this.Name = nameNavigator.Value;
                wasLoaded = true;
            }

            if (uriNavigator != null)
            {
                Uri uri;
                if (Uri.TryCreate(uriNavigator.Value, UriKind.RelativeOrAbsolute, out uri))
                {
                    this.Uri  = uri;
                    wasLoaded = true;
                }
            }

            if (emailNavigator != null)
            {
                this.EmailAddress = emailNavigator.Value;
                wasLoaded         = true;
            }

            return(wasLoaded);
        }
コード例 #2
0
        /// <summary>
        /// Loads this <see cref="AtomSource"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="AtomSource"/> 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="AtomSource"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable);

            if (AtomUtility.FillCommonObjectAttributes(this, source))
            {
                wasLoaded = true;
            }
            XPathNavigator idNavigator      = source.SelectSingleNode("atom:id", manager);
            XPathNavigator titleNavigator   = source.SelectSingleNode("atom:title", manager);
            XPathNavigator updatedNavigator = source.SelectSingleNode("atom:updated", manager);

            if (idNavigator != null)
            {
                this.Id = new AtomId();
                if (this.Id.Load(idNavigator))
                {
                    wasLoaded = true;
                }
            }

            if (titleNavigator != null)
            {
                this.Title = new AtomTextConstruct();
                if (this.Title.Load(titleNavigator))
                {
                    wasLoaded = true;
                }
            }

            if (updatedNavigator != null)
            {
                DateTime updatedOn;
                if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn))
                {
                    this.UpdatedOn = updatedOn;
                    wasLoaded      = true;
                }
            }

            if (this.LoadOptionals(source, manager))
            {
                wasLoaded = true;
            }

            if (this.LoadCollections(source, manager))
            {
                wasLoaded = true;
            }

            return(wasLoaded);
        }
コード例 #3
0
        /// <summary>
        /// Modifies the <see cref="IAtomCommonObjectAttributes"/> to match the data source.
        /// </summary>
        /// <param name="target">The object that implements the <see cref="IAtomCommonObjectAttributes"/> interface to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract Atom common attribute information from.</param>
        /// <returns><b>true</b> if the <paramref name="target"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="target"/> 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>
        public static bool FillCommonObjectAttributes(IAtomCommonObjectAttributes target, XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

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

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

            //------------------------------------------------------------
            //	Attempt to extract xml:base attribute information
            //------------------------------------------------------------
            string xmlBaseAttribute = source.GetAttribute("base", manager.LookupNamespace("xml"));

            if (!String.IsNullOrEmpty(xmlBaseAttribute))
            {
                Uri baseUri;
                if (Uri.TryCreate(xmlBaseAttribute, UriKind.RelativeOrAbsolute, out baseUri))
                {
                    target.BaseUri = baseUri;
                    wasLoaded      = true;
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract xml:lang attribute information
            //------------------------------------------------------------
            string xmlLangAttribute = source.GetAttribute("lang", manager.LookupNamespace("xml"));

            if (!String.IsNullOrEmpty(xmlLangAttribute))
            {
                try
                {
                    CultureInfo language = new CultureInfo(source.XmlLang);
                    target.Language = language;
                    wasLoaded       = true;
                }
                catch (ArgumentException)
                {
                    System.Diagnostics.Trace.TraceWarning("Unable to determine CultureInfo with a name of {0}.", source.XmlLang);
                }
            }

            return(wasLoaded);
        }
コード例 #4
0
        /// <summary>
        /// Loads this <see cref="AtomContent"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="AtomContent"/> 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="AtomContent"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");

            XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable);

            if (AtomUtility.FillCommonObjectAttributes(this, source))
            {
                wasLoaded = true;
            }

            if (source.HasAttributes)
            {
                string typeAttribute   = source.GetAttribute("type", String.Empty);
                string sourceAttribute = source.GetAttribute("src", String.Empty);

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    this.ContentType = typeAttribute;
                    wasLoaded        = true;
                }
                if (!String.IsNullOrEmpty(sourceAttribute))
                {
                    Uri src;
                    if (Uri.TryCreate(sourceAttribute, UriKind.RelativeOrAbsolute, out src))
                    {
                        this.Source = src;
                        wasLoaded   = true;
                    }
                }
            }

            if (String.Compare(this.ContentType, "xhtml", StringComparison.OrdinalIgnoreCase) == 0)
            {
                XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager);
                if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value))
                {
                    this.Content = xhtmlDivNavigator.InnerXml;
                    wasLoaded    = true;
                }
            }
            else if (!String.IsNullOrEmpty(source.Value))
            {
                this.Content = source.Value;
                wasLoaded    = true;
            }

            return(wasLoaded);
        }
コード例 #5
0
        /// <summary>
        /// Loads this <see cref="AtomTextConstruct"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="AtomTextConstruct"/> 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="AtomTextConstruct"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable);

            if (AtomUtility.FillCommonObjectAttributes(this, source))
            {
                wasLoaded = true;
            }
            if (source.HasAttributes)
            {
                string typeAttribute = source.GetAttribute("type", String.Empty);
                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    AtomTextConstructType type = AtomTextConstruct.ConstructTypeByName(typeAttribute);
                    if (type != AtomTextConstructType.None)
                    {
                        this.TextType = type;
                        wasLoaded     = true;
                    }
                }
            }

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

            return(wasLoaded);
        }
コード例 #6
0
        /// <summary>
        /// Loads this <see cref="AtomPersonConstruct"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="AtomPersonConstruct"/> 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="AtomPersonConstruct"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable);

            if (AtomUtility.FillCommonObjectAttributes(this, source))
            {
                wasLoaded = true;
            }
            XPathNavigator nameNavigator  = source.SelectSingleNode("atom:name", manager);
            XPathNavigator uriNavigator   = source.SelectSingleNode("atom:uri", manager);
            XPathNavigator emailNavigator = source.SelectSingleNode("atom:email", manager);

            if (nameNavigator != null)
            {
                this.Name = nameNavigator.Value;
                wasLoaded = true;
            }

            if (uriNavigator != null)
            {
                Uri uri;
                if (Uri.TryCreate(uriNavigator.Value, UriKind.RelativeOrAbsolute, out uri))
                {
                    this.Uri  = uri;
                    wasLoaded = true;
                }
            }

            if (emailNavigator != null)
            {
                this.EmailAddress = emailNavigator.Value;
                wasLoaded         = true;
            }

            return(wasLoaded);
        }
コード例 #7
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="AtomTextConstruct"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="AtomTextConstruct"/> 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="AtomTextConstruct"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

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

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

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

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string typeAttribute = source.GetAttribute("type", String.Empty);
                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    AtomTextConstructType type = AtomTextConstruct.ConstructTypeByName(typeAttribute);
                    if (type != AtomTextConstructType.None)
                    {
                        this.TextType = type;
                        wasLoaded     = true;
                    }
                }
            }

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

            return(wasLoaded);
        }
コード例 #8
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="AtomContent"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="AtomContent"/> 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="AtomContent"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

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

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

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

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string typeAttribute   = source.GetAttribute("type", String.Empty);
                string sourceAttribute = source.GetAttribute("src", String.Empty);

                if (!String.IsNullOrEmpty(typeAttribute))
                {
                    this.ContentType = typeAttribute;
                    wasLoaded        = true;
                }
                if (!String.IsNullOrEmpty(sourceAttribute))
                {
                    Uri src;
                    if (Uri.TryCreate(sourceAttribute, UriKind.RelativeOrAbsolute, out src))
                    {
                        this.Source = src;
                        wasLoaded   = true;
                    }
                }
            }

            if (String.Compare(this.ContentType, "xhtml", StringComparison.OrdinalIgnoreCase) == 0)
            {
                XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager);
                if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value))
                {
                    this.Content = xhtmlDivNavigator.InnerXml;
                    wasLoaded    = true;
                }
            }
            else if (!String.IsNullOrEmpty(source.Value))
            {
                this.Content = source.Value;
                wasLoaded    = true;
            }

            return(wasLoaded);
        }