Custom JSP taglib helps you to work with RSS (Rich Site Summary) news feeds. You can obtain
RDF files and publish them. For example, this code obtains data from www.theserverside.com and prints all the items:
<%@ taglib uri="taglib.tld" prefix="c" %>
<c:setFeed url="http://www.theserverside.com/rss/theserverside-1.0.rdf" id="A"/>
<p>Title:<c:getChannelTitle feedId="A"/>
<p>Description:<c:getChannelDescription feedId="A"/>
<c:forEachItem feedId="A">
Link:<%=itemLink%>
Title:<%=itemTitle%>
Description:<%=itemDescription%>
</c:forEachItem>
Your RDF data could be provided also as a body for setFeed tag. For data described through url parameter you can define a cache
policy: tag will save parsed data on the session or application scope.
Tag setFeed creates a bean of com.cj.rss.Channel type.
Bean com.cj.rss.Channel supports the following methods:
(all names do correspond to attributes in RSS 2.0):
java.lang.String getLanguage()
java.lang.String getCopyRight()
java.lang.String getManagingEditor()
java.lang.String getWebMaster()
java.lang.String getPubDate()
java.lang.String getLastBuildDate()
java.lang.String getCategory()
java.lang.String getGenerator()
java.lang.String getDocs()
java.lang.String getTtl()
java.lang.String getRating()
java.lang.String getSkipHours()
java.lang.String getImageURL()
java.lang.String getImageTitle()
java.lang.String getImageLink()
java.lang.String getImageDescription()
java.lang.String getImageWidth()
java.lang.String getImageHeight()
java.lang.String getCloudDomain()
java.lang.String getCloudPort()
java.lang.String getCloudPath()
java.lang.String getCloudProtocol()
java.lang.String getCloudRegisterProcedure()
java.lang.String getTextInputTitle()
java.lang.String getTextInputDescription()
java.lang.String getTextInputName()
java.lang.String getTextInputLink()
java.lang.String getSkipDays()
java.lang.String getLink()
java.lang.String getTitle()
java.lang.String getDescription()
so you can write for example:
<c:setFeed url="http://www.theserverside.com/rss/theserverside-1.0.rdf" id="A"/>
Language: <%=A.getLanguage()%>
Date: <%=A.getPubDate()%>
Tag forEachItem lets you iterate over existing items. Tag defines
a nested variable currentItem (type is com.cj.rss.Item). This
variable keeps all the attributes for the current item (as per RSS 2.0 spec).
For example:
<%@ taglib uri="taglib.tld" prefix="c" %>
<c:setFeed url="http://www.acme.com/rss/source.xml" id="A"/>
<p>Title:<c:getChannelTitle feedId="A"/>
<p>Description:<c:getChannelDescription feedId="A"/>
<c:forEachItem feedId="A">
Link:<%=currentItem.getLink()%>
Date:<%=currentItem.getPubDate()%>
etc.
</c:forEachItem>
Bean com.cj.rss.Item supports the following methods:
(all names do correspond to attributes in RSS 2.0)
java.lang.String getLink()
java.lang.String getTitle();
java.lang.String getDescription();
java.lang.String getAuthor();
java.lang.String getCategory();
java.lang.String getComments();
java.lang.String getEnclosureURL();
java.lang.String getEnclosureLength();
java.lang.String getEnclosureType();
java.lang.String getGuid();
java.lang.String getPubDate();
java.lang.String getSource();
java.lang.String getSourceURL();
For the most often used elements Title, Link, Description
tag forEachItem defines own nested variables.
Tags are:
setFeed
Body tag defines a data feed (RDF data). Parameters are:
1) url describes an URL or file path to your data file
2) id describes a name for the page scope variable you will
use as a reference for this data feed (type is com.cj.rss.Channel).
3) ttl Optional parameter. Describes a refresh time for your cache (in seconds).
Default value is -1 (do not use cache).
4) scope Optional parameter. Describes a scope for your cache.
Possible values are session or application. Default value is application.
getChannelTitle
Prints the title for the given feed or saves it in the page scope variable. Parameters are:
1) feedId Describes a name for your feed (see setFeed tag).
2) id Optional parameter. Describes a name for the page scope variable (type is java.lang.String).
Without this parameter tag just prints data.
getChannelDescription
Prints the description for the given feed or saves it in the page scope variable. Parameters are:
1) feedId Describes a name for your feed (see setFeed tag).
2) id Optional parameter. Describes a name for the page scope variable (type is java.lang.String).
Without this parameter tag just prints data.
getChannelLink
Prints the link for the given feed or saves it in the page scope variable. Parameters are:
1) feedId Describes a name for your feed (see setFeed tag).
2) id Optional parameter. Describes a name for the page scope variable (type is java.lang.String).
Without this parameter tag just prints data.
getSize
Prints the size (how many items) for the given feed or saves it in the page scope variable. Parameters are:
1) feedId Describes a name for your feed (see setFeed tag).
2) id Optional parameter. Describes a name for the page scope variable (type is java.lang.Integer).
Without this parameter tag just prints data.
forEachItem
Body tag executes own body for the each item in the given feed. Parameters are:
1) feedId Describes a name for your feed (see setFeed tag).
2) from Optional parameter. Describes an initial index for items (starting from 1).
Default value is 1.
3) to Optional parameter. Describes a last index for items. By default tag will scan all items.
4) titleId Optional parameter. Describes a name for the nested page scope variable (type is java.lang.String) you may use as a reference for the current title.
Default value is itemTitle.
5) linkId Optional parameter. Describes a name for the nested page scope variable (type is java.lang.String) you may use as a reference for the current link.
Default value is itemLink.
6) descriptionId Optional parameter. Describes a name for the nested page scope variable (type is java.lang.String) you may use as a reference for the current description.
Default value is itemDescription.
for downloading:
Library: rsstag.jar Description: taglib.tld
© Coldbeans
Comments?
See also Coldtags suite - the largest collection of custom JSP tags.
|