The Webfeed Flutter package for Appeto SDK.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 rivejä
2.8 KiB

  1. import 'package:webfeed/domain/atom_category.dart';
  2. import 'package:webfeed/domain/atom_link.dart';
  3. import 'package:webfeed/domain/atom_person.dart';
  4. import 'package:webfeed/domain/atom_source.dart';
  5. import 'package:webfeed/domain/media/media.dart';
  6. import 'package:webfeed/util/helpers.dart';
  7. import 'package:xml/xml.dart';
  8. class AtomItem {
  9. final String id;
  10. final String title;
  11. final String updated;
  12. final List<AtomPerson> authors;
  13. final List<AtomLink> links;
  14. final List<AtomCategory> categories;
  15. final List<AtomPerson> contributors;
  16. final AtomSource source;
  17. final String published;
  18. final String content;
  19. final String summary;
  20. final String rights;
  21. final Media media;
  22. AtomItem({
  23. this.id,
  24. this.title,
  25. this.updated,
  26. this.authors,
  27. this.links,
  28. this.categories,
  29. this.contributors,
  30. this.source,
  31. this.published,
  32. this.content,
  33. this.summary,
  34. this.rights,
  35. this.media,
  36. });
  37. factory AtomItem.parse(XmlElement element) {
  38. var id = xmlGetString(element, "id", strict: false);
  39. var title = xmlGetString(element, "title", strict: false);
  40. var updated = xmlGetString(element, "updated", strict: false);
  41. var authors = element.findElements("author").map((element) {
  42. return new AtomPerson.parse(element);
  43. }).toList();
  44. var links = element.findElements("link").map((element) {
  45. return new AtomLink.parse(element);
  46. }).toList();
  47. var categories = element.findElements("category").map((element) {
  48. return new AtomCategory.parse(element);
  49. }).toList();
  50. var contributors = element.findElements("contributor").map((element) {
  51. return new AtomPerson.parse(element);
  52. }).toList();
  53. AtomSource source;
  54. try {
  55. source = new AtomSource.parse(element.findElements("source").first);
  56. } on StateError {}
  57. var published = xmlGetString(element, "published", strict: false);
  58. var content = xmlGetString(element, "content", strict: false);
  59. var summary = xmlGetString(element, "summary", strict: false);
  60. var rights = xmlGetString(element, "rights", strict: false);
  61. return new AtomItem(
  62. id: id,
  63. title: title,
  64. updated: updated,
  65. authors: authors,
  66. links: links,
  67. categories: categories,
  68. contributors: contributors,
  69. source: source,
  70. published: published,
  71. content: content,
  72. summary: summary,
  73. rights: rights,
  74. media: new Media.parse(element),
  75. );
  76. }
  77. @override
  78. String toString() {
  79. return '''
  80. id: $id
  81. title: $title
  82. updated: $updated
  83. authors: $authors
  84. links: $links
  85. categories: $categories
  86. contributors: $contributors
  87. source: $source
  88. published: $published
  89. content: $content
  90. summary: $summary
  91. rights: $rights
  92. ''';
  93. }
  94. }