1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
|
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.ServiceModel.Syndication
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Xml;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
// NOTE: This class implements Clone so if you add any members, please update the copy ctor
[TypeForwardedFrom("System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
public class SyndicationItem : IExtensibleSyndicationObject
{
Collection<SyndicationPerson> authors;
Uri baseUri;
Collection<SyndicationCategory> categories;
SyndicationContent content;
Collection<SyndicationPerson> contributors;
TextSyndicationContent copyright;
ExtensibleSyndicationObject extensions = new ExtensibleSyndicationObject();
string id;
DateTimeOffset lastUpdatedTime;
Collection<SyndicationLink> links;
DateTimeOffset publishDate;
SyndicationFeed sourceFeed;
TextSyndicationContent summary;
TextSyndicationContent title;
public SyndicationItem()
: this(null, null, null)
{
}
public SyndicationItem(string title, string content, Uri itemAlternateLink)
: this(title, content, itemAlternateLink, null, DateTimeOffset.MinValue)
{
}
public SyndicationItem(string title, string content, Uri itemAlternateLink, string id, DateTimeOffset lastUpdatedTime)
: this(title, (content != null) ? new TextSyndicationContent(content) : null, itemAlternateLink, id, lastUpdatedTime)
{
}
public SyndicationItem(string title, SyndicationContent content, Uri itemAlternateLink, string id, DateTimeOffset lastUpdatedTime)
{
if (title != null)
{
this.Title = new TextSyndicationContent(title);
}
this.content = content;
if (itemAlternateLink != null)
{
this.Links.Add(SyndicationLink.CreateAlternateLink(itemAlternateLink));
}
this.id = id;
this.lastUpdatedTime = lastUpdatedTime;
}
protected SyndicationItem(SyndicationItem source)
{
if (source == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
}
this.extensions = source.extensions.Clone();
this.authors = FeedUtils.ClonePersons(source.authors);
this.categories = FeedUtils.CloneCategories(source.categories);
this.content = (source.content != null) ? source.content.Clone() : null;
this.contributors = FeedUtils.ClonePersons(source.contributors);
this.copyright = FeedUtils.CloneTextContent(source.copyright);
this.id = source.id;
this.lastUpdatedTime = source.lastUpdatedTime;
this.links = FeedUtils.CloneLinks(source.links);
this.publishDate = source.publishDate;
if (source.SourceFeed != null)
{
this.sourceFeed = source.sourceFeed.Clone(false);
this.sourceFeed.Items = new Collection<SyndicationItem>();
}
this.summary = FeedUtils.CloneTextContent(source.summary);
this.baseUri = source.baseUri;
this.title = FeedUtils.CloneTextContent(source.title);
}
public Dictionary<XmlQualifiedName, string> AttributeExtensions
{
get { return this.extensions.AttributeExtensions; }
}
public Collection<SyndicationPerson> Authors
{
get
{
if (this.authors == null)
{
this.authors = new NullNotAllowedCollection<SyndicationPerson>();
}
return this.authors;
}
}
public Uri BaseUri
{
get { return this.baseUri; }
set { this.baseUri = value; }
}
public Collection<SyndicationCategory> Categories
{
get
{
if (this.categories == null)
{
this.categories = new NullNotAllowedCollection<SyndicationCategory>();
}
return this.categories;
}
}
public SyndicationContent Content
{
get { return content; }
set { content = value; }
}
public Collection<SyndicationPerson> Contributors
{
get
{
if (this.contributors == null)
{
this.contributors = new NullNotAllowedCollection<SyndicationPerson>();
}
return this.contributors;
}
}
public TextSyndicationContent Copyright
{
get { return this.copyright; }
set { this.copyright = value; }
}
public SyndicationElementExtensionCollection ElementExtensions
{
get { return this.extensions.ElementExtensions; }
}
public string Id
{
get { return id; }
set { id = value; }
}
public DateTimeOffset LastUpdatedTime
{
get { return lastUpdatedTime; }
set { lastUpdatedTime = value; }
}
public Collection<SyndicationLink> Links
{
get
{
if (this.links == null)
{
this.links = new NullNotAllowedCollection<SyndicationLink>();
}
return this.links;
}
}
public DateTimeOffset PublishDate
{
get { return publishDate; }
set { publishDate = value; }
}
public SyndicationFeed SourceFeed
{
get { return this.sourceFeed; }
set { this.sourceFeed = value; }
}
public TextSyndicationContent Summary
{
get { return this.summary; }
set { this.summary = value; }
}
public TextSyndicationContent Title
{
get { return this.title; }
set { this.title = value; }
}
public static SyndicationItem Load(XmlReader reader)
{
return Load<SyndicationItem>(reader);
}
public static TSyndicationItem Load<TSyndicationItem>(XmlReader reader)
where TSyndicationItem : SyndicationItem, new ()
{
if (reader == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
}
Atom10ItemFormatter<TSyndicationItem> atomSerializer = new Atom10ItemFormatter<TSyndicationItem>();
if (atomSerializer.CanRead(reader))
{
atomSerializer.ReadFrom(reader);
return atomSerializer.Item as TSyndicationItem;
}
Rss20ItemFormatter<TSyndicationItem> rssSerializer = new Rss20ItemFormatter<TSyndicationItem>();
if (rssSerializer.CanRead(reader))
{
rssSerializer.ReadFrom(reader);
return rssSerializer.Item as TSyndicationItem;
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.UnknownItemXml, reader.LocalName, reader.NamespaceURI)));
}
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "0#permalink", Justification = "permalink is a term defined in the RSS format")]
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Permalink", Justification = "permalink is a term defined in the RSS format")]
public void AddPermalink(Uri permalink)
{
if (permalink == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("permalink");
}
this.Id = permalink.AbsoluteUri;
this.Links.Add(SyndicationLink.CreateAlternateLink(permalink));
}
public virtual SyndicationItem Clone()
{
return new SyndicationItem(this);
}
public Atom10ItemFormatter GetAtom10Formatter()
{
return new Atom10ItemFormatter(this);
}
public Rss20ItemFormatter GetRss20Formatter()
{
return GetRss20Formatter(true);
}
public Rss20ItemFormatter GetRss20Formatter(bool serializeExtensionsAsAtom)
{
return new Rss20ItemFormatter(this, serializeExtensionsAsAtom);
}
public void SaveAsAtom10(XmlWriter writer)
{
this.GetAtom10Formatter().WriteTo(writer);
}
public void SaveAsRss20(XmlWriter writer)
{
this.GetRss20Formatter().WriteTo(writer);
}
protected internal virtual SyndicationCategory CreateCategory()
{
return new SyndicationCategory();
}
protected internal virtual SyndicationLink CreateLink()
{
return new SyndicationLink();
}
protected internal virtual SyndicationPerson CreatePerson()
{
return new SyndicationPerson();
}
protected internal virtual bool TryParseAttribute(string name, string ns, string value, string version)
{
return false;
}
protected internal virtual bool TryParseContent(XmlReader reader, string contentType, string version, out SyndicationContent content)
{
content = null;
return false;
}
protected internal virtual bool TryParseElement(XmlReader reader, string version)
{
return false;
}
protected internal virtual void WriteAttributeExtensions(XmlWriter writer, string version)
{
this.extensions.WriteAttributeExtensions(writer);
}
protected internal virtual void WriteElementExtensions(XmlWriter writer, string version)
{
this.extensions.WriteElementExtensions(writer);
}
internal void LoadElementExtensions(XmlReader readerOverUnparsedExtensions, int maxExtensionSize)
{
this.extensions.LoadElementExtensions(readerOverUnparsedExtensions, maxExtensionSize);
}
internal void LoadElementExtensions(XmlBuffer buffer)
{
this.extensions.LoadElementExtensions(buffer);
}
}
}
|