2 // SyndicationItemFormatter.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System
.Collections
.Generic
;
30 using System
.Collections
.ObjectModel
;
32 using System
.Runtime
.Serialization
;
36 namespace System
.ServiceModel
.Syndication
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
)
52 throw new ArgumentNullException ("item");
53 return item
.CreateCategory ();
56 protected internal static SyndicationLink
CreateLink (SyndicationItem item
)
59 throw new ArgumentNullException ("item");
60 return item
.CreateLink ();
63 protected internal static SyndicationPerson
CreatePerson (SyndicationItem item
)
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
)
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
)
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
)
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
)
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
)
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
)
139 throw new ArgumentNullException ("item");
140 return item
.TryParseElement (reader
, version
);
143 protected internal static bool TryParseElement (XmlReader reader
, SyndicationLink link
, string version
)
146 throw new ArgumentNullException ("link");
147 return link
.TryParseElement (reader
, version
);
150 protected internal static bool TryParseElement (XmlReader reader
, SyndicationPerson person
, string version
)
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
)
167 throw new ArgumentNullException ("item");
168 item
.WriteAttributeExtensions (writer
, version
);
171 protected internal static void WriteAttributeExtensions (XmlWriter writer
, SyndicationLink link
, string version
)
174 throw new ArgumentNullException ("link");
175 link
.WriteAttributeExtensions (writer
, version
);
178 protected internal static void WriteAttributeExtensions (XmlWriter writer
, SyndicationPerson person
, string version
)
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
)
195 throw new ArgumentNullException ("item");
196 item
.WriteElementExtensions (writer
, version
);
199 protected internal void WriteElementExtensions (XmlWriter writer
, SyndicationLink link
, string version
)
202 throw new ArgumentNullException ("link");
203 link
.WriteElementExtensions (writer
, version
);
206 protected internal void WriteElementExtensions (XmlWriter writer
, SyndicationPerson person
, string version
)
209 throw new ArgumentNullException ("person");
210 person
.WriteElementExtensions (writer
, version
);
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
)
233 throw new ArgumentNullException ("item");
237 public SyndicationItem 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
);