import 'package:webfeed/domain/atom_category.dart'; import 'package:webfeed/domain/atom_link.dart'; import 'package:webfeed/domain/atom_person.dart'; import 'package:webfeed/domain/atom_source.dart'; import 'package:webfeed/domain/media/media.dart'; import 'package:webfeed/util/datetime.dart'; import 'package:webfeed/util/iterable.dart'; import 'package:xml/xml.dart'; class AtomItem { final String? id; final String? title; final DateTime? updated; final List? authors; final List? links; final List? categories; final List? contributors; final AtomSource? source; final String? published; final String? content; final String? summary; final String? rights; final Media? media; AtomItem({ this.id, this.title, this.updated, this.authors, this.links, this.categories, this.contributors, this.source, this.published, this.content, this.summary, this.rights, this.media, }); factory AtomItem.parse(XmlElement element) { return AtomItem( id: element.findElements('id').firstOrNull?.text, title: element.findElements('title').firstOrNull?.text, updated: parseDateTime(element.findElements('updated').firstOrNull?.text), authors: element .findElements('author') .map((e) => AtomPerson.parse(e)) .toList(), links: element.findElements('link').map((e) => AtomLink.parse(e)).toList(), categories: element .findElements('category') .map((e) => AtomCategory.parse(e)) .toList(), contributors: element .findElements('contributor') .map((e) => AtomPerson.parse(e)) .toList(), source: element .findElements('source') .map((e) => AtomSource.parse(e)) .firstOrNull, published: element.findElements('published').firstOrNull?.text, content: element.findElements('content').firstOrNull?.text, summary: element.findElements('summary').firstOrNull?.text, rights: element.findElements('rights').firstOrNull?.text, media: Media.parse(element), ); } }