Skip to content

Commit ddee04f

Browse files
authored
BAEL-644: RSS with Rome (eugenp#2385)
* BAEL-886: Updated README * BAEL-917 Testing with Google Truth Updated README * BAEL-936: adding akka-streams module to parent * BAEL-936: Update README * BAEL-918: Update README * BAEL-980: Update README * BAEL-967: Update README * BAEL-509: Using @GetMapping instead of @RequestMapping with method=GET * BAEL-1005: Update README * BAEL-509: Security and WebSockets (README) * BAEL-861: Intro to Awaitility (README) * BAEL-1010: Guide to the HyperLogLog Algorithm (README) * BAEL-907: Guide to Apache Commons CircularFifoQueue (README) * BAEL-644: Quick Guide to RSS with Rome
1 parent 5383b2b commit ddee04f

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

‎libraries/pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@
181181
<artifactId>jetty-servlet</artifactId>
182182
<version>${jetty.version}</version>
183183
</dependency>
184+
<dependency>
185+
<groupId>rome</groupId>
186+
<artifactId>rome</artifactId>
187+
<version>${rome.version}</version>
188+
</dependency>
184189
<dependency>
185190
<groupId>io.specto</groupId>
186191
<artifactId>hoverfly-java</artifactId>
@@ -497,5 +502,6 @@
497502
<hll.version>1.6.0</hll.version>
498503
<bytebuddy.version>1.7.1</bytebuddy.version>
499504
<pcollections.version>2.1.2</pcollections.version>
505+
<rome.version>1.0</rome.version>
500506
</properties>
501507
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.baeldung.rome;
2+
3+
import com.sun.syndication.feed.synd.*;
4+
import com.sun.syndication.io.FeedException;
5+
import com.sun.syndication.io.SyndFeedInput;
6+
import com.sun.syndication.io.SyndFeedOutput;
7+
import com.sun.syndication.io.XmlReader;
8+
9+
import java.io.FileWriter;
10+
import java.io.IOException;
11+
import java.io.Writer;
12+
import java.net.URL;
13+
import java.util.ArrayList;
14+
import java.util.Arrays;
15+
import java.util.List;
16+
17+
public class RSSRomeExample {
18+
19+
public static void main(String[] args) throws IOException, FeedException {
20+
SyndFeed feed = createFeed();
21+
addEntryToFeed(feed);
22+
publishFeed(feed);
23+
readFeed();
24+
}
25+
26+
private static SyndFeed createFeed() {
27+
SyndFeed feed = new SyndFeedImpl();
28+
feed.setFeedType("rss_1.0");
29+
feed.setTitle("Test title");
30+
feed.setLink("http://www.somelink.com");
31+
feed.setDescription("Basic description");
32+
33+
return feed;
34+
}
35+
36+
private static void addEntryToFeed(SyndFeed feed) {
37+
SyndEntry entry = new SyndEntryImpl();
38+
entry.setTitle("Entry title");
39+
entry.setLink("http://www.somelink.com/entry1");
40+
41+
addDescriptionToEntry(entry);
42+
addCategoryToEntry(entry);
43+
44+
feed.setEntries(Arrays.asList(entry));
45+
}
46+
47+
private static void addDescriptionToEntry(SyndEntry entry) {
48+
SyndContent description = new SyndContentImpl();
49+
description.setType("text/html");
50+
description.setValue("First entry");
51+
52+
entry.setDescription(description);
53+
}
54+
55+
private static void addCategoryToEntry(SyndEntry entry) {
56+
List<SyndCategory> categories = new ArrayList<>();
57+
SyndCategory category = new SyndCategoryImpl();
58+
category.setName("Sophisticated category");
59+
categories.add(category);
60+
61+
entry.setCategories(categories);
62+
}
63+
64+
private static void publishFeed(SyndFeed feed) throws IOException, FeedException {
65+
Writer writer = new FileWriter("xyz.txt");
66+
SyndFeedOutput syndFeedOutput = new SyndFeedOutput();
67+
syndFeedOutput.output(feed, writer);
68+
writer.close();
69+
}
70+
71+
private static SyndFeed readFeed() throws IOException, FeedException {
72+
URL feedSource = new URL("http://rssblog.whatisrss.com/feed/");
73+
SyndFeedInput input = new SyndFeedInput();
74+
return input.build(new XmlReader(feedSource));
75+
}
76+
}

0 commit comments

Comments
 (0)