ZK RSS API Part II: Publish your RSS feed in chosen type

From Documentation
Revision as of 07:01, 24 October 2012 by Francishsiao (talk | contribs) (→‎Download Link)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
DocumentationSmall Talks2007JuneZK RSS API Part II: Publish your RSS feed in chosen type
ZK RSS API Part II: Publish your RSS feed in chosen type

Ian Tsai, Engineer, Potix Corporation
June 5, 2007
  1. Apache-Tomcat-5.5.X
  2. ZK 2.3.1
  3. zrss-0.8.jar
  4. Rome-0.9.jar


Last time in ZK RSS API Part I: Build your own Rss Reader, I introduced how to build a simple RSS reader.

But in server side, publisher implementation is more needed then a reader, So this time I'll demonstrate how to use ZK Rss API to build a simple Rss publishing service through a zul page in various RSS type, And I'll show some usefull functions that can help you to build more powerfull Rss service on ZK.

Quickly build

Before real code to do publishing work we need to setup ZK environment. following those steps and checkout your web.xml:

1.Enable your ZK DSP engine, Uncomment or add this segment in your web.xml:


2.Make sure WEB-INF/tld/zk/rss.dsp.tld is out there. Like JSP Tag Lib Definition, Rss Publisher need a DSP Tag Lib Definition to attache function call in DSP page.

3.Make sure WEB-INF/rss/rssPublish.dsp is out there. This is the page that will write out your content.

4. Make sure your zrss.jar is version 0.8, Ver 0.7 dosen't support publish.

After environment setting, to "Publish" a content that you prepared as a rss feed is very simple. Just embedded codes bellow in your zul page:

    import org.zkoss.zrss.*;
    import org.zkoss.zrss.samples.*;
    RssPublisher publisher = new RssPublisher( Dummy.getDemoFeed());

If you don't like zscript code polluting the page, move it to a initiator like org.zkoss.zrss.samples.RssPublishDemoInit:

public void doInit(Page page, Object[] args) throws Exception
	String[] urlList = null;
		if(args[0] instanceof String)
			urlList = ((String)args[0]).split(",");
		else if(args[0] instanceof String[]) 
			urlList = (String[]) args[0];
	// create the feed you want...
	RssFeed feed = Dummy.getDemoFeed();
	// publish feed...
	RssPublisher publisher = new RssPublisher( feed);

Then your page will like this:

<?init class="org.zkoss.zrss.samples.RssPublishDemoInit" ?>

The most dirty code in this example is RssFeed's POJO Setter works in Dummy.getDemoFeed():

//create feed and its content... 
RssFeed feed = new ZFeedImpl();

//must filled...
feed.setFeedType(Const.atom_10);//setup the output feed type...
feed.setTitle("ZK - #1 Ajax project in SourceForge.net");
feed.setDescription("ZK is an open-source Ajax Web framework"+
" that enables rich user interface for Web applications with little programming.");

//option filled...
feed.setCopyright("POTIX Corp.");
feed.setAuthor("ZK Team.");

// make RssFeedEntry List... 
List entries = new ArrayList();
RssFeedEntry entry;
for(int i=0;i<4;i++)
	entry = new ZFeedEntryImpl();
	entry.setAuthor("ZK ");
	entry.setUpdatedDate(new Date());
	catch (ParseException ex) {}
	entry.setDescription(DEMO[3][i], DEMO[4][i]);

After all those works use browser to query you page. your get your feed.

Architecture Overview

The following graph shows how the ZK RSS API works:


While Publisher was declared in a page, and its publish() Method is fired befor write anything into response, the request will be forwarded to rssPublish.dsp. thats because zul page can only output HTML to browser side, but DSP can output any text file that you want.

More Applications implemented by ZK RSS API

Use RssBinder and RssPublisher we can aggregate feeds and bridge feeds to another type during publication. Lets take a look at org.zkoss.zrss.sample.RssPublishInit in demo page rsspublish2.zul:

<?init class="org.zkoss.zrss.samples.RssPublishTypeInit"
  http://www.osnews.com/files/recent.rdf" ?>
<zk> </zk> 
//set output rssType=atom_1.0
//set output FeedSources=http://www.mozillazine.org/atom.xml + 

Download Link

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.