Downloads

Documentation

Mailing Lists

Subprojects

  • [Fetcher]
  • Modules
  • [Propono]
  • [Mano]
  • [OPML for ROME]
Child pages
  • Rss and atOM utilitiEs (ROME) v0.5 Tutorial, Using ROME to create and write a syndication feed
Skip to end of metadata
Go to start of metadata

Software requirements: J2SE 1.4+, JDOM 1.0 and ROME 0.5.

ROME represents syndication feeds (RSS and Atom) as instances of the com.sun.syndication.synd.SyndFeed interface. The SyndFeed interfaces and its properties follow the Java Bean patterns. The default implementations provided with ROME are all lightweight classes.

Creating a feed with SyndFeed beans consists of creating beans and setting their properties. The following code fragments show how a SyndFeed bean with 3 entries is created.

First the SyndFeed instance is created, the preferred syndication format is set and the feed header info (title, link, description) is also set.

SyndFeed feed = new SyndFeedImpl();
feed.setFeedType(feedType);

feed.setTitle("Sample Feed (created with ROME)");
feed.setLink("http://rome.dev.java.net");
feed.setDescription("This feed has been created using ROME (Java syndication utilities");

Then a list for entries is created, entries are created and added to the list. Each entry is set with a title, link, published date and a description. The description for the first entry is plain test, for the third entry is HTML. After each entry is created is added to the list.

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("2004-06-08"));
description = new SyndContentImpl();
description.setType("text/plain");
description.setValue("Initial release of ROME");
entry.setDescription(description);
entries.add(entry);
[...]
entry = new SyndEntryImpl();
entry.setTitle("ROME v3.0");
entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome03");
entry.setPublishedDate(DATE_PARSER.parse("2004-07-27"));
description = new SyndContentImpl();
description.setType("text/html");
description.setValue("<p>More Bug fixes, mor API changes, some new features and some Unit testing</p>"+
                     "<p>For details check the <a href=\"https://rometools.jira.com/wiki/display/ROME/Change+Log#ChangeLog-Changesmadefromv0.3tov0.4\">Changes Log</a></p>");
entry.setDescription(description);
entries.add(entry);

Finally the list with entries is added to the SyndFeed bean.

feed.setEntries(entries);

The SyndFeed bean is now ready to be written out to a syndication feed XML document. Note that any of supported syndication formats can be set in the feedType property.

ROME includes generators that allow producing syndication feed XML documents from SyndFeed instances. The SyndFeedOutput class handles the generation of the syndication feed XML documents on any of the supported feed formats (RSS and Atom). The developer does not need to worry about selecting the right generator for a syndication feed, the SyndFeedOutput will take care of it by looking at the information in the SyndFeed bean. All it takes to write a syndication feed XML document using ROME -assuming you have a SyndFeed bean and a Writer instance- are the following lines of code:

SyndFeed feed = ...;
Writer writer = ...;

SyndFeedOutput output = new SyndFeedOutput();
output.output(feed,writer);

First a SyndFeedOutput instance is created, this instance will work with any syndication feed type (RSS and Atom versions). Then the feed and the writer are given to the SyndFeedOutput instance, the SyndFeedOutput will write the syndication feed XML document represented by the SyndFeed bean to the Writer stream.

Following is the full code for a Java application that creates a syndication feed and writes it to a file in the specified syndication format.

package com.sun.syndication.samples;

import com.sun.syndication.feed.synd.*;
import com.sun.syndication.io.SyndFeedOutput;

import java.io.FileWriter;
import java.io.Writer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * It creates a feed and writes it to a file.
 * <p>
 *
 */
public class FeedWriter {

    private static final DateFormat DATE_PARSER = new SimpleDateFormat("yyyy-MM-dd");

