示例#1
0
        internal static AtomPersonConstruct Parse(XPathNavigator navigator)
        {
            AtomPersonConstruct personElement = new AtomPersonConstruct();

            XPathNavigator    nav  = navigator.Clone();
            XPathNodeIterator iter = nav.SelectDescendants(XPathNodeType.Element, true);

            while (iter.MoveNext())
            {
                string name = iter.Current.Name.ToLower();
                int    idx  = name.IndexOf(":");
                if (idx != -1)
                {
                    name = name.Split(new char[] { ':' }, 2)[1];
                }

                switch (name)
                {
                case "contributor":
                case "author":
                    try
                    {
                        personElement.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
                    }
                    catch {}
                    personElement.LocalName = name;
                    break;

                case "name":
                    personElement.Name = iter.Current.Value;
                    break;

                case "url":
                    personElement.Url = resolveUri(xmlBaseRootUri, iter.Current.Value);
                    break;

                case "email":
                    personElement.Email = iter.Current.Value;
                    break;
                }
            }

            return(personElement);
        }
		public void TestAuthor()
		{
			AtomPersonConstruct author = new AtomPersonConstruct();
			author.Email = "*****@*****.**";
			author.Name = "Uncle Tom";
			author.Url = testUri;

			entry.Author = author;
			
			entry.Author.ToString();

			Assert.AreEqual(author.LocalName, "author");
			Assert.AreEqual(author.FullName, "atom:author");
            Assert.AreSame(entry.Author, author);
		}
        /// <summary>
        /// </summary>
        /// <param name="navigator"></param>
        /// <returns></returns>
        internal static AtomPersonConstruct parse(XPathNavigator navigator) {
            AtomPersonConstruct result = new AtomPersonConstruct();

            XPathNavigator temp_navigator = navigator.Clone();
            XPathNodeIterator it = temp_navigator.SelectDescendants( XPathNodeType.Element, true );

            while ( it.MoveNext() ) {
                string name = it.Current.Name.ToLower();
                int colon_index = name.IndexOf( ":" );

                if ( colon_index != -1 )
                    name = name.Split( new char[] { ':' }, 2 )[1];

                switch ( name ) {
                    case "contributor":
                    case "author":
                        try {
                            result.XmlLang = AtomUtility.parseLanguage( it.Current.XmlLang );
                        } catch { }
                        result.LocalName = name;
                        break;

                    case "name":
                        result.Name = it.Current.Value;
                        break;

                    case "location":
                    case "url":
                        result.Url = resolveUri( xmlBaseRootUri, it.Current.Value );
                        break;

                    case "email":
                        result.Email = it.Current.Value;
                        break;
                }
            }
            return result;
        }
		public void TestContributors()
		{
			AtomPersonConstruct contributor = new AtomPersonConstruct("contributor");
			contributor.Email = "*****@*****.**";
			contributor.Name = "Uncle Bob";
			contributor.Url = testUri;

			entry.Contributors.Add(contributor);


			Assert.AreEqual(contributor.LocalName, "contributor");
			Assert.AreEqual(contributor.FullName, "atom:contributor");
			Assert.AreSame(entry.Contributors[0], contributor);
			Assert.AreEqual(entry.Contributors[0], contributor);
		}
示例#5
0
        internal static AtomEntry Parse(XPathNavigator navigator)
        {
            AtomEntry entry = new AtomEntry();

            XPathNavigator    nav  = navigator.Clone();
            XPathNodeIterator iter = nav.SelectDescendants(XPathNodeType.All, true);

            while (iter.MoveNext())
            {
                string name = iter.Current.Name.ToLower();
                int    idx  = name.IndexOf(":");
                if (idx != -1)
                {
                    string prefix;
                    prefix = name.Split(new char[] { ':' }, 2)[0];
                    if (prefix == "atom")
                    {
                        name = name.Split(new char[] { ':' }, 2)[1];
                    }
                }

                switch (name)
                {
                case "entry":
                    try
                    {
                        entry.Uri     = FindAlternateUri(iter.Current);
                        entry.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
                    }
                    catch {}
                    break;

                case "title":
                    AtomContentConstruct content = AtomContentConstruct.Parse(iter.Current);
                    entry.Title = content;
                    break;

                case "link":
                    entry.Links.Add(AtomLink.Parse(iter.Current));
                    break;

                case "author":
                    entry.Author = AtomPersonConstruct.Parse(iter.Current);
                    break;

                case "contributor":
                    entry.Contributors.Add(AtomPersonConstruct.Parse(iter.Current));
                    break;

                case "id":
                    entry.Id = new Uri(iter.Current.Value);
                    break;

                case "modified":
                    entry.Modified = AtomDateConstruct.Parse(iter.Current);
                    break;

                case "issued":
                    entry.Issued = AtomDateConstruct.Parse(iter.Current);
                    break;

                case "created":
                    entry.Created = AtomDateConstruct.Parse(iter.Current);
                    break;

                case "summary":
                    entry.Summary = AtomContentConstruct.Parse(iter.Current);
                    break;

                case "content":
                    entry.Contents.Add(AtomContent.Parse(iter.Current));
                    break;

                case "dc:title":
                case "dc:creator":
                case "dc:subject":
                case "dc:description":
                case "dc:publisher":
                case "dc:contributor":
                case "dc:date":
                case "dc:type":
                case "dc:format":
                case "dc:identifier":
                case "dc:source":
                case "dc:language":
                case "dc:relation":
                case "dc:coverage":
                case "dc:rights":
                    entry.AdditionalElements.Add(DcElement.Parse(iter.Current));
                    break;
                }
            }

            return(entry);
        }
		internal static AtomPersonConstruct Parse(XPathNavigator navigator)
		{
			AtomPersonConstruct personElement = new AtomPersonConstruct();

			XPathNavigator nav = navigator.Clone();
			XPathNodeIterator iter = nav.SelectDescendants(XPathNodeType.Element, true);
			
			while(iter.MoveNext())
			{
				string name = iter.Current.Name.ToLower();
				int idx = name.IndexOf(":");
				if(idx != -1)
					name = name.Split(new char[] {':'}, 2)[1];

				switch(name)
				{
					case "contributor":
					case "author":
						try
						{
							personElement.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
						}
						catch {}
						personElement.LocalName = name;
						break;

					case "name":
						personElement.Name = iter.Current.Value;
						break;

					case "url":
						personElement.Url = resolveUri(xmlBaseRootUri, iter.Current.Value);
						break;

					case "email":
						personElement.Email = iter.Current.Value;
						break;
				}
			}

			return personElement;
		}
