Skip to content

Commit

Permalink
Map icon and logo
Browse files Browse the repository at this point in the history
  • Loading branch information
w3stling committed Sep 26, 2024
1 parent 4434fbb commit 8f06f3e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ protected void registerChannelTags() {
channelTags.putIfAbsent("dc:title", (channel, value) -> Mapper.mapIfEmpty(value, channel::getTitle, channel::setTitle));
channelTags.putIfAbsent("sy:updatePeriod", (channel, value) -> channel.syUpdatePeriod = value);
channelTags.putIfAbsent("sy:updateFrequency", (channel, value) -> mapInteger(value, number -> channel.syUpdateFrequency = number));
channelTags.putIfAbsent("/feed/icon", (channel, value) -> createIfNull(channel::getImage, channel::setImage, Image::new).setUrl(value));
channelTags.putIfAbsent("/feed/logo", (channel, value) -> createIfNull(channel::getImage, channel::setImage, Image::new).setUrl(value));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,20 +870,32 @@ void readFromAMixOfUrlAndString() throws IOException, URISyntaxException {
"https://www.nasa.gov/news-release/feed/",
getFileUri("atom-feed.xml")
);

var items = new RssReader().read(sources).collect(Collectors.toList());
assertEquals(33, items.size());
}

@Test
void syUpdatePeriodAndSyUpdateFrequency() throws IOException, URISyntaxException {
var source = getFileUri("rss-feed.xml");

var items = new RssReader().read(source).collect(Collectors.toList());
assertEquals(20, items.size());
assertEquals("30", items.get(0).getChannel().getTtl().orElse(""));
}

@Test
void feedIcon() throws IOException, URISyntaxException {
var source = getFileUri("atom-feed.xml");
var items = new RssReader().read(source).collect(Collectors.toList());
assertEquals("https://example.com/icon.png", items.get(0).getChannel().getImage().map(Image::getUrl).orElse(""));
}

@Test
void feedLogo() throws IOException, URISyntaxException {
var source = getFileUri("atom-feed-category.xml");
var items = new RssReader().read(source).collect(Collectors.toList());
assertEquals("https://example.com/logo.png", items.get(0).getChannel().getImage().map(Image::getUrl).orElse(""));
}

private InputStream fromFile(String fileName) {
return getClass().getClassLoader().getResourceAsStream(fileName);
}
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/atom-feed-category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
large collection of FAQs, tutorials and tips codes for application and
wWeb developers on Java, .NET, C, PHP, JavaScript, XML, HTML, CSS, RSS,
MySQL and Oracle - dev.fyicenter.com.</subtitle>
<logo>https://example.com/logo.png</logo>
<link rel="self" href="http://dev.fyicenter.com/atom_xml.php"/>
<id>http://dev.fyicenter.com/atom_xml.php</id>
<updated>2017-09-22T03:58:52+02:00</updated>
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/atom-feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
A &lt;em&gt;lot&lt;/em&gt; of effort
went into making this effortless
</subtitle>
<icon>https://example.com/icon.png</icon>
<updated>2005-07-31T12:29:29Z</updated>
<id>tag:example.org,2003:3</id>
<link rel="alternate" type="text/html"
Expand Down

0 comments on commit 8f06f3e

Please sign in to comment.