ZK RSS Publish Revisit: Implemented with ZK XML Components"
m (moved Small Talks/ZK RSS Publish Revisit: Implemented with ZK XML Components to Small Talks/2007/September/ZK RSS Publish Revisit: Implemented with ZK XML Components)
|Line 14:||Line 14:|
Last time in [
Last time in [///ZK_RSS_API_Part_III:_Make_Your_RSS_Publishing_More_Easily_with_ZK ZK RSS API Part III: Make Your RSS Publishing More Easily with ZK], I introduced how to use ZK RSS to publish your rss within a zul page. This time because ZK-2.5.0 begins to support ZK XML output and native namespace concept, I'll show how to refactor ZRSS to publish rss feed by using ZK XML output.
=Setup ZRSS Environment=
=Setup ZRSS Environment=
Latest revision as of 08:14, 8 December 2010
Jumper Chen, Engineer, Potix Corporation
September 28, 2007
- ZK Freshly (zk-2.5.0-FL-2007-08-29 and later)
Last time in ZK RSS API Part III: Make Your RSS Publishing More Easily with ZK, I introduced how to use ZK RSS to publish your rss within a zul page. This time because ZK-2.5.0 begins to support ZK XML output and native namespace concept, I'll show how to refactor ZRSS to publish rss feed by using ZK XML output.
Setup ZRSS Environment
After downloading needed resources listed at the end of this article, please following the steps below:
1. Unpack rssxml.war as folder "/rssxml".
2. Unpack zk-bin-2.5.0-FL-2007-08-XX.zip, and put all JAR files into "/rssxml/WEB-INF/lib/".
3. Put "Rome-0.9.jar" and "jdom.jar" into "/rssxml/WEB-INF/lib/".
4. Modify web.xml:
//Add this Servlet Mapping. Use zkLoader to handle zrss document. <servlet-mapping> <servlet-name>zkLoader</servlet-name> <url-pattern>*.zrss</url-pattern> </servlet-mapping>
//Add this Language Mapping. Use XML output device to handle *.zrss file. <language-mapping> <language-name>xml</language-name> <extension>zrss</extension> </language-mapping>
6. Put or link folder "/rssxml" to Tomcat( or any other JavaEE Web Container) and startup the web server.
Write a ZK RSS Publish Document(*.zrss file)
To publish your RSS, here is an exemple of a zrss document:
<r:rsspublisher id="publish" timeout="15" xmlns:r="http://www.zkoss.org/2007/xml" > <rssfeed> <attribute name="feedType">atom_1.0</attribute> <attribute name="title">ZK - #1 Ajax project in SourceForge.net</attribute> <attribute name="link">http://www.zkoss.org</attribute> <attribute name="copyright">POTIX Corp.</attribute> <attribute name="author">POTIX Engineer: Ian Tsai</attribute> <attribute name="description">A Simple Description.</attribute> <attribute name="publishedDate">2007/07/05</attribute> <rssentry> <attribute name="title">ZK 2.4 out now. Enrich your web application today. </attribute> <attribute name="author">Tom Yeh</attribute> <attribute name="link">http://www.zkoss.org/download/</attribute> <attribute name="publishedDate">2007/06/08</attribute> <attribute name="updatedDate">2007/06/08</attribute> <attribute name="description"><![CDATA[<b>A Simple Description.</b> ]]></attribute> </rssentry> </rssfeed> ... <rssfeed aggregate="true" url="..."/> </r:rsspublisher>
As we can see, this document is very like the previous version of ZRSS publisher. Although the concepts behind them are totally different, the only changed part between these two documents is that the current version of <r:rsspublisher> needs to declare it's namespace: xmlns:r="http://www.zkoss.org/2007/xml".
If you want to know more detailed information about configuration in other part, please refer to ZK RSS API Part III: Make Your RSS Publishing More Easily with ZK.
In downloaded demo package rssxml.war, you can use any RSS reader to browse the result in URL: http://localhost/rssxml/publish.zrss.
ZK Native Name Space & ZK XML Output Concept
Before explaining the implementation of ZRSS over ZK XML output, I'll briefly explain these two new features from ZK 2.5.0:
1. ZK XML Output
- While a ZUML page is requested, ZK parser will use the suffix of this request's URL(e.g. *.zul, *.mil, *.zhtml etc) to choose the right way to generate the response document. And in ZK-2.5.0 we add a new way for parser to handle the request from such client side application which requires a XML over HTTP response. In this demo, this client side application is an RSS reader.
2. ZK Native Name Space
- With the Native namespace, an XML element in a ZUML page denotes that it should be sent to the client side application directly rather than becoming a ZK component. It provides better performance for static element declaration and plays an important part in ZK XML output. Actually if any ZUML page is denoted to response by XML output, all elements in this page will be regarded using ZK Native namespace by default.
The Implementation of ZK RSS Publisher with ZK XML Component
Based on the code clips I showed above, now we know what it means by the xmlns attribute with value: "http://www.zkoss.org/2007/xml" in <r:rsspublisher> tag. It means ZK must generate target component mapped by <r:rsspublisher> tag which is defined in "http://www.zkoss.org/2007/xml" Component set, and can't directly output as other plan text tags like <rssfeed>, <rssentry> and <attribute>.
The picture below shows the component structure of zrss document.
ZK processes this document by using XML output setting, and the first element <r:rsspublisher> will make ZK generate corresponding component whose Java class must extends org.zkoss.zml.XmlNativeComponent. You can find the definition of rsspublisher in zrss.jar->metainfo/zk/lang-addon.xml.
The <rssfeed>, <rssentry> and <attribute> tags will be treated as native plan text document. While ZK invokes rsspublisher's redraw() method. rsspublisher will EAT this document and parse it to generate target rss content to page.
Compared with the previous ZK RSS publishing Model, the current implementation is more straightforward. The comparison in pictures are shown below:
Privious Version of ZRSS:
Current Version of ZRSS:
- rssxml.war(without jar files inside)
- zrss-0.9.5.zip(from SourceForge.net - zkapp)
- zk-2.5.0-FL-2007-08-29.zip( ZK-freshly or later)
|Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.|