Revert
[mono-project.git] / mcs / class / System.ServiceModel.Web / System.ServiceModel.Syndication / SyndicationItemFormatter.cs
blob1343bcdd3c76dd4a3f1dba43c803b7fb4f1ac720
1 //
2 // SyndicationItemFormatter.cs
3 //
4 // Author:
5 // Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using System;
29 using System.Collections.Generic;
30 using System.Collections.ObjectModel;
31 using System.IO;
32 using System.Runtime.Serialization;
33 using System.Text;
34 using System.Xml;
36 namespace System.ServiceModel.Syndication
38 [DataContract]
39 public abstract class SyndicationItemFormatter
41 #region static members
43 // My assumption is that those static methods are defined to
44 // be used in the derived classes and to dispatch the actual
45 // processing to each syndication element. Considering that
46 // they can be overriden in each element, I assume that these
47 // methods depend on the elements, not in reverse order.
49 protected internal static SyndicationCategory CreateCategory (SyndicationItem item)
51 if (item == null)
52 throw new ArgumentNullException ("item");
53 return item.CreateCategory ();
56 protected internal static SyndicationLink CreateLink (SyndicationItem item)
58 if (item == null)
59 throw new ArgumentNullException ("item");
60 return item.CreateLink ();
63 protected internal static SyndicationPerson CreatePerson (SyndicationItem item)
65 if (item == null)
66 throw new ArgumentNullException ("item");
67 return item.CreatePerson ();
70 [MonoTODO ("use maxExtensionsSize parameter")]
71 protected internal static void LoadElementExtensions (XmlReader reader, SyndicationCategory category, int maxExtensionSize)
73 category.ElementExtensions.Add (reader);
76 [MonoTODO ("use maxExtensionsSize parameter")]
77 protected internal static void LoadElementExtensions (XmlReader reader, SyndicationItem item, int maxExtensionSize)
79 item.ElementExtensions.Add (reader);
82 [MonoTODO ("use maxExtensionsSize parameter")]
83 protected internal static void LoadElementExtensions (XmlReader reader, SyndicationLink link, int maxExtensionSize)
85 link.ElementExtensions.Add (reader);
88 [MonoTODO ("use maxExtensionsSize parameter")]
89 protected internal static void LoadElementExtensions (XmlReader reader, SyndicationPerson person, int maxExtensionSize)
91 person.ElementExtensions.Add (reader);
94 protected internal static bool TryParseAttribute (string name, string ns, string value, SyndicationCategory category, string version)
96 if (category == null)
97 throw new ArgumentNullException ("category");
98 return category.TryParseAttribute (name, ns, value, version);
101 protected internal static bool TryParseAttribute (string name, string ns, string value, SyndicationItem item, string version)
103 if (item == null)
104 throw new ArgumentNullException ("item");
105 return item.TryParseAttribute (name, ns, value, version);
108 protected internal static bool TryParseAttribute (string name, string ns, string value, SyndicationLink link, string version)
110 if (link == null)
111 throw new ArgumentNullException ("link");
112 return link.TryParseAttribute (name, ns, value, version);
115 protected internal static bool TryParseAttribute (string name, string ns, string value, SyndicationPerson person, string version)
117 if (person == null)
118 throw new ArgumentNullException ("person");
119 return person.TryParseAttribute (name, ns, value, version);
122 protected internal static bool TryParseContent (XmlReader reader, SyndicationItem item, string contentType, string version, out SyndicationContent content)
124 if (item == null)
125 throw new ArgumentNullException ("item");
126 return item.TryParseContent (reader, contentType, version, out content);
129 protected internal static bool TryParseElement (XmlReader reader, SyndicationCategory category, string version)
131 if (category == null)
132 throw new ArgumentNullException ("category");
133 return category.TryParseElement (reader, version);
136 protected internal static bool TryParseElement (XmlReader reader, SyndicationItem item, string version)
138 if (item == null)
139 throw new ArgumentNullException ("item");
140 return item.TryParseElement (reader, version);
143 protected internal static bool TryParseElement (XmlReader reader, SyndicationLink link, string version)
145 if (link == null)
146 throw new ArgumentNullException ("link");
147 return link.TryParseElement (reader, version);
150 protected internal static bool TryParseElement (XmlReader reader, SyndicationPerson person, string version)
152 if (person == null)
153 throw new ArgumentNullException ("person");
154 return person.TryParseElement (reader, version);
157 protected internal static void WriteAttributeExtensions (XmlWriter writer, SyndicationCategory category, string version)
159 if (category == null)
160 throw new ArgumentNullException ("category");
161 category.WriteAttributeExtensions (writer, version);
164 protected internal static void WriteAttributeExtensions (XmlWriter writer, SyndicationItem item, string version)
166 if (item == null)
167 throw new ArgumentNullException ("item");
168 item.WriteAttributeExtensions (writer, version);
171 protected internal static void WriteAttributeExtensions (XmlWriter writer, SyndicationLink link, string version)
173 if (link == null)
174 throw new ArgumentNullException ("link");
175 link.WriteAttributeExtensions (writer, version);
178 protected internal static void WriteAttributeExtensions (XmlWriter writer, SyndicationPerson person, string version)
180 if (person == null)
181 throw new ArgumentNullException ("person");
182 person.WriteAttributeExtensions (writer, version);
185 protected internal void WriteElementExtensions (XmlWriter writer, SyndicationCategory category, string version)
187 if (category == null)
188 throw new ArgumentNullException ("category");
189 category.WriteElementExtensions (writer, version);
192 protected internal static void WriteElementExtensions (XmlWriter writer, SyndicationItem item, string version)
194 if (item == null)
195 throw new ArgumentNullException ("item");
196 item.WriteElementExtensions (writer, version);
199 protected internal void WriteElementExtensions (XmlWriter writer, SyndicationLink link, string version)
201 if (link == null)
202 throw new ArgumentNullException ("link");
203 link.WriteElementExtensions (writer, version);
206 protected internal void WriteElementExtensions (XmlWriter writer, SyndicationPerson person, string version)
208 if (person == null)
209 throw new ArgumentNullException ("person");
210 person.WriteElementExtensions (writer, version);
213 #endregion
215 #region instance members
217 SyndicationItem item;
219 protected SyndicationItemFormatter ()
223 protected SyndicationItemFormatter (SyndicationItem itemToWrite)
225 if (itemToWrite == null)
226 throw new ArgumentNullException ("itemToWrite");
227 SetItem (itemToWrite);
230 protected internal virtual void SetItem (SyndicationItem item)
232 if (item == null)
233 throw new ArgumentNullException ("item");
234 this.item = item;
237 public SyndicationItem Item {
238 get { return item; }
241 public abstract string Version { get; }
243 protected abstract SyndicationItem CreateItemInstance ();
245 public abstract bool CanRead (XmlReader reader);
247 public abstract void ReadFrom (XmlReader reader);
249 public abstract void WriteTo (XmlWriter writer);
251 public override string ToString ()
253 return String.Concat (GetType ().FullName, ", SyndicationVersion=", Version);
255 #endregion