RSSItemsTagpublic class RSSItemsTag extends BodyTagSupport implements IterationTagA custom tag class for the RSSItems tag. Iterates through each item in
the RSS channel, exposing the name and link of each item
as scripting variables |
Fields Summary |
---|
private static final String | NAME_ATTRthe names of the scripting variables | private static final String | LINK_ATTR | private int | counterthe index of the current item in the channel | private RSSInfo | rssInfothe RSS parser |
Constructors Summary |
---|
public RSSItemsTag()Constructor
super();
counter = 0;
|
Methods Summary |
---|
public int | doAfterBody()After each pass, iterate the counter. If there are still any items
left, set the scripting variables
if (++counter >= rssInfo.getItemCount()) {
return IterationTag.SKIP_BODY;
} else {
pageContext.setAttribute(NAME_ATTR, rssInfo.getTitleAt(counter));
pageContext.setAttribute(LINK_ATTR, rssInfo.getLinkAt(counter));
return IterationTag.EVAL_BODY_AGAIN;
}
| public int | doStartTag()Find the RSS parser in the parent tag and set the intial value of
the scripting variables.
if (rssInfo == null) {
RSSChannelTag rct =
(RSSChannelTag)findAncestorWithClass(this, RSSChannelTag.class);
rssInfo = rct.getRSSInfo();
}
pageContext.setAttribute(NAME_ATTR, rssInfo.getTitleAt(counter));
pageContext.setAttribute(LINK_ATTR, rssInfo.getLinkAt(counter));
return Tag.EVAL_BODY_INCLUDE;
|
|