Weather taglib ver. 1.1

    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()
   java.lang.String getCopyRight()
   java.lang.String getLink()
   java.lang.String getTitle()
   java.lang.String getDescription()

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()
   java.lang.String getTitle();
   java.lang.String getDescription();
   java.lang.String getImage();

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
2) id describes a name for the page scope variable you will use as a reference for this data feed (type is com.cj.weather.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.

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).
2) id Optional parameter. Describes a name for the page scope variable (type is java.lang.String).

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.

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).
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.
7) imageId 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 image. Default value is itemDescription.

for downloading:

Library: weathertag.jar    Description: taglib.tld

© Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.

Also in Coldtags: