Author: atsushi
Date: 2007-12-11 05:08:28 -0500 (Tue, 11 Dec 2007)
New Revision: 91077

Modified:
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20ItemFormatter.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationContent.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/TextSyndicationContent.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/Rss20ItemFormatterTest.cs
Log:
2007-12-11  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * Rss20ItemFormatter.cs, SyndicationContent.cs,
          TextSyndicationContent.cs : flush some more implementation.

        * TextSyndicationContentTest.cs : new test.
        * Rss20ItemFormatterTest.cs : test WriteTo()/WriteXml().



Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ChangeLog
 2007-12-11 09:55:40 UTC (rev 91076)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/ChangeLog
 2007-12-11 10:08:28 UTC (rev 91077)
@@ -1,3 +1,8 @@
+2007-12-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * Rss20ItemFormatter.cs, SyndicationContent.cs,
+         TextSyndicationContent.cs : flush some more implementation.
+
 2007-12-10  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * Atom10ItemFormatter.cs, Rss20ItemFormatter.cs,

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20ItemFormatter.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20ItemFormatter.cs
     2007-12-11 09:55:40 UTC (rev 91076)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/Rss20ItemFormatter.cs
     2007-12-11 10:08:28 UTC (rev 91077)
@@ -40,11 +40,14 @@
        [XmlRoot ("item", Namespace = "")]
        public class Rss20ItemFormatter : SyndicationItemFormatter, 
