Skip to content

Commit c545acb

Browse files
committed
support media namespaces
1 parent 0a8e430 commit c545acb

28 files changed

+1087
-108
lines changed

lib/domain/atom_feed.dart

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@ class AtomFeed {
2222
String rights;
2323
String subtitle;
2424

25-
AtomFeed(this.id, this.title, this.updated, this.items,
26-
{this.links,
27-
this.authors,
28-
this.contributors,
29-
this.categories,
30-
this.generator,
31-
this.icon,
32-
this.logo,
33-
this.rights,
34-
this.subtitle});
25+
AtomFeed({
26+
this.id,
27+
this.title,
28+
this.updated,
29+
this.items,
30+
this.links,
31+
this.authors,
32+
this.contributors,
33+
this.categories,
34+
this.generator,
35+
this.icon,
36+
this.logo,
37+
this.rights,
38+
this.subtitle,
39+
});
3540

3641
factory AtomFeed.parse(String xmlString) {
3742
var document = parse(xmlString);
@@ -41,9 +46,9 @@ class AtomFeed {
4146
} on StateError {
4247
throw new ArgumentError("feed not found");
4348
}
44-
var id = xmlGetString(feedElement, "id");
45-
var title = xmlGetString(feedElement, "title");
46-
var updated = xmlGetString(feedElement, "updated");
49+
var id = xmlGetString(feedElement, "id", strict: false);
50+
var title = xmlGetString(feedElement, "title", strict: false);
51+
var updated = xmlGetString(feedElement, "updated", strict: false);
4752

4853
var items = feedElement.findElements("entry").map((element) {
4954
return new AtomItem.parse(element);
@@ -76,7 +81,11 @@ class AtomFeed {
7681
var rights = xmlGetString(feedElement, "rights", strict: false);
7782
var subtitle = xmlGetString(feedElement, "subtitle", strict: false);
7883

79-
return new AtomFeed(id, title, updated, items,
84+
return new AtomFeed(
85+
id: id,
86+
title: title,
87+
updated: updated,
88+
items: items,
8089
links: links,
8190
authors: authors,
8291
contributors: contributors,

lib/domain/atom_item.dart

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,46 @@ import 'package:webfeed/domain/atom_category.dart';
22
import 'package:webfeed/domain/atom_link.dart';
33
import 'package:webfeed/domain/atom_person.dart';
44
import 'package:webfeed/domain/atom_source.dart';
5+
import 'package:webfeed/domain/media/media.dart';
56
import 'package:webfeed/util/helpers.dart';
67
import 'package:xml/xml.dart';
78

89
class AtomItem {
9-
String id;
10-
String title;
11-
String updated;
10+
final String id;
11+
final String title;
12+
final String updated;
1213

13-
List<AtomPerson> authors;
14-
List<AtomLink> links;
15-
List<AtomCategory> categories;
16-
List<AtomPerson> contributors;
17-
AtomSource source;
18-
String published;
19-
String content;
20-
String summary;
21-
String rights;
14+
final List<AtomPerson> authors;
15+
final List<AtomLink> links;
16+
final List<AtomCategory> categories;
17+
final List<AtomPerson> contributors;
18+
final AtomSource source;
19+
final String published;
20+
final String content;
21+
final String summary;
22+
final String rights;
23+
final Media media;
2224

23-
AtomItem(this.id, this.title, this.updated,
24-
{this.authors,
25-
this.links,
26-
this.categories,
27-
this.contributors,
28-
this.source,
29-
this.published,
30-
this.content,
31-
this.summary,
32-
this.rights});
25+
AtomItem({
26+
this.id,
27+
this.title,
28+
this.updated,
29+
this.authors,
30+
this.links,
31+
this.categories,
32+
this.contributors,
33+
this.source,
34+
this.published,
35+
this.content,
36+
this.summary,
37+
this.rights,
38+
this.media,
39+
});
3340

3441
factory AtomItem.parse(XmlElement element) {
35-
var id = xmlGetString(element, "id");
36-
var title = xmlGetString(element, "title");
37-
var updated = xmlGetString(element, "updated");
42+
var id = xmlGetString(element, "id", strict: false);
43+
var title = xmlGetString(element, "title", strict: false);
44+
var updated = xmlGetString(element, "updated", strict: false);
3845

3946
var authors = element.findElements("author").map((element) {
4047
return new AtomPerson.parse(element);
@@ -62,16 +69,21 @@ class AtomItem {
6269
var summary = xmlGetString(element, "summary", strict: false);
6370
var rights = xmlGetString(element, "rights", strict: false);
6471

65-
return new AtomItem(id, title, updated,
66-
authors: authors,
67-
links: links,
68-
categories: categories,
69-
contributors: contributors,
70-
source: source,
71-
published: published,
72-
content: content,
73-
summary: summary,
74-
rights: rights);
72+
return new AtomItem(
73+
id: id,
74+
title: title,
75+
updated: updated,
76+
authors: authors,
77+
links: links,
78+
categories: categories,
79+
contributors: contributors,
80+
source: source,
81+
published: published,
82+
content: content,
83+
summary: summary,
84+
rights: rights,
85+
media: new Media.parse(element),
86+
);
7587
}
7688

7789
@override

lib/domain/media/community.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'package:webfeed/domain/media/star_rating.dart';
2+
import 'package:webfeed/domain/media/statistics.dart';
3+
import 'package:webfeed/domain/media/tags.dart';
4+
import 'package:webfeed/util/helpers.dart';
5+
import 'package:xml/xml.dart';
6+
7+
class Community {
8+
final StarRating starRating;
9+
final Statistics statistics;
10+
final Tags tags;
11+
12+
Community({
13+
this.starRating,
14+
this.statistics,
15+
this.tags,
16+
});
17+
18+
factory Community.parse(XmlElement element) {
19+
if (element == null) {
20+
return null;
21+
}
22+
return new Community(
23+
starRating: new StarRating.parse(
24+
findElementOrNull(element, "media:starRating"),
25+
),
26+
statistics: new Statistics.parse(
27+
findElementOrNull(element, "media:statistics"),
28+
),
29+
tags: new Tags.parse(
30+
findElementOrNull(element, "media:tags"),
31+
),
32+
);
33+
}
34+
}

lib/domain/media/copyright.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'package:xml/xml.dart';
2+
3+
class Copyright {
4+
final String url;
5+
final String value;
6+
7+
Copyright({
8+
this.url,
9+
this.value,
10+
});
11+
12+
factory Copyright.parse(XmlElement element) {
13+
if (element == null) {
14+
return null;
15+
}
16+
return new Copyright(
17+
url: element.getAttribute("url"),
18+
value: element.text,
19+
);
20+
}
21+
}

lib/domain/media/description.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'package:xml/xml.dart';
2+
3+
class Description {
4+
final String type;
5+
final String value;
6+
7+
Description({
8+
this.type,
9+
this.value,
10+
});
11+
12+
factory Description.parse(XmlElement element) {
13+
if (element == null) {
14+
return null;
15+
}
16+
return new Description(
17+
type: element.getAttribute("type"),
18+
value: element.text,
19+
);
20+
}
21+
}

lib/domain/media/embed.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:webfeed/domain/media/param.dart';
2+
import 'package:xml/xml.dart';
3+
4+
class Embed {
5+
final String url;
6+
final int width;
7+
final int height;
8+
final List<Param> params;
9+
10+
Embed({
11+
this.url,
12+
this.width,
13+
this.height,
14+
this.params,
15+
});
16+
17+
factory Embed.parse(XmlElement element) {
18+
if (element == null) {
19+
return null;
20+
}
21+
return new Embed(
22+
url: element.getAttribute("url"),
23+
width: int.tryParse(element.getAttribute("width") ?? "0"),
24+
height: int.tryParse(element.getAttribute("height") ?? "0"),
25+
params: element.findElements("media:param").map((e) {
26+
return new Param.parse(e);
27+
}).toList(),
28+
);
29+
}
30+
}

lib/domain/media/hash.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'package:xml/xml.dart';
2+
3+
class Hash {
4+
final String algo;
5+
final String value;
6+
7+
Hash({
8+
this.algo,
9+
this.value,
10+
});
11+
12+
factory Hash.parse(XmlElement element) {
13+
if (element == null) {
14+
return null;
15+
}
16+
return new Hash(
17+
algo: element.getAttribute("algo"),
18+
value: element.text,
19+
);
20+
}
21+
}

lib/domain/media/license.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import 'package:xml/xml.dart';
2+
3+
class License {
4+
final String type;
5+
final String href;
6+
final String value;
7+
8+
License({
9+
this.type,
10+
this.href,
11+
this.value,
12+
});
13+
14+
factory License.parse(XmlElement element) {
15+
if (element == null) {
16+
return null;
17+
}
18+
return new License(
19+
type: element.getAttribute("type"),
20+
href: element.getAttribute("href"),
21+
value: element.text,
22+
);
23+
}
24+
}

0 commit comments

Comments
 (0)