DayName.java

/*
  Copyright 2001, Pajato Systems Group
  Copyright 2001, Allaire Corporation
*/

package allaire.samples.invoice.taglib;

import java.io.IOException;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * An <inv:getDayName> tag outputs the name of the current day.  The
 * tag must be located within a <inv:foreachDay> tag.
 */

public class DayName extends TagSupport {

    /**
     * Output the name of the current day.
     */
public int doStartTag() throws JspException, JspTagException {

	// Validate that the tag is inside a <inv:foreachDay> tag.
DayIterator parent = (DayIterator)
	    findAncestorWithClass( this, DayIterator.class );
        if ( parent == null ) {

	    // It is not.  Throw an invoice exception.
String message = 
		"The condition tag must be inside a <foreachDay> tag.";
	    throw new JspTagException( message );
	}

	// Output the day name as maintained in the parent tag.
	try {
	    pageContext.getOut().print( parent.getDayName() );
	} catch ( IOException exc ) {
	    exc.printStackTrace();
	    throw new JspException( exc.getMessage() );
	}

	return SKIP_BODY;
    }

}