reader.ReadEndElement ();
}
- TextSyndicationContent ReadTextSyndicationContent (XmlReader reader)
+ internal static TextSyndicationContent ReadTextSyndicationContent (XmlReader reader)
{
TextSyndicationContentKind kind = TextSyndicationContentKind.Plaintext;
switch (reader.GetAttribute ("type")) {
protected override ServiceDocument CreateDocumentInstance ()
{
- return doc_type != null ? (ServiceDocument) Activator.CreateInstance (doc_type, new object [0]) : base.CreateDocumentInstance ();
+ var doc = doc_type != null ? (ServiceDocument) Activator.CreateInstance (doc_type, new object [0]) : base.CreateDocumentInstance ();
+ doc.InternalFormatter = this;
+ return doc;
}
- [MonoTODO]
public override void ReadFrom (XmlReader reader)
{
- if (reader == null)
- throw new ArgumentNullException ("reader");
-
- for (int i = 0; i < reader.AttributeCount; i++) {
- reader.MoveToAttribute (i);
- Document.TryParseAttribute (reader.LocalName, reader.NamespaceURI, reader.Value, Version);
- }
- reader.MoveToElement ();
-
- throw new NotImplementedException ();
+ if (!Document.TryParseElement (reader, Version))
+ throw new XmlException (String.Format ("Unexpected element '{0}' in namespace '{1}'", reader.LocalName, reader.NamespaceURI));
}
public override void WriteTo (XmlWriter writer)
GetFormatter ().WriteTo (writer);
}
- [MonoTODO]
protected internal virtual bool TryParseAttribute (string name, string ns, string value, string version)
{
- throw new NotImplementedException ();
+ var inline = this as InlineCategoriesDocument;
+ if (name == "lang" && ns == Namespaces.Xml)
+ Language = value;
+ else if (name == "base" && ns == Namespaces.Xml)
+ BaseUri = new Uri (value, UriKind.RelativeOrAbsolute);
+ else if (name == "href" && ns == String.Empty && this is ReferencedCategoriesDocument)
+ ((ReferencedCategoriesDocument) this).Link = new Uri (value, UriKind.RelativeOrAbsolute);
+ else if (name == "fixed" && ns == String.Empty && inline != null && value == "true")
+ inline.IsFixed = true;
+ else if (name == "scheme" && ns == String.Empty && inline != null)
+ inline.Scheme = value;
+ else
+ return false;
+ return true;
}
- [MonoTODO]
protected internal virtual bool TryParseElement (XmlReader reader, string version)
{
- throw new NotImplementedException ();
+ if (reader == null)
+ throw new ArgumentNullException ("reader");
+
+ var f = GetFormatter ();
+ if (!f.CanRead (reader))
+ return false;
+ f.ReadFrom (reader);
+ return true;
}
protected internal virtual void WriteAttributeExtensions (XmlWriter writer, string version)
+2009-04-06 Atsushi Enomoto <atsushi@ximian.com>
+
+ * ServiceDocumentFormatter.cs
+ Workspace.cs
+ Atom10FeedFormatter.cs
+ AtomPub10ServiceDocumentFormatter.cs
+ ResourceCollectionInfo.cs
+ CategoriesDocument.cs
+ ServiceDocument.cs : implemented most of reader parts.
+
2009-04-06 Atsushi Enomoto <atsushi@ximian.com>
* Workspace.cs, ResourceCollectionInfo.cs,
return new ReferencedCategoriesDocument ();
}
- [MonoTODO]
protected internal virtual bool TryParseAttribute (string name, string ns, string value, string version)
{
- throw new NotImplementedException ();
+ if (name == "base" && ns == Namespaces.Xml)
+ BaseUri = new Uri (value, UriKind.RelativeOrAbsolute);
+ else if (name == "href" && ns == String.Empty)
+ Link = new Uri (value, UriKind.RelativeOrAbsolute);
+ else
+ return false;
+ return true;
}
- [MonoTODO]
protected internal virtual bool TryParseElement (XmlReader reader, string version)
{
- throw new NotImplementedException ();
+ if (reader == null)
+ throw new ArgumentNullException ("reader");
+ reader.MoveToContent ();
+
+ if (reader.LocalName != "collection" || reader.NamespaceURI != version)
+ return false;
+
+ for (int i = 0; i < reader.AttributeCount; i++) {
+ reader.MoveToAttribute (i);
+ if (!TryParseAttribute (reader.LocalName, reader.NamespaceURI, reader.Value, version))
+ AttributeExtensions.Add (new XmlQualifiedName (reader.LocalName, reader.NamespaceURI), reader.Value);
+ }
+ reader.MoveToElement ();
+
+ if (!reader.IsEmptyElement) {
+ reader.Read ();
+ for (reader.MoveToContent (); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
+ if (reader.LocalName == "title" && reader.NamespaceURI == Namespaces.Atom10)
+ Title = Atom10FeedFormatter.ReadTextSyndicationContent (reader);
+ else
+ ElementExtensions.Add (new SyndicationElementExtension (reader));
+ }
+ }
+ reader.Read ();
+ return true;
}
protected internal virtual void WriteAttributeExtensions (XmlWriter writer, string version)
{
extensions.WriteAttributeExtensions (writer, version);
}
+
+ protected internal virtual void WriteElementExtensions (XmlWriter writer, string version)
+ {
+ extensions.WriteElementExtensions (writer, version);
+ }
}
}
public class ServiceDocument
{
- [MonoTODO]
public static TServiceDocument Load<TServiceDocument> (XmlReader reader)
where TServiceDocument : ServiceDocument, new()
{
- throw new NotImplementedException ();
+ var doc = new TServiceDocument ();
+ new AtomPub10ServiceDocumentFormatter<TServiceDocument> (doc).ReadFrom (reader);
+ return doc;
}
- [MonoTODO]
public static ServiceDocument Load (XmlReader reader)
{
- throw new NotImplementedException ();
+ return Load<ServiceDocument> (reader);
}
ServiceDocumentFormatter formatter;
SyndicationExtensions extensions = new SyndicationExtensions ();
+ internal ServiceDocumentFormatter InternalFormatter {
+ set { formatter = value; }
+ }
+
public Dictionary<XmlQualifiedName, string> AttributeExtensions {
get { return extensions.Attributes; }
}
return false;
}
- [MonoTODO]
protected internal virtual bool TryParseElement (XmlReader reader, string version)
{
- throw new NotImplementedException ();
+ if (reader == null)
+ throw new ArgumentNullException ("reader");
+
+ reader.MoveToContent ();
+
+ if (reader.LocalName != "service" || reader.NamespaceURI != version)
+ return false;
+
+ for (int i = 0; i < reader.AttributeCount; i++) {
+ reader.MoveToAttribute (i);
+ if (!TryParseAttribute (reader.LocalName, reader.NamespaceURI, reader.Value, version))
+ AttributeExtensions.Add (new XmlQualifiedName (reader.LocalName, reader.NamespaceURI), reader.Value);
+ }
+ reader.MoveToElement ();
+
+ if (reader.IsEmptyElement)
+ throw new XmlException ("AtomPP service element requires at least one workspace element");
+
+ reader.ReadStartElement ();
+
+ for (reader.MoveToContent (); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
+ if (reader.LocalName == "workspace" && reader.NamespaceURI == version) {
+ var ws = CreateWorkspace ();
+ if (ws.TryParseElement (reader, version)) {
+ Workspaces.Add (ws);
+ continue;
+ }
+ }
+ ElementExtensions.Add (new SyndicationElementExtension (reader));
+ }
+
+ reader.ReadEndElement ();
+
+ return true;
}
protected internal virtual void WriteAttributeExtensions (XmlWriter writer, string version)
[DataContract]
public abstract class ServiceDocumentFormatter
{
- [MonoTODO]
protected static SyndicationCategory CreateCategory (InlineCategoriesDocument inlineCategories)
{
- throw new NotImplementedException ();
+ return inlineCategories.CreateCategory ();
}
- [MonoTODO]
protected static ResourceCollectionInfo CreateCollection (Workspace workspace)
{
- throw new NotImplementedException ();
+ return workspace.CreateResourceCollection ();
}
- [MonoTODO]
protected static InlineCategoriesDocument CreateInlineCategories (ResourceCollectionInfo collection)
{
- throw new NotImplementedException ();
+ return collection.CreateInlineCategoriesDocument ();
}
- [MonoTODO]
protected static ReferencedCategoriesDocument CreateReferencedCategories (ResourceCollectionInfo collection)
{
- throw new NotImplementedException ();
+ return collection.CreateReferencedCategoriesDocument ();
}
- [MonoTODO]
protected static Workspace CreateWorkspace (ServiceDocument document)
{
- throw new NotImplementedException ();
+ return document.CreateWorkspace ();
}
[MonoTODO]
protected virtual ServiceDocument CreateDocumentInstance ()
{
- return new ServiceDocument ();
+ return new ServiceDocument () { InternalFormatter = this };
}
public abstract void ReadFrom (XmlReader reader);
return new ResourceCollectionInfo ();
}
- [MonoTODO]
protected internal virtual bool TryParseAttribute (string name, string ns, string value, string version)
{
- throw new NotImplementedException ();
+ if (name == "base" && ns == Namespaces.Xml) {
+ BaseUri = new Uri (value, UriKind.RelativeOrAbsolute);
+ return true;
+ }
+ return false;
}
- [MonoTODO]
protected internal virtual bool TryParseElement (XmlReader reader, string version)
{
- throw new NotImplementedException ();
+ if (reader == null)
+ throw new ArgumentNullException ("reader");
+
+ reader.MoveToContent ();
+ if (reader.LocalName != "workspace" || reader.NamespaceURI != version)
+ return false;
+
+ bool isEmpty = reader.IsEmptyElement;
+
+ reader.ReadStartElement ();
+ if (isEmpty)
+ return true;
+
+ for (reader.MoveToContent (); reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ()) {
+ if (reader.LocalName == "title" && reader.NamespaceURI == Namespaces.Atom10) {
+ Title = Atom10FeedFormatter.ReadTextSyndicationContent (reader);
+ continue;
+ } else if (reader.LocalName == "collection" && reader.NamespaceURI == version) {
+ var rc = new ResourceCollectionInfo ();
+ if (rc.TryParseElement (reader, version)) {
+ Collections.Add (rc);
+ continue;
+ }
+ }
+ ElementExtensions.Add (new SyndicationElementExtension (reader));
+ }
+ return true;
}
protected internal virtual void WriteAttributeExtensions (XmlWriter writer, string version)
namespace MonoTests.System.ServiceModel.Syndication
{
+ class MyServiceFormatter : AtomPub10ServiceDocumentFormatter
+ {
+ public void Read (XmlReader reader)
+ {
+ ReadFrom (reader);
+ }
+ }
+
[TestFixture]
public class AtomPub10ServiceDocumentFormatterTest
{
{
ServiceDocument.Load (XmlReader.Create (new StringReader (app2)));
}
+
+ [Test]
+ public void ReadFrom ()
+ {
+ new MyServiceFormatter ().Read (XmlReader.Create (new StringReader (app2)));
+ }
}
}
+2009-04-06 Atsushi Enomoto <atsushi@ximian.com>
+
+ * AtomPub10ServiceDocumentFormatterTest.cs : add ReadFrom() test.
+
2009-04-06 Atsushi Enomoto <atsushi@ximian.com>
* AtomPub10CategoriesDocumentFormatterTest.cs : new test.