public override void WriteTo(XmlWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } writer.WriteStartElement("app", "categories", Version); if (writer.LookupPrefix(Namespaces.Atom10) != "a10") { writer.WriteAttributeString("xmlns", "a10", Namespaces.Xmlns, Namespaces.Atom10); } // xml:lang, xml:base, term, scheme, label if (Document.Language != null) { writer.WriteAttributeString("xml", "lang", Namespaces.Xml, Document.Language); } if (Document.BaseUri != null) { writer.WriteAttributeString("xml", "base", Namespaces.Xml, Document.BaseUri.ToString()); } InlineCategoriesDocument inline = Document as InlineCategoriesDocument; ReferencedCategoriesDocument referenced = Document as ReferencedCategoriesDocument; // ... no term ? if (inline != null) { if (inline.IsFixed) { writer.WriteAttributeString("fixed", "yes"); } if (inline.Scheme != null) { writer.WriteAttributeString("scheme", inline.Scheme); } } else if (referenced != null) { if (referenced.Link != null) { writer.WriteAttributeString("href", referenced.Link.ToString()); } } Document.WriteAttributeExtensions(writer, Version); Document.WriteElementExtensions(writer, Version); if (inline != null) { WriteInlineCategoriesContent(inline, writer); } // no (non-extension) contents for out-of-line category writer.WriteEndElement(); }
void WriteInlineCategoriesContent(InlineCategoriesDocument doc, XmlWriter writer) { foreach (var cat in doc.Categories) { atom10_formatter.WriteCategory(cat, writer); } }
void ReadInlineCategoriesContent(InlineCategoriesDocument doc, XmlReader reader) { var cat = new SyndicationCategory(); atom10_formatter.ReadCategory(reader, cat); doc.Categories.Add(cat); }
public static CategoriesDocument Load(XmlReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } var f = new AtomPub10CategoriesDocumentFormatter(); reader.MoveToContent(); CategoriesDocument doc; if (reader.GetAttribute("href") == null) { doc = new InlineCategoriesDocument(); } else { doc = new ReferencedCategoriesDocument(); } doc.GetFormatter().ReadFrom(reader); return(doc); }
protected static SyndicationCategory CreateCategory(InlineCategoriesDocument inlineCategories) { if (inlineCategories == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(inlineCategories)); } return(inlineCategories.CreateCategory()); }
protected static SyndicationCategory CreateCategory(InlineCategoriesDocument inlineCategories) { if (inlineCategories == null) { throw new ArgumentNullException(nameof(inlineCategories)); } return(inlineCategories.CreateCategory()); }
protected static SyndicationCategory CreateCategory(InlineCategoriesDocument inlineCategories) { if (inlineCategories == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("inlineCategories"); } return(inlineCategories.CreateCategory()); }
protected static SyndicationCategory CreateCategory(InlineCategoriesDocument inlineCategories) { if (inlineCategories == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("inlineCategories"); } return inlineCategories.CreateCategory(); }
public void WriteTo () { var doc = new InlineCategoriesDocument (); var f = new AtomPub10CategoriesDocumentFormatter (doc); doc.Scheme = "http"; doc.IsFixed = false; var sw = new StringWriter (); using (var xw = XmlWriter.Create (sw, settings)) f.WriteTo (xw); Assert.AreEqual (app1, sw.ToString ()); }
internal static CategoriesDocument ReadCategories(XmlReader reader, Uri baseUri, CreateInlineCategoriesDelegate inlineCategoriesFactory, CreateReferencedCategoriesDelegate referencedCategoriesFactory, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize) { string attribute = reader.GetAttribute("href", string.Empty); if (string.IsNullOrEmpty(attribute)) { InlineCategoriesDocument inlineCategories = inlineCategoriesFactory(); ReadInlineCategories(reader, inlineCategories, baseUri, version, preserveElementExtensions, preserveAttributeExtensions, maxExtensionSize); return(inlineCategories); } ReferencedCategoriesDocument referencedCategories = referencedCategoriesFactory(); ReadReferencedCategories(reader, referencedCategories, baseUri, new Uri(attribute, UriKind.RelativeOrAbsolute), version, preserveElementExtensions, preserveAttributeExtensions, maxExtensionSize); return(referencedCategories); }
public static CategoriesDocument Load (XmlReader reader) { if (reader == null) throw new ArgumentNullException ("reader"); var f = new AtomPub10CategoriesDocumentFormatter (); reader.MoveToContent (); CategoriesDocument doc; if (reader.GetAttribute ("href") == null) doc = new InlineCategoriesDocument (); else doc = new ReferencedCategoriesDocument (); doc.GetFormatter ().ReadFrom (reader); return doc; }
private static void WriteInlineCategoriesContent(XmlWriter writer, InlineCategoriesDocument categories, string version) { if (!string.IsNullOrEmpty(categories.Scheme)) { writer.WriteAttributeString("scheme", categories.Scheme); } if (categories.IsFixed) { writer.WriteAttributeString("fixed", "yes"); } ServiceDocumentFormatter.WriteAttributeExtensions(writer, categories, version); for (int i = 0; i < categories.Categories.Count; i++) { Atom10FeedFormatter.WriteCategory(writer, categories.Categories[i], version); } ServiceDocumentFormatter.WriteElementExtensions(writer, categories, version); }
internal static CategoriesDocument ReadCategories(XmlReader reader, Uri baseUri, CreateInlineCategoriesDelegate inlineCategoriesFactory, CreateReferencedCategoriesDelegate referencedCategoriesFactory, string version, int maxExtensionSize) { string link = reader.GetAttribute(App10Constants.Href, string.Empty); if (string.IsNullOrEmpty(link)) { InlineCategoriesDocument inlineCategories = inlineCategoriesFactory(); ReadInlineCategories(reader, inlineCategories, baseUri, version, maxExtensionSize); return(inlineCategories); } else { ReferencedCategoriesDocument referencedCategories = referencedCategoriesFactory(); ReadReferencedCategories(reader, referencedCategories, baseUri, new Uri(link, UriKind.RelativeOrAbsolute), version, maxExtensionSize); return(referencedCategories); } }
public override void WriteToStream(Type type, object value, Stream writeStream, HttpContent content) { var document = value as IPublicationCategoriesDocument; var atomDoc = new InlineCategoriesDocument( document.Categories.Select(c => new SyndicationCategory(c.Name) { Label = c.Label }), document.IsFixed, document.Scheme ); var formatter = new AtomPub10CategoriesDocumentFormatter(atomDoc); using (writeStream) { using (var writer = XmlWriter.Create(writeStream)) { formatter.WriteTo(writer); } } }
private static void WriteInlineCategoriesContent(XmlWriter writer, InlineCategoriesDocument categories, string version) { if (!string.IsNullOrEmpty(categories.Scheme)) { writer.WriteAttributeString(Atom10Constants.SchemeTag, categories.Scheme); } // by default, categories are not fixed if (categories.IsFixed) { writer.WriteAttributeString(App10Constants.Fixed, "yes"); } WriteAttributeExtensions(writer, categories, version); for (int i = 0; i < categories.Categories.Count; ++i) { Atom10FeedFormatter.WriteCategory(writer, categories.Categories[i], version); } WriteElementExtensions(writer, categories, version); }
internal static async Task <CategoriesDocument> ReadCategories(XmlReaderWrapper reader, Uri baseUri, CreateInlineCategoriesDelegate inlineCategoriesFactory, CreateReferencedCategoriesDelegate referencedCategoriesFactory, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize) { string link = reader.GetAttribute(App10Constants.Href, string.Empty); if (string.IsNullOrEmpty(link)) { InlineCategoriesDocument inlineCategories = inlineCategoriesFactory(); await ReadInlineCategoriesAsync(reader, inlineCategories, baseUri, version, preserveElementExtensions, preserveAttributeExtensions, maxExtensionSize); return(inlineCategories); } else { ReferencedCategoriesDocument referencedCategories = referencedCategoriesFactory(); await ReadReferencedCategoriesAsync(reader, referencedCategories, baseUri, new Uri(link, UriKind.RelativeOrAbsolute), version, preserveElementExtensions, preserveAttributeExtensions, maxExtensionSize); return(referencedCategories); } }
public void WriteTo2 () { var doc = new InlineCategoriesDocument (); var f = new AtomPub10CategoriesDocumentFormatter (doc); doc.Categories.Add (new SyndicationCategory ("TEST CATEGORY")); var sw = new StringWriter (); using (var xw = XmlWriter.Create (sw, settings)) f.WriteTo (xw); Assert.AreEqual (app2, sw.ToString ()); }
protected static SyndicationCategory CreateCategory(InlineCategoriesDocument inlineCategories) { return(default(SyndicationCategory)); }
void ReadInlineCategoriesContent (InlineCategoriesDocument doc, XmlReader reader) { var cat = new SyndicationCategory (); atom10_formatter.ReadCategory (reader, cat); doc.Categories.Add (cat); }
protected static SyndicationCategory CreateCategory(InlineCategoriesDocument inlineCategories) { return inlineCategories.CreateCategory (); }
private static async Task ReadInlineCategoriesAsync(XmlReaderWrapper reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int _maxExtensionSize) { inlineCategories.BaseUri = baseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { inlineCategories.BaseUri = FeedUtils.CombineXmlBase(inlineCategories.BaseUri, await reader.GetValueAsync()); } else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { inlineCategories.Language = await reader.GetValueAsync(); } else if (reader.LocalName == App10Constants.Fixed && reader.NamespaceURI == string.Empty) { inlineCategories.IsFixed = (reader.Value == "yes"); } else if (reader.LocalName == Atom10Constants.SchemeTag && reader.NamespaceURI == string.Empty) { inlineCategories.Scheme = await reader.GetValueAsync(); } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = await reader.GetValueAsync(); if (!TryParseAttribute(name, ns, val, inlineCategories, version)) { if (preserveAttributeExtensions) { inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), await reader.GetValueAsync()); } } } } } await SyndicationFeedFormatter.MoveToStartElementAsync(reader); bool isEmptyElement = reader.IsEmptyElement; await reader.ReadStartElementAsync(); if (!isEmptyElement) { XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; try { while (await reader.IsStartElementAsync()) { if (await reader.IsStartElementAsync(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace)) { SyndicationCategory category = CreateCategory(inlineCategories); await Atom10FeedFormatter.ReadCategoryAsync(reader, category, version, preserveAttributeExtensions, preserveElementExtensions, _maxExtensionSize); if (category.Scheme == null) { category.Scheme = inlineCategories.Scheme; } inlineCategories.Categories.Add(category); } else if (!TryParseElement(reader, inlineCategories, version)) { if (preserveElementExtensions) { var tuple = await SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNodeAsync(buffer, extWriter, reader, _maxExtensionSize); buffer = tuple.Item1; extWriter = tuple.Item2; } else { await reader.SkipAsync(); } } } LoadElementExtensions(buffer, extWriter, inlineCategories); } finally { if (extWriter != null) { extWriter.Close(); } } await reader.ReadEndElementAsync(); } }
protected static SyndicationCategory CreateCategory(InlineCategoriesDocument inlineCategories) { return default(SyndicationCategory); }
private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize) { inlineCategories.BaseUri = baseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")) { inlineCategories.BaseUri = FeedUtils.CombineXmlBase(inlineCategories.BaseUri, reader.Value); } else { if ((reader.LocalName == "lang") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")) { inlineCategories.Language = reader.Value; continue; } if ((reader.LocalName == "fixed") && (reader.NamespaceURI == string.Empty)) { inlineCategories.IsFixed = reader.Value == "yes"; continue; } if ((reader.LocalName == "scheme") && (reader.NamespaceURI == string.Empty)) { inlineCategories.Scheme = reader.Value; continue; } string namespaceURI = reader.NamespaceURI; string localName = reader.LocalName; if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI)) { string str3 = reader.Value; if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, inlineCategories, version)) { if (preserveAttributeExtensions) { inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); } } } } } SyndicationFeedFormatter.MoveToStartElement(reader); bool isEmptyElement = reader.IsEmptyElement; reader.ReadStartElement(); if (!isEmptyElement) { XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; try { while (reader.IsStartElement()) { if (reader.IsStartElement("category", "http://www.w3.org/2005/Atom")) { SyndicationCategory category = ServiceDocumentFormatter.CreateCategory(inlineCategories); Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions, preserveElementExtensions, maxExtensionSize); if (category.Scheme == null) { category.Scheme = inlineCategories.Scheme; } inlineCategories.Categories.Add(category); } else if (!ServiceDocumentFormatter.TryParseElement(reader, inlineCategories, version)) { if (preserveElementExtensions) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); reader.Skip(); } } ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, inlineCategories); } finally { if (extWriter != null) { extWriter.Close(); } } reader.ReadEndElement(); } }
private static async Task WriteInlineCategoriesContentAsync(XmlWriter writer, InlineCategoriesDocument categories, string version) { writer = XmlWriterWrapper.CreateFromWriter(writer); if (!string.IsNullOrEmpty(categories.Scheme)) { await writer.WriteAttributeStringAsync(Atom10Constants.SchemeTag, categories.Scheme); } // by default, categories are not fixed if (categories.IsFixed) { await writer.WriteAttributeStringAsync(App10Constants.Fixed, "yes"); } await WriteAttributeExtensionsAsync(writer, categories, version); for (int i = 0; i < categories.Categories.Count; ++i) { await Atom10FeedFormatter.WriteCategoryAsync(writer, categories.Categories[i], version); } await WriteElementExtensionsAsync(writer, categories, version); }
static void WriteInlineCategoriesContent(XmlWriter writer, InlineCategoriesDocument categories, string version) { if (!string.IsNullOrEmpty(categories.Scheme)) { writer.WriteAttributeString(Atom10Constants.SchemeTag, categories.Scheme); } // by default, categories are not fixed if (categories.IsFixed) { writer.WriteAttributeString(App10Constants.Fixed, "yes"); } WriteAttributeExtensions(writer, categories, version); for (int i = 0; i < categories.Categories.Count; ++i) { Atom10FeedFormatter.WriteCategory(writer, categories.Categories[i], version); } WriteElementExtensions(writer, categories, version); }
protected static SyndicationCategory CreateCategory(InlineCategoriesDocument inlineCategories) { return(inlineCategories.CreateCategory()); }
private static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, int maxExtensionSize) { inlineCategories.BaseUri = baseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { inlineCategories.BaseUri = FeedUtils.CombineXmlBase(inlineCategories.BaseUri, reader.Value); } else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { inlineCategories.Language = reader.Value; } else if (reader.LocalName == App10Constants.Fixed && reader.NamespaceURI == string.Empty) { inlineCategories.IsFixed = (reader.Value == "yes"); } else if (reader.LocalName == Atom10Constants.SchemeTag && reader.NamespaceURI == string.Empty) { inlineCategories.Scheme = reader.Value; } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = reader.Value; if (!TryParseAttribute(name, ns, val, inlineCategories, version)) { inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } SyndicationFeedFormatter.MoveToStartElement(reader); bool isEmptyElement = reader.IsEmptyElement; reader.ReadStartElement(); if (!isEmptyElement) { XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; try { while (reader.IsStartElement()) { if (reader.IsStartElement(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace)) { SyndicationCategory category = CreateCategory(inlineCategories); Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions: true, preserveElementExtensions: true, maxExtensionSize); if (category.Scheme == null) { category.Scheme = inlineCategories.Scheme; } inlineCategories.Categories.Add(category); } else if (!TryParseElement(reader, inlineCategories, version)) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize); } } LoadElementExtensions(buffer, extWriter, inlineCategories); } finally { extWriter?.Close(); } reader.ReadEndElement(); } }
static void ReadInlineCategories(XmlReader reader, InlineCategoriesDocument inlineCategories, Uri baseUri, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize) { inlineCategories.BaseUri = baseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { inlineCategories.BaseUri = FeedUtils.CombineXmlBase(inlineCategories.BaseUri, reader.Value); } else if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { inlineCategories.Language = reader.Value; } else if (reader.LocalName == App10Constants.Fixed && reader.NamespaceURI == string.Empty) { inlineCategories.IsFixed = (reader.Value == "yes"); } else if (reader.LocalName == Atom10Constants.SchemeTag && reader.NamespaceURI == string.Empty) { inlineCategories.Scheme = reader.Value; } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = reader.Value; if (!TryParseAttribute(name, ns, val, inlineCategories, version)) { if (preserveAttributeExtensions) { inlineCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } else { SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); } } } } } SyndicationFeedFormatter.MoveToStartElement(reader); bool isEmptyElement = reader.IsEmptyElement; reader.ReadStartElement(); if (!isEmptyElement) { XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; try { while (reader.IsStartElement()) { if (reader.IsStartElement(Atom10Constants.CategoryTag, Atom10Constants.Atom10Namespace)) { SyndicationCategory category = CreateCategory(inlineCategories); Atom10FeedFormatter.ReadCategory(reader, category, version, preserveAttributeExtensions, preserveElementExtensions, maxExtensionSize); if (category.Scheme == null) { category.Scheme = inlineCategories.Scheme; } inlineCategories.Categories.Add(category); } else if (!TryParseElement(reader, inlineCategories, version)) { if (preserveElementExtensions) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize); } else { SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); reader.Skip(); } } } LoadElementExtensions(buffer, extWriter, inlineCategories); } finally { if (extWriter != null) { extWriter.Close(); } } reader.ReadEndElement(); } }
void WriteInlineCategoriesContent (InlineCategoriesDocument doc, XmlWriter writer) { foreach (var cat in doc.Categories) atom10_formatter.WriteCategory (cat, writer); }