FileDocCategorySizeDatePackage
RSSItemsTag.javaAPI DocExample1870Sat Nov 22 19:55:24 GMT 2003vhexample.view

RSSItemsTag

public class RSSItemsTag extends BodyTagSupport implements IterationTag
A 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_ATTR
the names of the scripting variables
private static final String
LINK_ATTR
private int
counter
the index of the current item in the channel
private RSSInfo
rssInfo
the RSS parser
Constructors Summary
public RSSItemsTag()
Constructor

    
          
      
        super();   
        counter = 0;
    
Methods Summary
public intdoAfterBody()
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 intdoStartTag()
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;