RSSpect

About

Rsspect is a pure java implementation of the RSS news syndication format. It is a well designed and easy to use news feed library that integrates nicely with other software. It's written in pure java and can be easily integrated with other parts of your existing or new web application. It will work on any operating system supporting the JVM including Linux, Mac and Windows. It's FREE and Open Source with the Apache License!

Requirements

  • A Java Runtime (version 5 or above).
  • An application to make use of the library.

Usage

  • Add the rsspect-<version>.jar to the java classpath.The current version is 1.0.6
  • For a maven project, add the rsspect library as a maven dependency to your project.
    							<dependency>
    	<groupId>com.colorfulsoftware</groupId>
    	<artifactId>rsspect</artifactId>
    	<version>1.0.6</version>
    </dependency>
    								

Highlights

  • Downloads are available in the Maven Central Repository. The Source Code is hosted at GitHub
  • It comes with an intuitive, developer-friendly API javadoc.
  • All objects in the library are serializable, immutable and thread-safe.
  • Minimal dependencies. Atomsphere only requires a stax-api implementation to work. So if you are on java 6 there are no dependencies needed.
  • In the spirit of Open Source Software, Atomsphere is licensed with the terms of the Apache License, Version 2.0.

Examples

  • Read a file from disk into an RSS bean.
    									RSS myRSS = new RSSDoc()
    	.readRSSToBean(new File("/myPath/myRSS.xml");
    								
  • Read a file from the web into an RSS bean.
    									RSS myRSS = new RSSDoc()
    	.readRSSToBean(new URL("http://www.abcdefg.net/myRSS.xml");
    								
  • Read an RSS bean into a String.
    									String myRssStr = myRSS.toString();
    								
  • Read an RSS bean into a formatted String.
    									String myRssStr = new RSSDoc()
    	.readRSSToString(myRSS, "javanet.staxutils.IndentingXMLStreamWriter");
    								
  • Write an RSS bean to disk.
    									new RSSDoc().writeRSSDoc(new File("/somewhere/myRSS.xml"), myRSS, "UTF-8", "1.0");
    								
  • Write a formatted RSS bean to disk.
    									new RSSDoc()
    	.writeRSSDoc(new javanet.staxutils.IndentingXMLStreamWriter(
    	XMLOutputFactory.newInstance().createXMLStreamWriter(
    	new FileOutputStream("/somewhere/myRSS.xml"), "UTF-8")), myRSS, "UTF-8", "1.0");
    								
  • A CRUD example
    									
    public class CrudExample {
    	public static void main(String[] args) {
    		try {
    			RSSDoc rssDoc = new RSSDoc();
    
    			// make sure title or description is present for item
    			Title title = rssDoc.buildTitle("my title");
    			Description description = rssDoc.buildDescription("my description");
    			Item item = rssDoc.buildItem(title, null, description, null, null,
    			null, null, null, null, null, null);
    
    			// title, link and description are required for channel
    			// we add pubDate and items because these are usually there
    			Link link = rssDoc.buildLink("http://www.colorfulsoftware.com/projects/rsspect");
    			List<Item> items = new ArrayList<Item>();
    			PubDate pubDate = rssDoc.buildPubDate(Calendar.getInstance().getTime().toString());
    			items.add(item);
    			Channel channel = rssDoc.buildChannel(title, link, description,
    			null, null, null, null, pubDate,
    			null, null, null, null, null, null,
    			null, null, null, null, null, null,items);
    
    			//rss element require channel and version attribue
    			Attribute rssVersion = rssDoc.buildAttribute("version","2.0");
    			List<Attribute> attributes = new ArrayList<Attribute>();
    			attributes.add(rssVersion);
    			RSS rss = rssDoc.buildRSS(channel, attributes, null);
    			System.out.println("rss 1 : "+rss);
    			rssDoc.writeRSSDoc(new File("out1.xml"), rss, rssDoc.getEncoding(),rssDoc.getXmlVersion());
    			RSS newRSS = rssDoc.readRSSToBean(new File("out1.xml"));
    			System.out.println("newRSS 1 : "+newRSS);
    
    			//should print false
    			System.out.println("1) rss equal newRSS? "+rss.equals(newRSS));
    
    			//add the missing generator to rss
    			channel = rssDoc.buildChannel(channel.getTitle(), channel.getLink(), channel.getDescription(),
    			null, null, null, null, channel.getPubDate(),
    			null, null, rssDoc.getLibVersion(), null, null, null,
    			null, null, null, null, null, null,items);
    			rss = rssDoc.buildRSS(channel, attributes, null);
    			System.out.println("rss 2 : "+rss);
    
    			//should print true
    			System.out.println("2) rss equal newRSS? "+rss.equals(newRSS));
    
    			//make an update
    			Attribute xmlns = rssDoc.buildAttribute("xmlns:html","http://www.w3.org/1999/xhtml");
    			attributes = new ArrayList<Attribute>();
    			attributes.add(rssVersion);
    			attributes.add(xmlns);
    			Extension extension = rssDoc.buildExtension("html:html", attributes,
    			"<html:head><html:title>web markup</html:title></html:head><html:body><html:h1>Hello Web.</html:h1></html:body>");
    			List<Extension> extensions = new ArrayList<Extension>();
    			extensions.add(extension);
    			newRSS = rssDoc.buildRSS(channel, attributes, extensions);
    			System.out.println("newRSS 2 : "+newRSS);
    
    			//should print false
    			System.out.println("3) rss equal newRSS? "+rss.equals(newRSS));
    
    			//should still be able to write to file
    			rssDoc.writeRSSDoc(new File("out2.xml"), newRSS, rssDoc.getEncoding(),rssDoc.getXmlVersion());
    
    			//delete the extension
    			attributes = new ArrayList<Attribute>();
    			attributes.add(rssVersion);
    			newRSS = rssDoc.buildRSS(channel, attributes, null);
    			System.out.println("newRSS 3 : "+newRSS);
    
    			//should print true
    			System.out.println("4) rss equal newRSS? "+rss.equals(newRSS));
    
    			//another way to write the feed to file
    			BufferedWriter out = new BufferedWriter(new FileWriter("out3.xml"));
    			out.write(newRSS.toString());
    			out.close();
    
    			//another way to consume xml into a bean
    			newRSS = rssDoc.readRSSToBean(rss.toString());
    			System.out.println("newRSS 4 : "+newRSS);
    
    			//should print true
    			System.out.println("5) rss equal newRSS? "+rss.equals(newRSS));
    			System.out.println("finished.");
    
    		} catch (Exception e) {
    			System.out.println("error with feed: " + e.getMessage());
    			e.printStackTrace();
    		}
    	}
    }
    							

See Also

  • Visit the brother project Atomsphere for using Atom 1.0 feeds.