1

I am a newbie to this pub/sub protocol. Sorry if my questions are very naive. Could you help me by answering my questions. I started off creating an atom feed using ROME API looking at the example given on its wiki.

SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("atom_1.0");
feed.setTitle("Sample Feed (created with ROME)");
feed.setLink("http://www.example.com");
feed.setDescription("This feed has been created using ROME";

List entries = new ArrayList();
SyndEntry entry;
SyndContent description;

entry = new SyndEntryImpl();
entry.setTitle("ROME v1.0");
entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
entry.setPublishedDate(DATE_PARSER.parse("2010-04-09"));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("Initial release of ROME");
entry.setDescription(description);
entries.add(entry);

feed.setEntries(entries);

I am writing this into a file atomfeed.xml. The default rel-attribute in the tag is . How do I set different rel-attributes using this SyndFeed's or SyndEntry's setLink() method ?

How should I publish this atomfeed.xml feed onto the web(not on any blog).Can I create a directory in my public_html folder and just publish it with that dir in my URL ? Is this the correct way of doing it ? And every time I want to add a new entry can I just update this and keep publishing it on the web ?

How is Publisher Client different from Publisher ?

Thanks for your time and help

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Sashi Kiran Challa
  • 905
  • 1
  • 11
  • 21

2 Answers2

0

You can make a SyndLink, eg

SyndLink link = new SyndLinkImpl();
link.setRel("alternative");
link.setHref("http://something.com/entry/something.xml");

Then on your entry set that

entry.setLink(link);

Then for multiple links, create a List of SyndLinks and set on the entry with setLinks(list).

http://www.jarvana.com/jarvana/view/net/java/dev/rome/rome/1.0.0/rome-1.0.0-javadoc.jar!/com/sun/syndication/feed/synd/SyndLink.html

sksamuel
  • 16,154
  • 8
  • 60
  • 108
0

Should be realized like this:

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

        SyndFeed feed = new SyndFeedImpl();
        feed.setFeedType("rss_2.0");
        feed.setTitle("Rss Title");
        feed.setDescription("Rss Description");
        feed.setAuthor("Rss Author");
        feed.setLink("http://www.rss.link.com");

        ArrayList<SyndEntry> entries = new ArrayList<>();
        // TODO: Access DB to add entries
        for(int i=0;i<3;i++){
            SyndEntry entry = new SyndEntryImpl();
            entry.setTitle("Entry Title " +i);
            entry.setLink("http://entry.link");
            SyndContent description = new SyndContentImpl();
            description.setType(MediaType.TEXT_PLAIN);
            description.setValue("Entry description "+i);
            entry.setDescription(description);
            entries.add(entry);
        }
        feed.setEntries(entries);

        response.setContentType(MediaType.APPLICATION_XML);
        SyndFeedOutput output = new SyndFeedOutput();
        try {
            output.output(feed,response.getWriter());
        } catch (FeedException e) {
            e.printStackTrace();
        }
    }
dixdragan
  • 71
  • 1