protected SyndicationContent GetContent(Content content)
    {
      SyndicationContent sc = null;
      if (content != null)
      {
        if (!string.IsNullOrEmpty(content.Url))
        {
          sc = new UrlSyndicationContent(
            !string.IsNullOrEmpty(content.Url) ? null : new Uri(content.Url),
            content.Type);
        }
        if (string.IsNullOrEmpty(content.Type) || content.Type == "xhtml" ||
          content.Type == "html" || content.Type == "text")
        {

          sc = new TextSyndicationContent(content.Text,
            (string.IsNullOrEmpty(content.Type) || content.Type == "text") ?
          TextSyndicationContentKind.Plaintext :
          content.Type == "xhtml" ? TextSyndicationContentKind.XHtml :
          TextSyndicationContentKind.Html);
        }
        else
        {
          sc = new XmlSyndicationContent(content.Type,
           new SyndicationElementExtension(new XmlTextReader(new StringReader(content.Text))));
        }
        LoadAttributes(sc.AttributeExtensions, content.Attributes);
      }
      return sc;
    }
 protected UrlSyndicationContent(UrlSyndicationContent source)
 {
     if (source == null)
         throw new ArgumentNullException ("source");
     url = source.url;
     media_type = source.media_type;
 }
		public void Clone ()
		{
			Uri uri = new Uri ("http://mono-project.com");
			UrlSyndicationContent t = new UrlSyndicationContent (uri, "text/plain");
			t = t.Clone () as UrlSyndicationContent;
			Assert.AreEqual (uri, t.Url, "#1");
			Assert.AreEqual ("text/plain", t.Type, "#2");
		}
 protected UrlSyndicationContent(UrlSyndicationContent source)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     url        = source.url;
     media_type = source.media_type;
 }
 protected UrlSyndicationContent(UrlSyndicationContent source) : base(source)
 {
     if (source == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
     }
     this.url       = source.url;
     this.mediaType = source.mediaType;
 }
 protected UrlSyndicationContent(UrlSyndicationContent source) : base(source)
 {
     if (source == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("source");
     }
     this.url = source.url;
     this.mediaType = source.mediaType;
 }
Example #7
0
 protected UrlSyndicationContent(UrlSyndicationContent source)
     : base(source)
 {
     if (source == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(source));
     }
     _url       = source._url;
     _mediaType = source._mediaType;
 }
 protected UrlSyndicationContent(UrlSyndicationContent source)
     : base(source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     _url       = source._url;
     _mediaType = source._mediaType;
 }
		public void WriteTo ()
		{
			Uri uri = new Uri ("http://mono-project.com/");
			UrlSyndicationContent t = new UrlSyndicationContent (uri, null);
			StringWriter sw = new StringWriter ();
			using (XmlWriter w = CreateWriter (sw))
				t.WriteTo (w, "root", String.Empty);
			Assert.AreEqual ("<root type=\"\" src=\"http://mono-project.com/\" />", sw.ToString ());

			t = new UrlSyndicationContent (uri, "application/xml+svg");
			sw = new StringWriter ();
			using (XmlWriter w = CreateWriter (sw))
				t.WriteTo (w, "root", String.Empty);
			Assert.AreEqual ("<root type=\"application/xml+svg\" src=\"http://mono-project.com/\" />", sw.ToString ());
		}
Example #10
0
		public void Simple ()
		{
			Uri suri = new Uri (url);
			UrlSyndicationContent surl = new UrlSyndicationContent (suri, media_type);

			Assert.AreEqual (typeof (UrlSyndicationContent), surl.GetType (), "#S1");
			// check for content and type
			Assert.AreEqual (url.ToLower (), surl.Url.ToString (), "#S2");
			Assert.AreEqual (media_type, surl.Type.ToString (), "#S3");
		}
