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.

73 regels
2.1 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/datetime.dart';
  7. import 'package:webfeed/util/iterable.dart';
  8. import 'package:xml/xml.dart';
  9. class AtomItem {
  10. final String? id;
  11. final String? title;
  12. final DateTime? updated;
  13. final List<AtomPerson>? authors;
  14. final List<AtomLink>? links;
  15. final List<AtomCategory>? categories;
  16. final List<AtomPerson>? contributors;
  17. final AtomSource? source;
  18. final String? published;
  19. final String? content;
  20. final String? summary;
  21. final String? rights;
  22. final Media? media;
  23. AtomItem({
  24. this.id,
  25. this.title,
  26. this.updated,
  27. this.authors,
  28. this.links,
  29. this.categories,
  30. this.contributors,
  31. this.source,
  32. this.published,
  33. this.content,
  34. this.summary,
  35. this.rights,
  36. this.media,
  37. });
  38. factory AtomItem.parse(XmlElement element) {
  39. return AtomItem(
  40. id: element.findElements('id').firstOrNull?.text,
  41. title: element.findElements('title').firstOrNull?.text,
  42. updated: parseDateTime(element.findElements('updated').firstOrNull?.text),
  43. authors: element
  44. .findElements('author')
  45. .map((e) => AtomPerson.parse(e))
  46. .toList(),
  47. links:
  48. element.findElements('link').map((e) => AtomLink.parse(e)).toList(),
  49. categories: element
  50. .findElements('category')
  51. .map((e) => AtomCategory.parse(e))
  52. .toList(),
  53. contributors: element
  54. .findElements('contributor')
  55. .map((e) => AtomPerson.parse(e))
  56. .toList(),
  57. source: element
  58. .findElements('source')
  59. .map((e) => AtomSource.parse(e))
  60. .firstOrNull,
  61. published: element.findElements('published').firstOrNull?.text,
  62. content: element.findElements('content').firstOrNull?.text,
  63. summary: element.findElements('summary').firstOrNull?.text,
  64. rights: element.findElements('rights').firstOrNull?.text,
  65. media: Media.parse(element),
  66. );
  67. }
  68. }