public void Init()
		{
			entry = new AtomEntry();
			testUri = new Uri("http://www.w3.org");
			entriespath = @"..\..\tests\entries\";
			files = Directory.GetFiles(entriespath);
		}
Exemple #2
0
		public void TestMultipleMultipartsContent()
		{
            AtomEntry entry = new AtomEntry(new Uri("http://purl.org/atom/ns#"));

            AtomContent content = new AtomContent(new Uri("http://purl.org/atom/ns#"));
			content.Content = "sample text";
			content.Mode = Mode.Xml;
			content.Type = MediaType.MultipartAlternative;
			content.XmlLang = Language.en_US;

			entry.Contents.Add(content);

            content = new AtomContent(new Uri("http://purl.org/atom/ns#"));
			content.Content = "sample text";
			content.Mode = Mode.Xml;
			content.Type = MediaType.MultipartAlternative;
			content.XmlLang = Language.en_US;
			entry.Contents.Add(content);
		}
		public void TestNameIsNotEmail()
		{
			foreach(string file in files)
			{
				entry = AtomEntry.Load(file);
				if(entry.Author != null)
					Assert.IsFalse(AU.Utils.IsEmail(entry.Author.Name));
				foreach(AtomPersonConstruct contributor in entry.Contributors)
					Assert.IsFalse(AU.Utils.IsEmail(contributor.Name));
			}
		}
		public void TestXmlFragment()
		{
			string filename = "test";
			for(int i = 0; i < files.Length; i++)
			{
				StreamReader reader = new StreamReader(files[i]);
				string content = reader.ReadToEnd();
				entry = AtomEntry.LoadXml(content);
				Assert.IsNotNull(entry);
				entry.Save(filename);
				File.Delete(filename);
			}
		}
		public void TestXmlReaderXmlWriter()
		{
			for(int i = 0; i < files.Length; i++)
			{
				XmlTextReader reader = new XmlTextReader(files[i]);
				entry = AtomEntry.Load(reader);
				Assert.IsNotNull(entry);
				MemoryStream stream = new MemoryStream();
				XmlTextWriter writer = new XmlTextWriter(stream,
					System.Text.Encoding.Default);
				entry.Save(writer);
				stream.Close();
			}
		}
		public void TestTextReaderWriter()
		{
			for(int i = 0; i < files.Length; i++)
			{
				StreamReader reader = new StreamReader(files[i]);
				entry = AtomEntry.Load(reader);
				Assert.IsNotNull(entry);
				MemoryStream stream = new MemoryStream();
				StreamWriter w = new StreamWriter(stream);
				entry.Save(w);
				stream.Close();
			}
		}
		public void TestStream()
		{
			for(int i = 0; i < files.Length; i++)
			{
				FileStream stream = File.OpenRead(files[i]);
				entry = AtomEntry.Load(stream);
				Assert.IsNotNull(entry);
				MemoryStream memStream = new MemoryStream();
				entry.Save(memStream);
				stream.Close();
			}
		}
		public void TestInvalidEntries()
		{
			string filename = "test";
			entriespath = @"..\..\tests\invalidentries\";
			files = Directory.GetFiles(entriespath);
			for(int i = 0; i < files.Length; i++)
			{
				entry = AtomEntry.Load(files[i]);
				Assert.IsNotNull(entry);
				entry.Save(filename);
				File.Delete(filename);
			}
		}
Exemple #9
0
		internal void Write(AtomEntry entry)
		{
			this.WriteEntry(entry);
		}
		public void TestUri()
		{
			for(int i = 0; i < files.Length; i++)
			{
				Console.WriteLine("{0}: {1}", i, files[i]);
				entry = AtomEntry.Load(files[i]);
				Assert.IsNotNull(entry.Uri);
			}
		}
Exemple #11
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);
        }
Exemple #12
0
		public void TestSaveToFile()
		{
			string filename = "test";
			for(int i = 0; i < files.Length; i++)
			{
                entry = AtomEntry.Load(files[i], new Uri("http://purl.org/atom/ns#"));
				Assert.IsNotNull(entry);
				entry.Save(filename);
				File.Delete(filename);
			}
		}
Exemple #13
0
		public void TestUri()
		{
			for(int i = 0; i < files.Length; i++)
			{
				Console.WriteLine("{0}: {1}", i, files[i]);
                entry = AtomEntry.Load(files[i], new Uri("http://purl.org/atom/ns#"));
				Assert.IsNotNull(entry.Uri);
			}
		}
Exemple #14
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);
        }
		public void TestSaveToFile()
		{
			string filename = "test";
			for(int i = 0; i < files.Length; i++)
			{
				entry = AtomEntry.Load(files[i]);
				Assert.IsNotNull(entry);
				entry.Save(filename);
				File.Delete(filename);
			}
		}
		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;
		}
Exemple #17
0
		/// <summary>
		/// Writes the Atom entry body.
		/// </summary>
		private void WriteEntry(AtomEntry entry)
		{
			if(this._writer == null)
				throw new InvalidOperationException("AtomWriter has been closed, and can not be written to.");

			if(entry == null)
				throw new RequiredElementNotFoundException("AtomEntry cannot be null.");

			this._writer.WriteRaw(entry.ToString());

			this._writer.Flush();
			this._writer.Close();
			this._writer = null;
		}