Example #11
0
 protected UrlSyndicationContent(UrlSyndicationContent source) : base(source)
 {
     Debug.Assert(source != null, "The base constructor already checks if source is valid.");
     Url        = source.Url;
     _mediaType = source._mediaType;
 }
        SyndicationContent ReadContentFrom(XmlReader reader, SyndicationItem item)
        {
            MoveToStartElement(reader);
            string type = reader.GetAttribute(Atom10Constants.TypeTag, string.Empty);

            SyndicationContent result;
            if (TryParseContent(reader, item, type, this.Version, out result))
            {
                return result;
            }

            if (string.IsNullOrEmpty(type))
            {
                type = Atom10Constants.PlaintextType;
            }
            string src = reader.GetAttribute(Atom10Constants.SourceTag, string.Empty);

            if (string.IsNullOrEmpty(src) && type != Atom10Constants.PlaintextType && type != Atom10Constants.HtmlType && type != Atom10Constants.XHtmlType)
            {
                return new XmlSyndicationContent(reader);
            }

            if (!string.IsNullOrEmpty(src))
            {
                result = new UrlSyndicationContent(new Uri(src, UriKind.RelativeOrAbsolute), type);
                bool isEmpty = reader.IsEmptyElement;
                if (reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        if (reader.LocalName == Atom10Constants.TypeTag && reader.NamespaceURI == string.Empty)
                        {
                            continue;
                        }
                        else if (reader.LocalName == Atom10Constants.SourceTag && reader.NamespaceURI == string.Empty)
                        {
                            continue;
                        }
                        else if (!FeedUtils.IsXmlns(reader.LocalName, reader.NamespaceURI))
                        {
                            if (this.preserveAttributeExtensions)
                            {
                                result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                            }
                            else
                            {
                                TraceSyndicationElementIgnoredOnRead(reader);
                            }
                        }
                    }
                }
                reader.ReadStartElement();
                if (!isEmpty)
                {
                    reader.ReadEndElement();
                }
                return result;
            }
            else
            {
                return ReadTextContentFromHelper(reader, type, "//atom:feed/atom:entry/atom:content[@type]", this.preserveAttributeExtensions);
            }
        }
Example #13
0
        private SyndicationItem MapEntryToSyndicationItem(Identity topicId, FeedEntry e)
        {
            var messageLink = ResourceLocation.OfMessageByTopic(topicId, e.MessageId);
            var message = messageByMessageKey.Get(new MessageKey {TopicId = topicId, MessageId = e.MessageId});

            var contentType = message.Headers.FirstOrDefault(h => h.Key == "Content-Type");
            var content = new UrlSyndicationContent(messageLink, contentType.Value.Aggregate((a,b)=>a +","+b));

            return new SyndicationItem(string.Format("Message {0}", e.MessageId),
                                       content,
                                       null,
                                       e.MessageId.ToString(), e.TimeStamp)
                       {
                           Links = { new SyndicationLink(messageLink) },
                           LastUpdatedTime = e.TimeStamp
                       };
        }
 private SyndicationContent ReadContentFrom(XmlReader reader, SyndicationItem item)
 {
     SyndicationContent content;
     SyndicationFeedFormatter.MoveToStartElement(reader);
     string attribute = reader.GetAttribute("type", string.Empty);
     if (!SyndicationFeedFormatter.TryParseContent(reader, item, attribute, this.Version, out content))
     {
         if (string.IsNullOrEmpty(attribute))
         {
             attribute = "text";
         }
         string str2 = reader.GetAttribute("src", string.Empty);
         if ((string.IsNullOrEmpty(str2) && (attribute != "text")) && ((attribute != "html") && (attribute != "xhtml")))
         {
             return new XmlSyndicationContent(reader);
         }
         if (string.IsNullOrEmpty(str2))
         {
             return ReadTextContentFromHelper(reader, attribute, "//atom:feed/atom:entry/atom:content[@type]", this.preserveAttributeExtensions);
         }
         content = new UrlSyndicationContent(new Uri(str2, UriKind.RelativeOrAbsolute), attribute);
         bool isEmptyElement = reader.IsEmptyElement;
         if (reader.HasAttributes)
         {
             while (reader.MoveToNextAttribute())
             {
                 if ((((reader.LocalName != "type") || (reader.NamespaceURI != string.Empty)) && ((reader.LocalName != "src") || (reader.NamespaceURI != string.Empty))) && !FeedUtils.IsXmlns(reader.LocalName, reader.NamespaceURI))
                 {
                     if (this.preserveAttributeExtensions)
                     {
                         content.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value);
                     }
                     else
                     {
                         SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader);
                     }
                 }
             }
         }
         reader.ReadStartElement();
         if (!isEmptyElement)
         {
             reader.ReadEndElement();
         }
     }
     return content;
 }