package examples;

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.IOException;

/**
 * LifeCycleTag class is used to tests tagext API's 
 */
public class LifeCycleTag  extends ExampleTagBase 
    implements BodyTag {


    boolean toBrowser = false;
    String TestString="";
    String endString=" method <br>";
    private String atts1,atts2,atts3,atts4,atts5,atts6;
    int count=0;
   
 
    
    // setting the value from jsp att1,att1 from JSP test case 
    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 setAtt3(String value) {
        atts3 = value;
    }
  
    public String getAtt3() {
    	return atts3;
     }
    

    public void setAtt4(String value) {
        atts4 = value;
    }
  
    public String getAtt4() {
    	return atts4;
     }

    public void setAtt5(String value) {
        atts5 = value;
    }
  
    public String getAtt5() {
    	return atts5;
     }
    

    public void setAtt6(String value) {
        atts6 = value;
    }
  
    public String getAtt6() {
    	return atts6;
     }
     
     
     
     
     
     

  
    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) {
if ("pageContext".equalsIgnoreCase (this.getAtt1())) {
	 
	TestString = TestString + this.getAtt1() + endString;
	}
}

	
// Test for doStartTag method in TagSupport class.

    public int doStartTag() {
       if ("doStartTag".equalsIgnoreCase (this.getAtt2())) { 
	TestString = TestString + this.getAtt2() + endString;
 
 
} // if condition
return EVAL_BODY_TAG;
}
    
// Test for doInitBody method in BodyTagsupport class     
    public void doInitBody() throws JspException {
       if ("doInitBody".equalsIgnoreCase (this.getAtt3())) { 
		TestString = TestString + this.getAtt3() + endString;
		}
	}

//Test for doAfterBody method in BodyTagSupport class
    
    public int doAfterBody() throws JspException {
        try {

       if ("doAfterBody".equalsIgnoreCase (this.getAtt4())) { 
		TestString = TestString + this.getAtt4() + endString;
        }
            String s = bodyOut.getString();
            System.err.println(s);
            if (false)
            	bodyOut.println(TestString);
            return SKIP_BODY;
        } catch (IOException ex) {
            throw new JspException(ex.toString());
        }
    }
    
// Test for doEndTag method in BodyTagSupport class
    
    public int doEndTag() throws JspException{
    	
       if ("doEndTag".equalsIgnoreCase (this.getAtt5())) { 
	TestString = TestString + this.getAtt5() + endString;
		} 
       return EVAL_PAGE;	
    }	


// Test for release method in BodyTagSupport class

    public void release() {
       if ("release".equalsIgnoreCase (this.getAtt6())) { 
 	TestString = TestString + this.getAtt6() + endString;

       	} 

    try {
    
        if (toBrowser)
            bodyOut.println(TestString);
     		bodyOut.writeOut(bodyOut.getEnclosingWriter());
     } catch (IOException ioe) {}

    }	



}

    
        
    
