package examples;


import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

import java.io.IOException;

/**
 * PageTag class is used to tests tagext API's  
 */
public class PageTag extends ExampleTagBase  implements BodyTag {
    	
    boolean toBrowser = false;
    String TestString="";
    private String atts1,atts2;
    
 
    // setting the value from jsp att1 
    
    
    public void setAtt1(String value) {
        atts1 = value;
    }
  
    public String getAtt1() {
    	return atts1;
     }
    

    public void setAtt2(String value) {
        atts2 = value;
    }
  
    public String getAtt2() {
    	return atts2;
     }

    
    public void setToBrowser(String value) {
        if (value == null)
            toBrowser = false;
        else if (value.equalsIgnoreCase("true"))
            toBrowser = true;
        else
            toBrowser = false;
    }

// Test for setPageContext in TagSupport class.
		public void setPageContext(PageContext pc) {
		pc.setAttribute("name","pageContext");
		TestString+=pc.getAttribute("name");
	}
	


    public int doStartTag() {
        return EVAL_BODY_TAG;
    }
    
    
    public void doInitBody() throws JspException {
    }


    
    public int doAfterBody() throws JspException {
        try {


            String s = bodyOut.getString();
            System.err.println(s);
            if (toBrowser)
            	bodyOut.println(TestString);
     			bodyOut.writeOut(bodyOut.getEnclosingWriter());
            return SKIP_BODY;
        } catch (IOException ex) {
            throw new JspException(ex.toString());
        }
    }
    
}

    
        
    
