1 16 17 package org.apache.taglibs.request; 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 HttpServletRequest req = null; 55 private Enumeration attributes = null; 56 private String attribute = null; 57 58 63 public final int doStartTag() throws JspException 64 { 65 req = (HttpServletRequest)pageContext.getRequest(); 67 68 attributes = req.getAttributeNames(); 69 if( attributes == null || !attributes.hasMoreElements() ) 70 return SKIP_BODY; 71 attribute = (String )attributes.nextElement(); 72 if( attribute == null ) 73 return SKIP_BODY; 74 75 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 76 return EVAL_BODY_TAG; 77 } 78 79 84 public final int doAfterBody() throws JspException 85 { 86 if( !attributes.hasMoreElements() ) 88 return SKIP_BODY; 89 attribute = (String )attributes.nextElement(); 91 if( attribute == null ) 92 return SKIP_BODY; 93 return EVAL_BODY_TAG; 94 } 95 96 100 public final int doEndTag() throws JspException 101 { 102 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 103 try 104 { 105 if(bodyContent != null) 106 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 107 } catch(java.io.IOException e) 108 { 109 throw new JspException("IO Error: " + e.getMessage()); 110 } 111 return EVAL_PAGE; 112 } 113 114 121 public final String getName() 122 { 123 return attribute; 124 } 125 126 133 public final String getValue() 134 { 135 Object value = req.getAttribute(attribute); 136 if( value == null ) 137 return ""; 138 return "" + value.toString(); 139 } 140 141 } 142 | Popular Tags |