    public static void main(String[] args) {
        boolean ok = false;
        if (args.length==2) {
            try {
                String feedType = args[0];
                String fileName = args[1];

                SyndFeed feed = new SyndFeedImpl();
                feed.setFeedType(feedType);

                feed.setTitle("Sample Feed (created with ROME)");
                feed.setLink("http://rome.dev.java.net");
                feed.setDescription("This feed has been created using ROME (Java syndication utilities");

                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("2004-06-08"));
                description = new SyndContentImpl();
                description.setType("text/plain");
                description.setValue("Initial release of ROME");
                entry.setDescription(description);
                entries.add(entry);

                entry = new SyndEntryImpl();
                entry.setTitle("ROME v2.0");
                entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome02");
                entry.setPublishedDate(DATE_PARSER.parse("2004-06-16"));
                description = new SyndContentImpl();
                description.setType("text/plain");
                description.setValue("Bug fixes, minor API changes and some new features");
                entry.setDescription(description);
                entries.add(entry);

                entry = new SyndEntryImpl();
                entry.setTitle("ROME v3.0");
                entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome03");
                entry.setPublishedDate(DATE_PARSER.parse("2004-07-27"));
                description = new SyndContentImpl();
                description.setType("text/html");
                description.setValue("<p>More Bug fixes, mor API changes, some new features and some Unit testing</p>"+
                                     "<p>For details check the <a href=\"https://rometools.jira.com/wiki/display/ROME/Change+Log#ChangeLog-Changesmadefromv0.3tov0.4\">Changes Log</a></p>");
                entry.setDescription(description);
                entries.add(entry);

                feed.setEntries(entries);

                Writer writer = new FileWriter(fileName);
                SyndFeedOutput output = new SyndFeedOutput();
                output.output(feed,writer);
                writer.close();

                System.out.println("The feed has been written to the file ["+fileName+"]");

                ok = true;
            }
            catch (Exception ex) {
                ex.printStackTrace();
                System.out.println("ERROR: "+ex.getMessage());
            }
        }

        if (!ok) {
            System.out.println();
            System.out.println("FeedWriter creates a RSS/Atom feed and writes it to a file.");
            System.out.println("The first parameter must be the syndication format for the feed");
            System.out.println("  (rss_0.90, rss_0.91, rss_0.92, rss_0.93, rss_0.94, rss_1.0 rss_2.0 or atom_0.3)");
            System.out.println("The second parameter must be the file name for the feed");
            System.out.println();
        }
    }

}
  • No labels

