- ZK 2.4.1
In the pervious ZK RSS article ZK RSS API Part II: Publish your RSS feed in chosen type, we use Java API to publish RSS. This time I'll show how to use a very simple ZUML Library(a XML tag set) to publish RSS. In order to understand the important mechanism of RSS ZUML tag library, let's first discuss why to create such library like this.
The Reason Why
There are two important reasons to create a RSS ZUML tag library:
1. Non-programmer can easily publish
- Although ZRSS API is already simple enough, it is still hard for non-programmer to publish RSS. Therefore, an easy to use RSS ZUML tag library is needed. My approach is: create new text file named *.zul, copy-paste defult template page, fill the blank and that's it.
2. Avoid Version & Standards Chaos in RSS
- Although some of the RSS standards want to be "Really Simple", actually it sarcastically becomes more and more complex day after day. Sometimes (maybe most of the time) what we need is very simple: A feed with newses that human can read.
The setup work of ZK environment is same as Part II, A demo Web Application with ZK + ZRSS + ROME + JDOM jar files inside WEB-INF/lib.
After setup, let's publishing our first RSS step-by-step using new tag library:
1.Create a new zul file
- A simple plan text .zul file.
- There are only three types of tag elements defined in ZRSS: <rsspublisher>, <rssfeed>, <rssentry>. The following is a sample template page to build a RSS publishing service:
<?xml version="1.0" encoding="UTF-8"?> <zk> <!--***** Publisher component *****--> <rsspublisher timeout=""> <!--***** main feed, only one*****--> <rssfeed feedType="" link="" copyright="" author="" publishedDate="" title="" description=""> <!--***** entries *****--> <rssentry title="" author="" link="" publishedDate="" updatedDate=""> <attribute name="description"><![CDATA[ //output feed entry contents... ]]></attribute> </rssentry> </rssfeed> <!--***** aggregate other feed's entries*****--> <rssfeed aggregate="true" url=""/> </rsspublisher> </zk>
3.Test sample page
- Put your zul page in demo web application and various rss readers can be used testing it. In our demo, you can test result RSS using: $TOMCAT_HOME/webapps/zrss/rss.zul.(e.g Tomcat webapps folder)
- Click "Add New Feed" button, fill your feed's URL, and press confirm button to see the result.
Unique Main feed & Aggregate Function
The boolean attribute: aggregate is used to indicate that a feed is an aggregate feed. If the value is false, this feed is a main feed.
<rssfeed ...> //content... </rssfeed> <rssfeed aggregate="true" url=""/>
In a publisher tag's children, there only can be a single main feed or none. In contrast, aggregate feeds can be multiple in one publisher. ZRSS uses aggregate feeds to add more entries from other site into the feed you published in current version. When trying to aggregate multiple feeds, ZRSS use multithreads to parallel downloading feed content. The timeout attribute in <rsspublisher> can help you ignore those requesting feeds which been waited for too long.
ZK Component Implementation
As tags in template page that been demonstrated, There are three ZK Components: Rsspublisher,Rssfeed and Rssentry- Component in org.zkoss.zrss.ui package. The org.zkoss.zk.ui.ext.AfterCompose interface is implemented to support public void afterCompose() method in these 3 components. Since the method is invoked in Component Creation Phase(If you want to know more about zul page's lifecycle, see ZK-devguide.pdf: 4. The Component Lifecycle.). Therefore, no event handling will be taken in the response content.
ZRSS Component & Tag Attributes
Because ZK UI Engine can directly map tag attributes to Component setter & getter methods. The attributes in org.zkoss.zrss.ui.Rssfeed and org.zkoss.zrss.ui.Rssentry are defined on RssFeed and RssEntry interfaces. Here is the list of mostly used attributs:
- timeout: used to set timeout attribute to ignore no response aggregate feeds
- feedType(required): used to set output feed type, support
- aggregate(option): Defult value is false, set true if this is a aggregate feed.
- url(option):used when this is a aggregate feed to request RSS site.
- author: author of this feed.
- publishedDate: publish date about this feed.
- title: title of this feed.
- description: description of this feed.
- link: link to web site home page.
- copyright: copyright of this feed content.
- title: title of this entry.
- author: author of this entry.
- link: URL link about this entry.
- publishedDate: publish date about this entry.
- updatedDate: update date about this entry.
- description: main content in this entry.
- zrss.war(without jar files inside)
- zrss-0.9.zip(from SourceForge.net - zkapp)
- ZK-2.4.1.zip(ZK standard Library)
|Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.|