Custom JSP taglib lets you obtain a world weather forecast from site yr.no and use
extracted data in your applications. As per site policy you can use data for free, just provide a copyright info as well as the link to the original data.
For example, the following code prints weather forecast for Moscow:
<%@ taglib uri="taglib.tld" prefix="w" %> <w:setLocation url="http://www.yr.no/place/Russia/Moscow/Moscow/" id="A"/> <p>Title:<w:getChannelTitle feedId="A"/> <p>Description:<w:getChannelDescription feedId="A"/> <p>Copyright:<w:getChannelCopyright feedId="A"/> <w:forEachDay feedId="A"> Link:<%=itemLink%> Title:<%=itemTitle%> Description:<%=itemDescription%> </w:forEachDay> Tag setLocation creates a bean of com.cj.weather.Channel type. You have to provide an URL to data on yr.no site. Bean com.cj.weather.Channel supports the following methods: (all names do correspond to attributes in RSS 2.0): java.lang.String getLanguage()
so you can write for example:
<w:setFeed url="http://www.yr.no/place/Russia/Moscow/Moscow/" id="A"/> Link: <%=A.getLink()%> Copyright: <%=A.getCopyRight()%> Tag forEachDay lets you iterate over existing items. Tag defines
a nested variable currentItem (type is com.cj.weather.Item). This
variable keeps all the attributes for the current item (as per RSS 2.0 spec).
For example (London's weather):
<%@ taglib uri="taglib.tld" prefix="w" %> <w:setLocation url="http://www.yr.no/place/United_Kingdom/England/London/" id="B"/> <p>Title:<w:getChannelTitle feedId="B"/> <p>Description:<w:getChannelDescription feedId="B"/> <w:forEachDay feedId="B"> Link:<%=currentItem.getTitle()%> Weather:<%=currentItem.getDescription()%> etc. </w:forEachDay> Bean com.cj.weather.Item supports the following methods: java.lang.String getLink()
For the most often used elements Title, Link, Description, Image tag forEachDay defines own nested variables. Tags are: setLocation Body tag defines an URL from yr.no (weather data). Parameters are: 1) url describes an URL
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).
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).
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).
getChannelCopyright Prints the copyright info 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).
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).
forEachDay Body tag executes own body for the each day in the given forecast feed. Parameters are: 1) feedId Describes a name for your feed (see setFeed tag).
for downloading: Library: weathertag.jar Description: taglib.tld See also Coldtags suite - the largest collection of custom JSP tags.
|
Also in Coldtags:
|