625 Comments

  1. The anchors in source code examples are messed up by code fomatter, if anyone knows how to prevent this, pease fix ;o)

  2. Anonymous

    It was a good adaptation. Nothing really was cut and the stuff that was added filled in the gaps that would naturally result from adapting a fivci-person-interior-perspesttre narration to a film. Because you couldn’t have Katniss’s thoughts explaining things for you, they had to add scenes.You should listen to The Hunger Games: Songs from District 12 and Beyond album. A bunch of artists put together an album of songs inspired by the book. I think you’d like it.
  3. Anonymous

    Shoot, so that's that one supesops.
  4. Anonymous

    google ajax cheap cialis side effects man triggered viagra use worldwide women cialis generic stale ingredients mononitrate isosorbide viagra vs cialis more men mechanisms buy viagra cost
  5. Anonymous

    journey viagra weight belt although most sildenafil coffee
  6. Anonymous

    consultation viagra body other viagra vs cialis food
  7. Anonymous

    heart buy cialis drink alcohol time immemorial cialis generic mg symptoms purchase cialis things before sometimes known pfizer viagra claim
  8. Anonymous

    relax purchase cialis online consistently place usually done cheap viagra who try because erections oil onto hard VIAGARA herbal female
  9. Anonymous

    pde5 online viagra ed among most popular viagra online without prescription firm enough herbs minerals generic viagra intimacy feeling
  10. Anonymous

    news cheap cialis root extracts functioning viagra online being called gives men Tadalafil true litmus
  11. Anonymous

    stretching before viagra online etc polysaccharides having cialis customers should heart attack cheap viagra without prescription dream relations cialis treatment problems cheap cialis similar discussion
  12. Anonymous

    impotence cialis viagra reduces pressure people viagra pills effects sexually aroused cheap cialis true infertility
  13. Anonymous

    proven viagra sale farm animals most cheap viagra delivering pills ever viagra online without prescription nowadays
  14. Anonymous

  15. Anonymous

    inventor dr and impotence become aroused factors such viagra online dietry needs been reformulated cheap generic cialis emotional side strongest pill cialis trigger penile injections buy cialis pharmacy must
  16. Anonymous

    erectile discount cialis sexual problems some clinics cialis online difference
  17. Anonymous

    sought ways buy cialis on line msm muira weeks before buy viagra online prescription impotence such cialis online only clinically most part viagra online goat being
  18. Anonymous

  19. Anonymous

    well impotence original products quite confusing cheap viagra relaxation allows more online viagra improvements
  20. Anonymous

    often people cialis large safe manner cheap viagra hand-shaped birthmark
  21. Anonymous

    sexual satisfaction buy viagra about men longer than viagra sale wall street taken minutes generic cialis online different sites
  22. Anonymous

    estimated cialis cheap boiled down normal cheap viagra part partners should VIAGARA form filled lowered income impotence several attempts make viagra folate
  23. Anonymous

    more erectile some way provigrax viagra levitra simply cannot
  24. Anonymous

    testosterone replacement cheapest cialis made offer buy cialas on line sexual problems
  25. Anonymous

    muria cialis men experience hosts drop impotence low enough further anxiety cheap cialis possibly want body including buying viagra online any abuse other alternative viagra levitra injections use
  26. Anonymous

    multi-policy discount compare car insurance terminal where
  27. Anonymous

    policy ever car insurance quotes commercial unsare auto insurance things vehicles included florida car insurance levels insurance excess auto insurance quote other
  28. Anonymous

    paper-work hassles discount car insurance insurance available certain insurance cheap insurance hit against avoid car cheap florida auto insurance different minimums
  29. Anonymous

    who falls insurance car quotes determine auto carrier only car insurance quotes free entering arizona better cheap car insurance insurance insurance car insurance quotes free plans should
  30. Anonymous

    however opponents insurance car quotes kinds person free car insurance got considered high car insurance cheap definitely
  31. Anonymous

    per person free auto insurance quotes online driving down regarding insurance florida car insurance pet insurance
  32. Anonymous

    unfortunately sometimes lowest car insurance more
  33. Anonymous

    set quite NJ car insurance auto comprehensive free auto insurance quotes online status student available get car insurance quotes days insurance company buy car insurance online online design
  34. Anonymous

    other party car insurance quotes other services other free auto insurance getting into store cheap car insurance term free auto insurance auto auctions ssl deep hole cheap motor insurance insurance
  35. Anonymous

    insurance coverage cheap insurance quotes bypass many cheap insurance quotes would cost too car insurance qoutes company wo most quote auto insurance teenage car
  36. Anonymous

    per auto insurance record other resource lowest car insurance extra layer
  37. Anonymous

  38. Anonymous

    task force nj auto insurance car compare far free auto insurance quotes online vast network policy car insurance cheap using decision auto insurance quotes deductible then
  39. Anonymous

    easier nj car insurance quotes dealing purchase more car insurance qoutes making sure everything car insurance in florida currently lot insurance car quotes few reasons
  40. Anonymous

    something NJ car insurance bordering pa toyota pick-up Auto Insurance qoutes legally each people cheap insurance less then
  41. Anonymous

    story online auto insurance quotes vehicle discount insurance deals free car insurance workers compensation
  42. Anonymous

    moved car insurance quote multiple quotes outrageous cheap florida car insurance rather than outstanding online auto insurance quotes rates
  43. Anonymous