Rome Basic Introduction
Recently, companies have to develop a base with Java's RSS reader, but time is tight, find an open source framework Rome, Rome does not refer to Rome. Don't misunderstand, the Rome here is an open source Java framework, you can find it on www.java.net, which is a framework developed for RSS aggregation, allowing you to quickly develop Java-based RSS reading, publisher, stand by
RSS 0.91 Netscape
RSS 0.91 Userland
RSS 0.92
RSS 0.93
RSS 0.94
RSS 1.0
RSS 2.0
Atom 0.3
Atom 1.0
Waiting for standards. You can also extend his Module yourself, let him parse your own defined XML format. It can be said that it is a very wide framework that uses it. You must download the JDOM development package because it is parsing XML with JDom.
In the Rome, the main packages are wrapped below several packages.
com.sun.syndication.feed
com.sun.syndication.feed.atom
Data with each node in Atom
com.sun.syndication.feed.module
Modeule is a layer of data model. Can expand your own
com.sun.syndication.feed.rss
Use the value in the XML node corresponding to each of the RSS
com.sun.syndication.feed.sse com.sun.syndication.Feed.Synd
This package is the attribute com.sun.syndication.io of XML set a node in the RSS format.
This package is input and output stream.
Its UML map
figure 1
Below is an example, the function is to generate XML in the RSS format
Public class feedwriter {
Private static final string Date_Format = "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];
DateFormat DateParser = New SimpleDateFormat (Date_Format);
SYNDFEED feed = new syndfeedimpl (); // feed stream
Feed.setfeedType (feedty); // Set the RSS version
Feed.SetTitle ("Sample feed (create with rome)); //
Feed.SetLink
http://www.9cbs.net); //
Feed.SetDescription ("this feed has been createding rome; java syndication utilities");
List entries = new arraylist ();
SyndEntry Entry;
SyndContent description;
Entry = new syndiffiMPL (); // child node
Entry.SetTitle ("Rome V1.0");
Entry.SetLink
http://www.9cbs.net);
Entry.SetPublishedDate ("2004-06-08"); Description = new syndcontentImpl ();
Description.SetType ("text / place");
Description.SetValue ("Initial Release of Rome");
Entry.setdescription (Description); DESCRIPTION
Entries.Add (entry);
Entry = new syndiffnessImpl ();
Entry.SetTitle ("Rome V2.0");
Entry.SetLink
http://ww.9cbs.net);
Entry.setpublishedDate (DateParser.Parse ("2004-06-16"));
Description = new syndContentImpl (); // Description
Description.SetType ("text / xml");
Description.SetValue ("Bug Fixes,
Entry.setdescription (Description); DESCRIPTION
Entries.Add (entry);
Entry = new syndiffnessImpl ();
Entry.SetTitle ("Rome V3.0");
Entry.SetLink ("http://www.9cbs.net");
Entry.SetPublisheddate (DateParser.Parse ("2004-07-27");
Description = New SyndContentImpl ();
Description.SetType ("text / html");
Description.SetValue ("
more bug fixes, mor api changes, some new features and some unit testing p>"
"
for details check the Changes Log p>);
Entry.setdescription (Description); DESCRIPTION
Entries.Add (entry);
Feed.sentries (Entries); // Set child node
Writer Writer = New FileWriter (FileName);
SYNDFEEDOUTPUT OUTPUT = New Syndfeedoutput ();
Output.output (feed, write); // Write to the file
Writer.close ();
System.out.println ("The Feed Has Been Written to The File");
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 ();
}
}
}
That's all. The first time I wrote blog written bad. Don't take a brick :)