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 58 59 public class QueryStringsTag extends BodyTagSupport 60 { 61 private String name = null; 62 private HttpServletRequest req = null; 63 private StringTokenizer querystrings = null; 64 private StringTokenizer querystring = null; 65 private String parameter = null; 66 private String value = null; 67 private String query = null; 68 69 75 public final int doStartTag() throws JspException 76 { 77 String qs = 79 ((HttpServletRequest)pageContext.getRequest()).getQueryString(); 80 if( qs == null || qs.length() <= 0 ) 81 return SKIP_BODY; 82 querystrings = new StringTokenizer(qs,"&"); 83 84 85 if( name != null ) { 86 String prefix = name + "="; 87 String tmp = null; 88 while( querystrings.hasMoreTokens() ) { 89 tmp = querystrings.nextToken(); 90 if( tmp.startsWith(prefix) ) { 91 query = tmp; 92 querystring = new StringTokenizer(tmp,"="); 93 break; 94 } 95 } 96 } else { 97 if( !querystrings.hasMoreTokens() ) 98 return SKIP_BODY; 99 query = querystrings.nextToken(); 100 if( query == null ) 101 return SKIP_BODY; 102 querystring = new StringTokenizer(query,"="); 103 } 104 if( querystring == null ) 105 return SKIP_BODY; 106 107 if( querystring.hasMoreTokens() ) 108 parameter = querystring.nextToken(); 109 if( querystring.hasMoreTokens() ) 110 value = querystring.nextToken(); 111 112 pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); 113 return EVAL_BODY_TAG; 114 } 115 116 121 public final int doAfterBody() throws JspException 122 { 123 if( name != null || !querystrings.hasMoreTokens() ) 125 return SKIP_BODY; 126 query = querystrings.nextToken(); 128 if( query == null ) 129 return SKIP_BODY; 130 querystring = new StringTokenizer(query,"="); 131 if( querystring == null ) 132 return SKIP_BODY; 133 134 parameter = value = null; 135 if( querystring.hasMoreTokens() ) 136 parameter = querystring.nextToken(); 137 if( querystring.hasMoreTokens() ) 138 value = querystring.nextToken(); 139 return EVAL_BODY_TAG; 140 } 141 142 146 public final int doEndTag() throws JspException 147 { 148 pageContext.removeAttribute(id,PageContext.PAGE_SCOPE); 149 try 150 { 151 if(bodyContent != null) 152 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 153 } catch(java.io.IOException e) 154 { 155 throw new JspException("IO Error: " + e.getMessage()); 156 } 157 return EVAL_PAGE; 158 } 159 160 165 public final void setName(String str) 166 { 167 name = str; 168 } 169 170 177 public final String getName() 178 { 179 if( parameter == null ) 180 return ""; 181 return parameter; 182 } 183 184 191 public final String getValue() 192 { 193 if( value == null ) 194 return ""; 195 return value; 196 } 197 198 205 public final String getQueryString() 206 { 207 if( query == null ) 208 return ""; 209 return query; 210 } 211 212 } 213 | Popular Tags |