Ejemplo n.º 1
0
		public void TestTitle()
		{
            AtomContentConstruct title = new AtomContentConstruct(new Uri("http://purl.org/atom/ns#"));
			title.Content = "sample text";
			title.Mode = Mode.Xml;
			title.Type = MediaType.TextPlain;

			feed.Title = title;

			Assert.AreEqual(title.LocalName, "title");
			Assert.AreEqual(title.FullName, "atom:title");
			Assert.AreSame(feed.Title, title);
		}
Ejemplo n.º 2
0
		public void TestTitle()
		{
			AtomContentConstruct title = new AtomContentConstruct();
			title.Content = "sample text";
			title.Mode = Mode.Xml;
			title.Type = MediaType.TextPlain;

			entry.Title = title;

			Assert.AreEqual(title.LocalName, "title");
			Assert.AreEqual(title.FullName, "atom:title");
			Assert.AreSame(entry.Title, title);
		}
Ejemplo n.º 3
0
		public void TestSummary()
		{
			AtomContentConstruct summary = new AtomContentConstruct("summary");
			summary.Content = "sample text";
			summary.Mode = Mode.Xml;
			summary.Type = MediaType.TextPlain;

			entry.Summary = summary;

			Assert.AreEqual(summary.LocalName, "summary");
			Assert.AreEqual(summary.FullName, "atom:summary");
			Assert.AreSame(entry.Summary, summary);
		}
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
		public void TestInfo()
		{
			AtomContentConstruct info = new AtomContentConstruct("info");
			info.Content = "Some not so useful infos";
			info.Mode = Mode.Xml;
			info.Type = MediaType.TextPlain;

			feed.Info = info;

			Assert.AreEqual(info.LocalName, "info");
			Assert.AreEqual(info.FullName, "atom:info");
			Assert.AreSame(feed.Info, info);
		}
Ejemplo n.º 6
0
		public void TestCopyright()
		{
			AtomContentConstruct copyright = new AtomContentConstruct("copyright");
			copyright.Content = " 2003 Buffalo Bill Corporations";
			copyright.Mode = Mode.Xml;
			copyright.Type = MediaType.TextPlain;

			feed.Copyright = copyright;
			Assert.AreEqual(copyright.LocalName, "copyright");
			Assert.AreEqual(copyright.FullName, "atom:copyright");
			Assert.AreSame(feed.Copyright, copyright);
		}
Ejemplo n.º 7
0
		public void TestTagline()
		{
			AtomContentConstruct tagline = new AtomContentConstruct("tagline");
			tagline.Content = "sample text";
			tagline.Mode = Mode.Xml;
			tagline.Type = MediaType.TextPlain;

			feed.Tagline = tagline;

			Assert.AreEqual(tagline.LocalName, "tagline");
			Assert.AreEqual(tagline.FullName, "atom:tagline");
			Assert.AreSame(feed.Tagline, tagline);
		}
Ejemplo n.º 8
0
        internal static AtomContentConstruct Parse(XPathNavigator navigator, Uri ns)
        {
            AtomContentConstruct contentElement = new AtomContentConstruct(ns);
            string content = String.Empty;

            XPathNavigator nav = navigator.Clone();

            // select the element itself
            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 "title":
                    case "copyright":
                    case "info":
                    case "tagline":
                    case "summary":
                    case "content":
                        try
                        {
                            contentElement.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
                        }
                        catch { }
                        contentElement.LocalName = name;
                        XPathNavigatorReader reader = new XPathNavigatorReader(iter.Current);
                        bool fread = reader.Read();
                        if (iter.Current.HasChildren) // dblock: bug 149
                        {
                            content = reader.ReadInnerXml();
                        }
                        break;
                }
            }

            // select the attributes
            iter = nav.Select("@*");
            do
            {
                switch (iter.Current.Name.ToLower())
                {
                    case "type":

                        switch (iter.Current.Value)
                        {
                                // shortcut used, doesn't look like compliant to spec, should be text/html, mode="escaped"
                            case "html":
                                contentElement.Mode = Mode.Escaped;
                                contentElement.Type = MediaType.TextHtml;
                                break;
                            default:
                                contentElement.Type = Utils.Utils.ParseMediaType(
                                    iter.Current.Value);
                                break;
                        }
                        break;

                    case "mode":
                        {
                            switch (iter.Current.Value.ToLower())
                            {
                                case "escaped":
                                    contentElement.Mode = Mode.Escaped;
                                    break;

                                case "base64":
                                    contentElement.Mode = Mode.Base64;
                                    break;
                            }
                            break;
                        }
                }
            } while (iter.MoveNext());

            switch (contentElement.Mode)
            {
                case Mode.Escaped:
                    content = Utils.Utils.Unescape(content);
                    break;

                case Mode.Base64:
                    content = Encoding.Unicode.GetString(
                        Utils.Utils.Base64Decode(content));
                    break;
            }

            contentElement.Content = content;
            return contentElement;
        }
