GettingStarted

Using ManjyuRss is very easy.

Prepare to run RSS 2.0 read and write sample

Put ManjyuRss jar file 'manjyu-rss-?.?.?.jar' in your java class path.

Writing RSS 2.0 sample

  1. import java.io.IOException;
  2. import java.util.Date;
  3. import org.manjyu.rss.ManjyuRssSerializer;
  4. import org.manjyu.rss.vo.ManjyuRss;
  5. import org.manjyu.rss.vo.ManjyuRssChannel;
  6. import org.manjyu.rss.vo.ManjyuRssItem;
  7. public class GettingStarted001 {
  8. public static final void main(final String[] args) throws IOException {
  9. final ManjyuRss rss = new ManjyuRss();
  10. final ManjyuRssChannel channel = rss.getChannel();
  11. channel.setTitle("Sample RSS.");
  12. channel.setLink("http://www.igapyon.com/");
  13. channel.setDescription("Description of sample RSS.");
  14. channel.setLanguage("en_US");
  15. channel.setCopyright("Copyright(C) Toshiki Iga");
  16. channel.setPubDate(new Date());
  17. new ManjyuRssSerializer() {
  18. @Override
  19. protected void processItems() throws IOException {
  20. {
  21. final ManjyuRssItem item = new ManjyuRssItem();
  22. item.setTitle("bsqlformatter: Free online SQL formatter");
  23. item.setLink("http://www.igapyon.com/bsqlformatter/");
  24. item.setDescription("bsqlformatter is a Free Online SQL Formatter.");
  25. item.setPubDate(new Date());
  26. serializeItem(item);
  27. }
  28. {
  29. final ManjyuRssItem item = new ManjyuRssItem();
  30. item.setTitle("Manjyu: classify URL system");
  31. item.setLink("http://www.igapyon.com/manjyu/");
  32. item.setDescription("Manjyu is URL management system for classify URL as you want.");
  33. item.setPubDate(new Date());
  34. serializeItem(item);
  35. }
  36. }
  37. }.serialize(rss, System.out);
  38. }
  39. }

Result of writing RSS 2.0 sample

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <rss version="2.0">
  3. <!-- Generated by ManjyuRss (0.0.2-201211142334) -->
  4. <channel>
  5. <title>Sample RSS.</title>
  6. <link>http://www.igapyon.com/</link>
  7. <description>Description of sample RSS.</description>
  8. <language>en_US</language>
  9. <copyright>Copyright(C) Toshiki Iga</copyright>
  10. <pubDate>Wed, 14 Nov 2012 23:43:32 +0900</pubDate>
  11. <generator>Manjyu RSS Library (0.0.2-201211142334)</generator>
  12. <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  13. <item>
  14. <title>bsqlformatter: Free online SQL formatter</title>
  15. <link>http://www.igapyon.com/bsqlformatter/</link>
  16. <description>bsqlformatter is a Free Online SQL Formatter.</description>
  17. <pubDate>Wed, 14 Nov 2012 23:43:33 +0900</pubDate>
  18. </item>
  19. <item>
  20. <title>Manjyu: classify URL system</title>
  21. <link>http://www.igapyon.com/manjyu/</link>
  22. <description>Manjyu is URL management system for classify URL as you want.</description>
  23. <pubDate>Wed, 14 Nov 2012 23:43:33 +0900</pubDate>
  24. </item>
  25. </channel>
  26. </rss>

Reading RSS 2.0 sample

  1. import java.io.BufferedInputStream;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import org.manjyu.rss.ManjyuRssParser;
  6. import org.manjyu.rss.vo.ManjyuRssChannel;
  7. import org.manjyu.rss.vo.ManjyuRssItem;
  8. public class GettingStarted002 {
  9. public static final void main(final String[] args) throws IOException {
  10. final InputStream inStream = new BufferedInputStream(new FileInputStream("test/data/GettingStarted001.rss"));
  11. new ManjyuRssParser() {
  12. @Override
  13. protected void processChannel(final ManjyuRssChannel channel) throws IOException {
  14. System.out.println("Channel: " + channel.getTitle() + " [" + channel.getLink() + "]");
  15. System.out.println(" description: " + channel.getDescription());
  16. System.out.println(" pubDate : " + channel.getPubDate());
  17. }
  18. @Override
  19. protected void processItem(final ManjyuRssItem item) throws IOException {
  20. System.out.println(" Item: " + item.getTitle() + " [" + item.getLink() + "]");
  21. System.out.println(" description: " + item.getDescription());
  22. System.out.println(" pubDate : " + item.getPubDate());
  23. }
  24. }.parse(inStream);
  25. inStream.close();
  26. }
  27. }

Result of reading RSS 2.0 sample

  1. Channel: Sample RSS. [http://www.igapyon.com/]
  2. description: Description of sample RSS.
  3. pubDate : Wed Nov 14 23:43:32 JST 2012
  4. Item: bsqlformatter: Free online SQL formatter [http://www.igapyon.com/bsqlformatter/]
  5. description: bsqlformatter is a Free Online SQL Formatter.
  6. pubDate : Wed Nov 14 23:43:33 JST 2012
  7. Item: Manjyu: classify URL system [http://www.igapyon.com/manjyu/]
  8. description: Manjyu is URL management system for classify URL as you want.
  9. pubDate : Wed Nov 14 23:43:33 JST 2012