示例#7
0
        internal static AtomFeed Parse(XPathNavigator navigator)
        {
            AtomFeed feed = new AtomFeed();

            XPathNavigator    nav  = navigator.Clone();
            XPathNodeIterator iter = nav.SelectChildren(XPathNodeType.All);

            do
            {
                string name = iter.Current.Name.ToLower();
                int    idx  = name.IndexOf(":");
                if (idx != -1)
                {
                    name = name.Split(new char[] { ':' }, 2)[1];
                }

                switch (name)
                {
                case "feed":
                {
                    try
                    {
                        XPathNavigatorReader reader = new XPathNavigatorReader(nav);
                        string baseUri = reader.GetAttribute("base", XmlNamespaces.Xml);
                        if (baseUri != null && baseUri.Length > 0)
                        {
                            feed.XmlBase = new Uri(baseUri);
                        }
                    }
                    catch {}

                    try
                    {
                        feed.Uri = FindAlternateUri(iter.Current);
                    }
                    catch {}

                    try
                    {
                        feed.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
                    }
                    catch {}

                    XPathNodeIterator attrIterator = nav.Select("@*");
                    while (attrIterator.MoveNext())
                    {
                        if (attrIterator.Current.Name.ToLower() == "version")
                        {
                            if (attrIterator.Current.Value != DefaultValues.AtomVersion)
                            {
                                string msg = String.Format("Atom {0} version is not supported!", attrIterator.Current.Value);
                                throw new InvalidOperationException(msg);
                            }
                        }
                    }
                    break;
                }

                case "title":
                    AtomContentConstruct content = AtomContentConstruct.Parse(iter.Current);
                    feed.Title = content;
                    break;

                case "link":
                    feed.Links.Add(AtomLink.Parse(iter.Current));
                    break;

                case "author":
                    feed.Author = AtomPersonConstruct.Parse(iter.Current);
                    break;

                case "contributor":
                    feed.Contributors.Add(AtomPersonConstruct.Parse(iter.Current));
                    break;

                case "tagline":
                    feed.Tagline = AtomContentConstruct.Parse(iter.Current);
                    break;

                case "id":
                    feed.Id = new Uri(iter.Current.Value);
                    break;

                case "copyright":
                    feed.Copyright = AtomContentConstruct.Parse(iter.Current);
                    break;

                case "info":
                    feed.Info = AtomContentConstruct.Parse(iter.Current);
                    break;

                case "modified":
                    feed.Modified = AtomDateConstruct.Parse(iter.Current);
                    break;

                case "entry":
                    feed.Entries.Add(AtomEntry.Parse(iter.Current));
                    break;
                }
            } while(iter.MoveNext());

            return(feed);
        }
示例#8
0
		public void TestContributors()
		{
            AtomPersonConstruct contributor = new AtomPersonConstruct("contributor", new Uri("http://purl.org/atom/ns#"));
			contributor.Email = "*****@*****.**";
			contributor.Name = "Uncle Bob";
			contributor.Url = testUri;

			feed.Contributors.Add(contributor);

			Assert.AreEqual(contributor.LocalName, "contributor");
			Assert.AreEqual(contributor.FullName, "atom:contributor");
			Assert.AreSame(feed.Contributors[0], contributor);
			Assert.AreEqual(feed.Contributors[0], contributor);
		}
示例#9
0
		public void TestAuthor()
		{
            AtomPersonConstruct author = new AtomPersonConstruct(new Uri("http://purl.org/atom/ns#"));
			author.Email = "*****@*****.**";
			author.Name = "Uncle Tom";
			author.Url = testUri;

			feed.Author = author;

			Assert.AreEqual(author.LocalName, "author");
			Assert.AreEqual(author.FullName, "atom:author");
            Assert.AreSame(feed.Author, author);
		}