Ejemplo n.º 9
0
        internal static AtomContentConstruct Parse(XPathNavigator navigator)
        {
            AtomContentConstruct contentElement = new AtomContentConstruct();
            string content = String.Empty;

            XPathNavigator nav = navigator.Clone();

            // select the element itself
            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 "title":
                case "copyright":
                case "info":
                case "tagline":
                case "summary":
                case "content":
                    try
                    {
                        contentElement.XmlLang = Utils.Utils.ParseLanguage(iter.Current.XmlLang);
                    }
                    catch {}
                    contentElement.LocalName = name;
                    XPathNavigatorReader reader = new XPathNavigatorReader(iter.Current);
                    reader.Read();
                    content = reader.ReadInnerXml();
                    break;
                }
            }

            // select the attributes
            iter = nav.Select("@*");
            do
            {
                switch (iter.Current.Name.ToLower())
                {
                case "type":
                    contentElement.Type = Utils.Utils.ParseMediaType(
                        iter.Current.Value);
                    break;

                case "mode":
                {
                    switch (iter.Current.Value.ToLower())
                    {
                    case "escaped":
                        contentElement.Mode = Mode.Escaped;
                        break;

                    case "base64":
                        contentElement.Mode = Mode.Base64;
                        break;
                    }
                    break;
                }
                }
            } while(iter.MoveNext());

            switch (contentElement.Mode)
            {
            case Mode.Escaped:
                content = Utils.Utils.Unescape(content);
                break;

            case Mode.Base64:
                content = Encoding.Unicode.GetString(
                    Utils.Utils.Base64Decode(content));
                break;
            }

            contentElement.Content = content;
            return(contentElement);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="navigator"></param>
        /// <returns></returns>
        internal static AtomContentConstruct parse(XPathNavigator navigator) {
            AtomContentConstruct result_content = new AtomContentConstruct();
            string content = string.Empty;

            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 "title":
                    case "copyright":
                    case "info":
                    case "tagline":
                    case "summary":
                    case "content":
                        try {
                            result_content.XmlLang = AtomUtility.parseLanguage( it.Current.XmlLang );
                        } catch { }
                        result_content.LocalName = name;

                        XPathNavigatorReader reader = new XPathNavigatorReader( it.Current );
                        reader.Read();
                        content = reader.ReadInnerXml();
                        break;
                }
            }

            it = temp_navigator.Select( "@*" );
            do {
                switch ( it.Current.Name.ToLower() ) {
                    case "type":
                        result_content.Type = AtomUtility.parseMediaType( it.Current.Value );
                        break;

                    case "mode":
                        switch ( it.Current.Value.ToLower() ) {
                            case "escaped":
                                result_content.Mode = EncodedMode.Escaped;
                                break;

                            case "base64":
                                result_content.Mode = EncodedMode.Base64;
                                break;
                        }
                        break;
                }
            } while ( it.MoveNext() );

            switch ( result_content.Mode ) {
                case EncodedMode.Escaped:
                    content = AtomUtility.Unescape( content );
                    break;

                case EncodedMode.Base64:
                    content = Encoding.Unicode.GetString( Base64.Decode( content ) );
                    break;
            }
            result_content.Content = content;

            return result_content;
        }