1 16 17 package org.apache.taglibs.session; 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 HttpSession sess = null; 55 private Enumeration attributes = null; 57 private String attribute = null; 59 60 65 public final int doStartTag() throws JspException 66 { 67 sess = pageContext.getSession(); 69 70 attributes = sess.getAttributeNames(); 72 if( attributes == null || !attributes.hasMoreElements() ) 73 return SKIP_BODY; 74 attribute = (String )attributes.nextElement(); 75 if( attribute == null ) 76 return SKIP_BODY; 77 78 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 79 return EVAL_BODY_TAG; 80 } 81 82 87 public final int doAfterBody() throws JspException 88 { 89 if( !attributes.hasMoreElements() ) 91 return SKIP_BODY; 92 attribute = (String )attributes.nextElement(); 93 if( attribute == null ) 94 return SKIP_BODY; 95 return EVAL_BODY_TAG; 97 } 98 99 105 public final int doEndTag() throws JspException 106 { 107 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 108 try 109 { 110 if(bodyContent != null) 111 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 112 } catch(java.io.IOException e) 113 { 114 throw new JspException("IO Error: " + e.getMessage()); 115 } 116 return EVAL_PAGE; 117 } 118 119 126 public final String getName() 127 { 128 return attribute; 129 } 130 131 138 public final String getValue() 139 { 140 Object value = sess.getAttribute(attribute); 141 if( value == null ) 142 return ""; 143 return "" + value.toString(); 144 } 145 146 } 147 | Popular Tags |