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 InitParametersTag extends BodyTagSupport 52 { 53 private String name = null; 54 private ServletContext app = null; 55 private Enumeration parameters = null; 56 private String paramName = null; 57 58 63 public final int doStartTag() throws JspException 64 { 65 app = pageContext.getServletContext(); 67 paramName = null; 68 69 if( name != null ) { 70 if( app.getInitParameter(name) != null ) { 71 paramName = name; 72 } 73 } else { 74 parameters = app.getInitParameterNames(); 75 if( parameters != null && parameters.hasMoreElements() ) { 76 paramName = (String )parameters.nextElement(); 77 } 78 } 79 if( paramName == null ) 80 return SKIP_BODY; 81 82 pageContext.setAttribute(id,this); 83 return EVAL_BODY_TAG; 84 } 85 86 91 public final int doAfterBody() throws JspException 92 { 93 if( name != null || !parameters.hasMoreElements() ) 95 return SKIP_BODY; 96 paramName = (String )parameters.nextElement(); 98 99 if( paramName == null ) 100 return SKIP_BODY; 101 return EVAL_BODY_TAG; 102 } 103 104 108 public final int doEndTag() throws JspException 109 { 110 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 111 try 112 { 113 if(bodyContent != null) 114 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 115 } catch(java.io.IOException e) 116 { 117 throw new JspException("IO Error: " + e.getMessage()); 118 } 119 return EVAL_PAGE; 120 } 121 122 129 public final String getName() 130 { 131 return paramName; 132 } 133 134 139 public final void setName(String name) 140 { 141 this.name = name; 142 } 143 144 151 public final String getValue() 152 { 153 String paramValue = app.getInitParameter(paramName); 154 if (paramValue == null) { 155 return ""; 156 } 157 158 return paramValue; 159 } 160 161 } 162 | Popular Tags |