1 16 17 package org.apache.taglibs.page; 18 19 import java.util.*; 20 import javax.servlet.*; 21 import javax.servlet.http.*; 22 import javax.servlet.jsp.*; 23 import javax.servlet.jsp.tagext.*; 24 25 50 51 public class AttributesTag extends BodyTagSupport 52 { 53 private String name = null; 54 private Enumeration attributes = null; 55 private String attribute = null; 56 57 62 public final int doStartTag() throws JspException 63 { 64 65 attributes = pageContext.getAttributeNamesInScope(PageContext.PAGE_SCOPE); 66 if( attributes == null || !attributes.hasMoreElements() ) 67 return SKIP_BODY; 68 attribute = (String )attributes.nextElement(); 69 if( attribute == null ) 70 return SKIP_BODY; 71 72 pageContext.setAttribute(id,this); 73 return EVAL_BODY_TAG; 74 } 75 76 81 public final int doAfterBody() throws JspException 82 { 83 if( !attributes.hasMoreElements() ) 85 return SKIP_BODY; 86 attribute = (String )attributes.nextElement(); 88 if( attribute == null ) 89 return SKIP_BODY; 90 return EVAL_BODY_TAG; 91 } 92 93 97 public final int doEndTag() throws JspException 98 { 99 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 100 try 101 { 102 if(bodyContent != null) { 103 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 104 } 105 } catch(java.io.IOException e) 106 { 107 throw new JspException("IO Error: " + e.getMessage()); 108 } 109 return EVAL_PAGE; 110 } 111 112 119 public final String getName() 120 { 121 return attribute; 122 } 123 124 131 public final String getValue() 132 { 133 Object value = pageContext.getAttribute(attribute); 134 if( value == null ) 135 return ""; 136 return "" + value.toString(); 137 } 138 139 } 140 | Popular Tags |