1 20 package org.apache.cactus.sample.servlet; 21 22 import java.io.IOException ; 23 24 import java.util.Enumeration ; 25 26 import javax.servlet.jsp.JspTagException ; 27 import javax.servlet.jsp.JspWriter ; 28 import javax.servlet.jsp.PageContext ; 29 import javax.servlet.jsp.tagext.Tag ; 30 import javax.servlet.jsp.tagext.TagSupport ; 31 32 37 public class SampleTag extends TagSupport 38 { 39 42 private boolean showBody; 43 44 47 private boolean stopPage; 48 49 56 public void setShowBody(String isBodyShown) 57 { 58 this.showBody = "true".equals(isBodyShown.toLowerCase()); 59 } 60 61 68 public void setStopPage(String isPageStopped) 69 { 70 this.stopPage = "true".equals(isPageStopped); 71 } 72 73 80 public int doStartTag() throws JspTagException 81 { 82 Enumeration names = pageContext.getAttributeNamesInScope( 83 PageContext.PAGE_SCOPE); 84 85 JspWriter out = pageContext.getOut(); 86 87 try 88 { 89 out.println("The following attributes exist in page scope: <BR>"); 90 91 while (names.hasMoreElements()) 92 { 93 String name = (String ) names.nextElement(); 94 Object attribute = pageContext.getAttribute(name); 95 96 out.println(name + " = " + attribute + " <BR>"); 97 } 98 99 if (this.showBody) 100 { 101 out.println("Body Content Follows: <BR>"); 102 103 return EVAL_BODY_INCLUDE; 104 } 105 } 106 catch (IOException e) 107 { 108 throw new JspTagException (e.getMessage()); 109 } 110 111 return SKIP_BODY; 112 } 113 114 124 public int doEndTag() throws JspTagException 125 { 126 Tag parent = this.getParent(); 128 129 if (parent != null) 130 { 131 try 132 { 133 JspWriter out = this.pageContext.getOut(); 134 135 out.println("This tag has a parent. <BR>"); 136 } 137 catch (IOException e) 138 { 139 throw new JspTagException (e.getMessage()); 140 } 141 } 142 143 if (this.stopPage) 144 { 145 return Tag.SKIP_PAGE; 146 } 147 148 return Tag.EVAL_PAGE; 149 } 150 } 151 | Popular Tags |