Skip to content

Commit 81c2aaa

Browse files
authored
Universal feed reader (#314)
1 parent 6f29d78 commit 81c2aaa

36 files changed

+385
-57
lines changed

src/main/java/com/apptasticsoftware/rssreader/AbstractRssReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected void initialize() {
199199
/**
200200
* Register channel tags for mapping to channel object fields
201201
*/
202-
@SuppressWarnings("java:S1192")
202+
@SuppressWarnings({"java:S1192", "java:S1612"})
203203
protected void registerChannelTags() {
204204
channelTags.putIfAbsent("title", (channel, value) -> Mapper.mapIfEmpty(value, channel::getTitle, channel::setTitle));
205205
channelTags.putIfAbsent("description", (channel, value) -> Mapper.mapIfEmpty(value, channel::getDescription, channel::setDescription));
@@ -239,8 +239,8 @@ protected void registerChannelTags() {
239239
channelTags.putIfAbsent("dc:title", (channel, value) -> Mapper.mapIfEmpty(value, channel::getTitle, channel::setTitle));
240240
channelTags.putIfAbsent("dc:date", (channel, value) -> Mapper.mapIfEmpty(value, channel::getPubDate, channel::setPubDate));
241241
channelTags.putIfAbsent("dc:creator", (channel, value) -> Mapper.mapIfEmpty(value, channel::getManagingEditor, channel::setManagingEditor));
242-
channelTags.putIfAbsent("sy:updatePeriod", (channel, value) -> { if (channel instanceof ChannelImpl) ((ChannelImpl)channel).syUpdatePeriod = value; });
243-
channelTags.putIfAbsent("sy:updateFrequency", (channel, value) -> { if (channel instanceof ChannelImpl) mapInteger(value, number -> ((ChannelImpl)channel).syUpdateFrequency = number); });
242+
channelTags.putIfAbsent("sy:updatePeriod", (channel, value) -> { if (channel instanceof ChannelImpl) ((ChannelImpl)channel).setSyUpdatePeriod(value); });
243+
channelTags.putIfAbsent("sy:updateFrequency", (channel, value) -> { if (channel instanceof ChannelImpl) mapInteger(value, number -> ((ChannelImpl)channel).setSyUpdateFrequency(number)); });
244244
channelTags.putIfAbsent("/feed/icon", (channel, value) -> createIfNull(channel::getImage, channel::setImage, Image::new).setUrl(value));
245245
channelTags.putIfAbsent("/feed/logo", (channel, value) -> createIfNull(channel::getImage, channel::setImage, Image::new).setUrl(value));
246246
}

src/main/java/com/apptasticsoftware/rssreader/Channel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface Channel {
3434
*
3535
* @deprecated
3636
* This method be removed in a future version.
37-
* <p> Use {@link ChannelImpl#getCategories()} instead.
37+
* <p> Use {@link Channel#getCategories()} instead.
3838
*
3939
* @return category
4040
*/
@@ -47,7 +47,7 @@ public interface Channel {
4747
*
4848
* @deprecated
4949
* This method be removed in a future version.
50-
* <p> Use {@link ChannelImpl#addCategory(String category)} instead.
50+
* <p> Use {@link Channel#addCategory(String category)} instead.
5151
*
5252
* @param category channel category
5353
*/

src/main/java/com/apptasticsoftware/rssreader/DateTime.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package com.apptasticsoftware.rssreader;
2525

26+
import com.apptasticsoftware.rssreader.internal.ItemImpl;
2627
import com.apptasticsoftware.rssreader.util.Default;
2728
import com.apptasticsoftware.rssreader.util.ItemComparator;
2829

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.apptasticsoftware.rssreader;
2+
3+
import com.apptasticsoftware.rssreader.module.itunes.ItunesChannel;
4+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssChannel;
5+
import com.apptasticsoftware.rssreader.module.opensearch.OpenSearchChannel;
6+
import com.apptasticsoftware.rssreader.module.podcast.PodcastChannel;
7+
import com.apptasticsoftware.rssreader.module.psc.PscChannel;
8+
import com.apptasticsoftware.rssreader.module.spotify.SpotifyChannel;
9+
import com.apptasticsoftware.rssreader.module.youtube.YoutubeChannel;
10+
11+
public interface FeedChannel extends Channel, ItunesChannel, MediaRssChannel, OpenSearchChannel, PodcastChannel, PscChannel, SpotifyChannel, YoutubeChannel {
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.apptasticsoftware.rssreader;
2+
3+
import com.apptasticsoftware.rssreader.module.itunes.ItunesItem;
4+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssItem;
5+
import com.apptasticsoftware.rssreader.module.opensearch.OpenSearchItem;
6+
import com.apptasticsoftware.rssreader.module.podcast.PodcastItem;
7+
import com.apptasticsoftware.rssreader.module.psc.PscItem;
8+
import com.apptasticsoftware.rssreader.module.spotify.SpotifyItem;
9+
import com.apptasticsoftware.rssreader.module.youtube.YoutubeItem;
10+
11+
public interface FeedItem extends Item, ItunesItem, MediaRssItem, OpenSearchItem, PodcastItem, PscItem, SpotifyItem, YoutubeItem {
12+
13+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.apptasticsoftware.rssreader;
2+
3+
import com.apptasticsoftware.rssreader.internal.FeedChannelImpl;
4+
import com.apptasticsoftware.rssreader.internal.FeedItemImpl;
5+
import com.apptasticsoftware.rssreader.module.itunes.ItunesExtensions;
6+
import com.apptasticsoftware.rssreader.module.mediarss.MediaRssExtensions;
7+
import com.apptasticsoftware.rssreader.module.opensearch.OpenSearchExtensions;
8+
import com.apptasticsoftware.rssreader.module.podcast.PodcastExtensions;
9+
import com.apptasticsoftware.rssreader.module.psc.PscExtensions;
10+
import com.apptasticsoftware.rssreader.module.spotify.SpotifyExtensions;
11+
import com.apptasticsoftware.rssreader.module.youtube.YoutubeExtensions;
12+
13+
public class FeedReader extends AbstractRssReader<FeedChannel, FeedItem> {
14+
15+
@Override
16+
protected FeedChannel createChannel(DateTimeParser dateTimeParser) {
17+
return new FeedChannelImpl(dateTimeParser);
18+
}
19+
20+
@Override
21+
protected FeedItem createItem(DateTimeParser dateTimeParser) {
22+
return new FeedItemImpl(dateTimeParser);
23+
}
24+
25+
@Override
26+
protected void registerChannelTags() {
27+
super.registerChannelTags();
28+
var registry = getFeedExtensionRegistry();
29+
ItunesExtensions.register(registry);
30+
MediaRssExtensions.register(registry);
31+
OpenSearchExtensions.register(registry);
32+
PodcastExtensions.register(registry, dateTimeParser);
33+
PscExtensions.register(registry);
34+
SpotifyExtensions.register(registry);
35+
YoutubeExtensions.register(registry);
36+
}
37+
}

src/main/java/com/apptasticsoftware/rssreader/Item.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public interface Item extends Comparable<Item> {
8181
*
8282
* @deprecated
8383
* This method be removed in a future version.
84-
* <p> Use {@link ItemImpl#getCategories()} instead.
84+
* <p> Use {@link Item#getCategories()} instead.
8585
*
8686
* @return category
8787
*/
@@ -94,7 +94,7 @@ public interface Item extends Comparable<Item> {
9494
*
9595
* @deprecated
9696
* This method be removed in a future version.
97-
* <p> Use {@link ItemImpl#addCategory(String category)} instead.
97+
* <p> Use {@link Item#addCategory(String category)} instead.
9898
*
9999
* @param category category
100100
*/

src/main/java/com/apptasticsoftware/rssreader/RssReader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
*/
2424
package com.apptasticsoftware.rssreader;
2525

26+
import com.apptasticsoftware.rssreader.internal.ChannelImpl;
27+
import com.apptasticsoftware.rssreader.internal.ItemImpl;
28+
2629
import java.net.http.HttpClient;
2730

2831
/**

src/main/java/com/apptasticsoftware/rssreader/filter/FeedFilter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.apptasticsoftware.rssreader.filter;
22

3-
import com.apptasticsoftware.rssreader.ItemImpl;
4-
53
import java.io.InputStream;
64

75
/**
86
* An interface for filtering RSS or Atom feed streams. This filter can
97
* modify or clean feed data before it is processed by the feed parser,
10-
* which maps it to {@link ItemImpl} objects.
8+
* which maps it to {@link com.apptasticsoftware.rssreader.Item} objects.
119
*/
1210
public interface FeedFilter {
1311

src/main/java/com/apptasticsoftware/rssreader/ChannelImpl.java renamed to src/main/java/com/apptasticsoftware/rssreader/internal/ChannelImpl.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.apptasticsoftware.rssreader;
24+
package com.apptasticsoftware.rssreader.internal;
2525

26+
import com.apptasticsoftware.rssreader.Channel;
27+
import com.apptasticsoftware.rssreader.DateTimeParser;
28+
import com.apptasticsoftware.rssreader.Image;
2629
import com.apptasticsoftware.rssreader.util.Default;
2730
import com.apptasticsoftware.rssreader.util.Mapper;
2831
import com.apptasticsoftware.rssreader.util.Util;
@@ -57,8 +60,8 @@ public class ChannelImpl implements Channel {
5760
private List<Integer> skipHours;
5861
private List<String> skipDays;
5962
private Image image;
60-
protected String syUpdatePeriod;
61-
protected int syUpdateFrequency = 1;
63+
private String syUpdatePeriod;
64+
private int syUpdateFrequency = 1;
6265
private final DateTimeParser dateTimeParser;
6366

6467
/**
@@ -463,6 +466,14 @@ public void setImage(Image image) {
463466
this.image = image;
464467
}
465468

469+
public void setSyUpdatePeriod(String syUpdatePeriod) {
470+
this.syUpdatePeriod = syUpdatePeriod;
471+
}
472+
473+
public void setSyUpdateFrequency(int syUpdateFrequency) {
474+
this.syUpdateFrequency = syUpdateFrequency;
475+
}
476+
466477
@Override
467478
public boolean equals(Object o) {
468479
if (this == o) return true;

0 commit comments

Comments
 (0)