IXmlSerializable
        {
+               const string AtomNamespace ="http://www.w3.org/2005/Atom";;
+
                bool ext_atom_serialization, preserve_att_ext, 
preserve_elem_ext;
                Type item_type;
 
                public Rss20ItemFormatter ()
                {
+                       ext_atom_serialization = true;
                }
 
                public Rss20ItemFormatter (SyndicationItem feedToWrite)
@@ -109,7 +112,7 @@
                [MonoTODO]
                public override void WriteTo (XmlWriter writer)
                {
-                       throw new NotImplementedException ();
+                       WriteXml (writer, true);
                }
 
                [MonoTODO]
@@ -121,7 +124,7 @@
                [MonoTODO]
                void IXmlSerializable.WriteXml (XmlWriter writer)
                {
-                       throw new NotImplementedException ();
+                       WriteXml (writer, false);
                }
 
                [MonoTODO]
@@ -129,5 +132,64 @@
                {
                        throw new NotImplementedException ();
                }
+
+               // FIXME: call WriteElementExtensions() and 
WriteAttributExtensions on every syndication element.
+               void WriteXml (XmlWriter writer, bool writeRoot)
+               {
+                       if (writer == null)
+                               throw new ArgumentNullException ("writer");
+                       if (Item == null)
+                               throw new InvalidOperationException 
("Syndication item must be set before writing");
+
+                       if (writeRoot)
+                               writer.WriteStartElement ("item");
+
+                       if (Item.Title != null) {
+                               writer.WriteStartElement ("title");
+                               writer.WriteString (Item.Title.Text);
+                               writer.WriteEndElement ();
+                       }
+
+                       foreach (SyndicationPerson author in Item.Authors)
+                               if (author != null) {
+                                       writer.WriteStartElement ("author");
+                                       writer.WriteString (author.Email);
+                                       writer.WriteEndElement ();
+                               }
+                       foreach (SyndicationCategory category in 
Item.Categories)
+                               if (category != null) {
+                                       writer.WriteStartElement ("category");
+                                       if (category.Scheme != null)
+                                               writer.WriteAttributeString 
("domain", category.Scheme);
+                                       writer.WriteString (category.Name);
+                                       writer.WriteEndElement ();
+                               }
+                       if (Item.Summary != null)
+                               Item.Summary.WriteTo (writer, "description", 
String.Empty);
+                       else if (Item.Title == null) { // according to the RSS 
2.0 spec, either of title or description must exist.
+                               writer.WriteStartElement ("description");
+                               writer.WriteEndElement ();
+                       }
+                       // FIXME; what to do for Contributors?
+                       foreach (SyndicationLink link in Item.Links)
+                               if (link != null) {
+                                       writer.WriteStartElement ("link");
+                                       writer.WriteString (link.Uri != null ? 
link.Uri.ToString () : String.Empty);
+                                       writer.WriteEndElement ();
+                               }
+
+                       // Contributors are part of Atom extension
+                       if (SerializeExtensionsAsAtom)
+                               foreach (SyndicationPerson contributor in 
Item.Contributors) {
+                                       writer.WriteStartElement 
("contributor", AtomNamespace);
+                                       writer.WriteElementString ("name", 
AtomNamespace, contributor.Name);
+                                       writer.WriteElementString ("uri", 
AtomNamespace, contributor.Uri);
+                                       writer.WriteElementString ("email", 
AtomNamespace, contributor.Email);
+                                       writer.WriteEndElement ();
+                               }
+
+                       if (writeRoot)
+                               writer.WriteEndElement ();
+               }
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationContent.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationContent.cs
     2007-12-11 09:55:40 UTC (rev 91076)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/SyndicationContent.cs
     2007-12-11 10:08:28 UTC (rev 91077)
@@ -111,10 +111,18 @@
 
                protected abstract void WriteContentsTo (XmlWriter writer);
 
-               [MonoTODO]
                public void WriteTo (XmlWriter writer, string outerElementName, 
string outerElementNamespace)
                {
-                       throw new NotImplementedException ();
+                       if (writer == null)
+                               throw new ArgumentNullException ("writer");
+                       if (outerElementName == null)
+                               throw new ArgumentNullException 
("outerElementName");
+                       if (outerElementNamespace == null)
+                               throw new ArgumentNullException 
("outerElementNamespace");
+                       writer.WriteStartElement (outerElementName, 
outerElementNamespace);
+                       writer.WriteAttributeString ("type", Type);
+                       WriteContentsTo (writer);
+                       writer.WriteFullEndElement ();
                }
 
                #endregion

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/TextSyndicationContent.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/TextSyndicationContent.cs
 2007-12-11 09:55:40 UTC (rev 91076)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Syndication/TextSyndicationContent.cs
 2007-12-11 10:08:28 UTC (rev 91077)
@@ -37,44 +37,53 @@
 {
        public class TextSyndicationContent : SyndicationContent
        {
-               [MonoTODO]
+               string text;
+               TextSyndicationContentKind kind;
+
                public TextSyndicationContent (string text)
+                       : this (text, TextSyndicationContentKind.Plaintext)
                {
-                       throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public TextSyndicationContent (string text, 
TextSyndicationContentKind textKind)
                {
-                       throw new NotImplementedException ();
+                       this.text = text;
+                       kind = textKind;
                }
 
-               [MonoTODO]
                protected TextSyndicationContent (TextSyndicationContent source)
                {
-                       throw new NotImplementedException ();
+                       if (source == null)
+                               throw new ArgumentNullException ("source");
+                       text = source.text;
+                       kind = source.kind;
                }
 
-               [MonoTODO]
                public override SyndicationContent Clone ()
                {
-                       throw new NotImplementedException ();
+                       return new TextSyndicationContent (this);
                }
 
-               [MonoTODO]
                protected override void WriteContentsTo (XmlWriter writer)
                {
-                       throw new NotImplementedException ();
+                       writer.WriteString (text ?? String.Empty);
                }
 
-               [MonoTODO]
                public string Text {
-                       get { throw new NotImplementedException (); }
+                       get { return text; }
                }
 
-               [MonoTODO]
                public override string Type {
-                       get { throw new NotImplementedException (); }
+                       get {
+                               switch (kind) {
+                               case TextSyndicationContentKind.Html:
+                                       return "html";
+                               case TextSyndicationContentKind.XHtml:
+                                       return "xhtml";
+                               default:
+                                       return "text";
+                               }
+                       }
                }
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
  2007-12-11 09:55:40 UTC (rev 91076)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
  2007-12-11 10:08:28 UTC (rev 91077)
@@ -6,3 +6,4 @@
 System.ServiceModel.Syndication/SyndicationFeedTest.cs
 System.ServiceModel.Syndication/SyndicationItemTest.cs
 System.ServiceModel.Syndication/SyndicationLinkTest.cs
+System.ServiceModel.Syndication/TextSyndicationContentTest.cs

Modified: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/ChangeLog
    2007-12-11 09:55:40 UTC (rev 91076)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/ChangeLog
    2007-12-11 10:08:28 UTC (rev 91077)
@@ -1,3 +1,8 @@
+2007-12-11  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * TextSyndicationContentTest.cs : new test.
+       * Rss20ItemFormatterTest.cs : test WriteTo()/WriteXml().
+
 2007-12-10  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * Atom10ItemFormatterTest.cs, Rss20ItemFormatterTest.cs,

Modified: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/Rss20ItemFormatterTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/Rss20ItemFormatterTest.cs
    2007-12-11 09:55:40 UTC (rev 91076)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Syndication/Rss20ItemFormatterTest.cs
    2007-12-11 10:08:28 UTC (rev 91077)
@@ -32,6 +32,7 @@
 using System.Runtime.Serialization;
 using System.Text;
 using System.Xml;
+using System.Xml.Serialization;
 using System.ServiceModel.Syndication;
 using NUnit.Framework;
 
@@ -80,5 +81,88 @@
                        Rss20ItemFormatter f = new Rss20ItemFormatter ();
                        Assert.IsTrue (f.SerializeExtensionsAsAtom, "#1");
                }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void DefaultConstructorThenWriteXml ()
+               {
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20ItemFormatter ().WriteTo (w);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void WriteToNull ()
+               {
+                       SyndicationItem item = new SyndicationItem ();
+                       new Rss20ItemFormatter (item).WriteTo (null);
+               }
+
+               [Test]
+               public void WriteTo_EmptyItem ()
+               {
+                       SyndicationItem item = new SyndicationItem ();
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20ItemFormatter (item).WriteTo (w);
+                       // either title or description must exist (RSS 2.0 spec)
+                       Assert.AreEqual ("<item><description /></item>", 
sw.ToString ());
+               }
+
+               [Test]
+               public void WriteTo_TitleOnlyItem ()
+               {
+                       SyndicationItem item = new SyndicationItem ();
+                       item.Title = new TextSyndicationContent ("title text");
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20ItemFormatter (item).WriteTo (w);
+                       Assert.AreEqual ("<item><title>title 
text</title></item>", sw.ToString ());
+               }
+
+               [Test]
+               public void WriteTo_Category ()
+               {
+                       SyndicationItem item = new SyndicationItem ();
+                       item.Categories.Add (new SyndicationCategory ("myname", 
"myscheme", "mylabel"));
+                       item.Authors.Add (new SyndicationPerson ("[EMAIL 
PROTECTED]", "John Doe", "http://john.doe.name";));
+                       item.Contributors.Add (new SyndicationPerson ("[EMAIL 
PROTECTED]", "Jane Doe", "http://jane.doe.name";));
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20ItemFormatter (item).WriteTo (w);
+                       // contributors are serialized as Atom extension
+                       Assert.AreEqual ("<item><author>[EMAIL 
PROTECTED]</author><category domain=\"myscheme\">myname</category><description 
/><contributor xmlns=\"http://www.w3.org/2005/Atom\";><name>Jane 
Doe</name><uri>http://jane.doe.name</uri><email>[EMAIL 
PROTECTED]</email></contributor></item>", sw.ToString ());
+               }
+
+               [Test]
+               public void SerializeExtensionsAsAtomFalse ()
+               {
+                       SyndicationItem item = new SyndicationItem ();
+                       item.Contributors.Add (new SyndicationPerson ("[EMAIL 
PROTECTED]", "Jane Doe", "http://jane.doe.name";));
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               new Rss20ItemFormatter (item, false).WriteTo 
(w);
+                       // skip contributors
+                       Assert.AreEqual ("<item><description /></item>", 
sw.ToString ());
+               }
+
+               [Test]
+               public void ISerializableWriteXml ()
+               {
+                       SyndicationItem item = new SyndicationItem ();
+                       item.Title = new TextSyndicationContent ("title text");
+                       StringWriter sw = new StringWriter ();
+                       using (XmlWriter w = CreateWriter (sw))
+                               ((IXmlSerializable) new Rss20ItemFormatter 
(item)).WriteXml (w);
+                       Assert.AreEqual ("<title>title text</title>", 
sw.ToString ());
+               }
+
+               XmlWriter CreateWriter (StringWriter sw)
+               {
+                       XmlWriterSettings s = new XmlWriterSettings ();
+                       s.OmitXmlDeclaration = true;
+                       return XmlWriter.Create (sw, s);
+               }
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to