The Webfeed Flutter package for Appeto SDK.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

75 righe
2.3 KiB

  1. import 'dart:core';
  2. import 'package:webfeedclient/domain/rss_category.dart';
  3. import 'package:webfeedclient/domain/rss_item.dart';
  4. import 'package:webfeedclient/util/helpers.dart';
  5. import 'package:xml/xml.dart';
  6. import 'package:webfeedclient/domain/rss_image.dart';
  7. class RssFeed {
  8. final String title;
  9. final String description;
  10. final String link;
  11. final List<RssItem> items;
  12. final RssImage image;
  13. final List<RssCategory> categories;
  14. final String lastBuildDate;
  15. final String language;
  16. final String generator;
  17. final String copyright;
  18. RssFeed(this.title, this.description, this.link, this.items,
  19. {this.image, this.categories, this.lastBuildDate, this.language, this.generator, this.copyright});
  20. factory RssFeed.parse(XmlDocument document) {
  21. XmlElement channelElement;
  22. try {
  23. channelElement = document.findAllElements("channel").first;
  24. } on StateError {
  25. throw new ArgumentError("channel not found");
  26. }
  27. var title = xmlGetString(channelElement, "title");
  28. var description = xmlGetString(channelElement, "description");
  29. var link = xmlGetString(channelElement, "link");
  30. List<RssItem> feeds = channelElement.findElements("item").map((element) {
  31. return new RssItem.parse(element);
  32. }).toList();
  33. RssImage image;
  34. try {
  35. image = new RssImage.parse(channelElement.findElements("image").first);
  36. } on StateError {}
  37. List<RssCategory> categories = channelElement.findElements("category").map((element) {
  38. return new RssCategory.parse(element);
  39. }).toList();
  40. var lastBuildDate = xmlGetString(channelElement, "lastBuildDate", strict: false);
  41. var language = xmlGetString(channelElement, "language", strict: false);
  42. var generator = xmlGetString(channelElement, "generator", strict: false);
  43. var copyright = xmlGetString(channelElement, "copyright", strict: false);
  44. return new RssFeed(title, description, link, feeds,
  45. image: image,
  46. categories: categories,
  47. lastBuildDate: lastBuildDate,
  48. language: language,
  49. generator: generator,
  50. copyright: copyright);
  51. }
  52. @override
  53. String toString() {
  54. return '''
  55. title: $title
  56. description: $description
  57. link: $link
  58. lastBuildDate: $lastBuildDate
  59. items: $items
  60. ''';
  61. }
  62. }