public static IList <Tag> ParseTagList(JsonReader reader, ErrorList errors) { return(TagListParser.ParseTags(reader, errors)); }
private static BundleEntry loadEntry(XElement entry, ErrorList errors) { BundleEntry result; errors.DefaultContext = "An atom entry"; try { if (entry.Name == XTOMBSTONE + XATOM_DELETED_ENTRY) { result = new DeletedEntry(); result.Id = Util.UriValueOrNull(entry.Attribute(XATOM_DELETED_REF)); if (result.Id != null) { errors.DefaultContext = String.Format("Entry '{0}'", result.Id.ToString()); } } else { XElement content = entry.Element(XATOMNS + XATOM_CONTENT); var id = Util.UriValueOrNull(entry.Element(XATOMNS + XATOM_ID)); if (id != null) { errors.DefaultContext = String.Format("Entry '{0}'", id.ToString()); } if (content != null) { var parsed = getContents(content, errors); if (parsed != null) { result = ResourceEntry.Create(parsed); } else { return(null); } } else { throw new InvalidOperationException("BundleEntry has empty content: cannot determine Resource type in parser."); } result.Id = id; } result.Links = getLinks(entry.Elements(XATOMNS + XATOM_LINK)); result.Tags = TagListParser.ParseTags(entry.Elements(XATOMNS + XATOM_CATEGORY)); if (result is DeletedEntry) { ((DeletedEntry)result).When = Util.InstantOrNull(entry.Attribute(XATOM_DELETED_WHEN)); } else { ResourceEntry re = (ResourceEntry)result; re.Title = Util.StringValueOrNull(entry.Element(XATOMNS + XATOM_TITLE)); re.LastUpdated = Util.InstantOrNull(entry.Element(XATOMNS + XATOM_UPDATED)); re.Published = Util.InstantOrNull(entry.Element(XATOMNS + XATOM_PUBLISHED)); re.AuthorName = entry.Elements(XATOMNS + XATOM_AUTHOR).Count() == 0 ? null : Util.StringValueOrNull(entry.Element(XATOMNS + XATOM_AUTHOR) .Element(XATOMNS + XATOM_AUTH_NAME)); re.AuthorUri = entry.Elements(XATOMNS + XATOM_AUTHOR).Count() == 0 ? null : Util.StringValueOrNull(entry.Element(XATOMNS + XATOM_AUTHOR) .Element(XATOMNS + XATOM_AUTH_URI)); } } catch (Exception exc) { errors.Add("Exception while reading entry: " + exc.Message); return(null); } finally { errors.DefaultContext = null; } return(result); }
private static BundleEntry loadEntry(JToken entry, ErrorList errors) { BundleEntry result; errors.DefaultContext = "An atom entry"; try { if (entry.Value <DateTimeOffset?>(JATOM_DELETED) != null) { result = new DeletedEntry(); } else { var content = entry[BundleXmlParser.XATOM_CONTENT]; if (content != null) { var parsed = getContents(content, errors); if (parsed != null) { result = ResourceEntry.Create(parsed); } else { return(null); } } else { throw new InvalidOperationException("BundleEntry has empty content: cannot determine Resource type in parser"); } } result.Id = Util.UriValueOrNull(entry[BundleXmlParser.XATOM_ID]); if (result.Id != null) { errors.DefaultContext = String.Format("Entry '{0}'", result.Id.ToString()); } result.Links = getLinks(entry[BundleXmlParser.XATOM_LINK]); result.Tags = TagListParser.ParseTags(entry[BundleXmlParser.XATOM_CATEGORY]); if (result is DeletedEntry) { ((DeletedEntry)result).When = instantOrNull(entry[JATOM_DELETED]); } else { var re = (ResourceEntry)result; re.Title = entry.Value <string>(BundleXmlParser.XATOM_TITLE); re.LastUpdated = instantOrNull(entry[BundleXmlParser.XATOM_UPDATED]); re.Published = instantOrNull(entry[BundleXmlParser.XATOM_PUBLISHED]); re.AuthorName = entry[BundleXmlParser.XATOM_AUTHOR] as JArray != null ? entry[BundleXmlParser.XATOM_AUTHOR] .Select(auth => auth.Value <string>(BundleXmlParser.XATOM_AUTH_NAME)) .FirstOrDefault() : null; re.AuthorUri = entry[BundleXmlParser.XATOM_AUTHOR] as JArray != null ? entry[BundleXmlParser.XATOM_AUTHOR] .Select(auth => auth.Value <string>(BundleXmlParser.XATOM_AUTH_URI)) .FirstOrDefault() : null; } } catch (Exception exc) { errors.Add("Exception while reading entry: " + exc.Message); return(null); } finally { errors.DefaultContext = null; } return(result); }