FileDocCategorySizeDatePackage
ForAllArticles.javaAPI DocExample1980Sun Mar 25 15:30:56 BST 2001jabadot

ForAllArticles

public class ForAllArticles extends BodyTagSupport
JSP Custom Tag class for iterating over all JabaDot news articles.
author
Ian Darwin, ian@darwinsys.com
version
$Id: ForAllArticles.java,v 1.2 2001/03/25 19:30:57 ian Exp $

Fields Summary
private String
element
private Iterator
it
private Object
o
private NewsArticleDB
theNews
private ArrayList
articles
Constructors Summary
public ForAllArticles()


	  
		try {
			articles = theNews.getCurrentArticles();
		} catch (IOException ex) {
			System.err.println("ForAllArticles.init: " +
				ex.toString());
		}
	
Methods Summary
public intdoAfterBody()
Called AFTER the first (and subsequent) body has been output. This one controls the iteration!!

		if (it == null) {
			return Tag.SKIP_BODY;
		}
		if (it.hasNext()) {
			o = it.next();

			// Put the "bean" named "element", really NewsArticle object in o,
			// into the pageContext where <jsp:getProperty can find it.
			pageContext.setAttribute(element, o);

		 	return BodyTag.EVAL_BODY_TAG;	// Process it.
		}
		// All done the iterator, don't do body any more.
		return Tag.SKIP_BODY;
	
public intdoEndTag()
Final step - actually output something!

		try {
			if (bodyContent != null) {
				bodyContent.writeOut(bodyContent.getEnclosingWriter());
			}
			return Tag.EVAL_PAGE;
		} catch (IOException ex) {
			throw new JspException(ex.toString());
		}
	
public intdoStartTag()
Called after the start tag. Must get the *first* element from the collection and put it into the collection.

		// DELEGATE - code is all common.
		return doAfterBody();
	
public voidsetElement(java.lang.String elem)

		element = elem;
		// reset the iterator!
		it = articles.iterator();
		// System.err.println("ForAllArticles: it=" + it);