1 16 17 package org.apache.taglibs.application; 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 ServletContext app = null; 55 private Enumeration attributes = null; 56 private String attribute = null; 57 58 63 public final int doStartTag() throws JspException 64 { 65 app = pageContext.getServletContext(); 67 attribute = null; 68 69 if( name != null ) { 70 if( app.getAttribute(name) != null) { 71 attribute = name; 72 } 73 } else { 74 attributes = app.getAttributeNames(); 75 if( attributes == null || !attributes.hasMoreElements() ) 76 return SKIP_BODY; 77 attribute = (String )attributes.nextElement(); 78 } 79 if( attribute == null ) 80 return SKIP_BODY; 81 82 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 83 return EVAL_BODY_TAG; 84 } 85 86 91 public final int doAfterBody() throws JspException 92 { 93 if( name != null || !attributes.hasMoreElements() ) 95 return SKIP_BODY; 96 attribute = (String )attributes.nextElement(); 98 if( attribute == null ) 99 return SKIP_BODY; 100 return EVAL_BODY_TAG; 101 } 102 103 107 public final int doEndTag() throws JspException 108 { 109 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 110 try 111 { 112 if(bodyContent != null) 113 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 114 } catch(java.io.IOException e) 115 { 116 throw new JspException("IO Error: " + e.getMessage()); 117 } 118 return EVAL_PAGE; 119 } 120 121 128 public final String getName() 129 { 130 return attribute; 131 } 132 133 138 public final void setName(String name) 139 { 140 this.name = name; 141 } 142 143 150 public final String getValue() 151 { 152 Object value = app.getAttribute(attribute); 153 if( value == null ) 154 return ""; 155 return "" + value.toString(); 156 } 157 158 } 159 | Popular Tags |