1 23 24 package org.dbforms.util; 25 26 27 import java.util.Enumeration ; 28 import java.util.Vector ; 29 30 import javax.servlet.http.HttpServletRequest ; 31 32 33 34 40 public class ParseUtil { 41 50 public static FileHolder getFileHolder(HttpServletRequest request, 51 String name) { 52 MultipartRequest multipartRequest = (MultipartRequest) request 53 .getAttribute("multipartRequest"); 54 55 return (multipartRequest == null) ? null 56 : multipartRequest.getFileHolder(name); 57 } 58 59 60 61 69 public static String getFirstParameterStartingWith(HttpServletRequest request, 70 String str) { 71 MultipartRequest multipartRequest = (MultipartRequest) request 72 .getAttribute("multipartRequest"); 73 74 Enumeration e = (multipartRequest == null) 75 ? request.getParameterNames() 76 : multipartRequest.getParameterNames(); 77 78 while (e.hasMoreElements()) { 79 String param = (String ) e.nextElement(); 80 81 if (param.startsWith(str)) { 82 return param; 83 } 84 } 85 86 e = request.getAttributeNames(); 87 88 while (e.hasMoreElements()) { 89 String param = (String ) e.nextElement(); 90 91 if (param.startsWith(str)) { 92 return param; 93 } 94 } 95 96 return null; 97 } 98 99 100 114 public static String getParameter(HttpServletRequest request, 115 String name, 116 String def) { 117 String s = getParameter(request, name); 118 119 if (Util.isNull(s)) { 120 s = def; 121 } 122 123 return s; 124 } 125 126 127 140 public static String getParameter(HttpServletRequest request, 141 String name) { 142 String res; 143 MultipartRequest multipartRequest = (MultipartRequest) request 144 .getAttribute("multipartRequest"); 145 146 if (request.getAttribute(name) != null) { 148 res = request.getAttribute(name) 149 .toString(); 150 } else { 151 res = (multipartRequest == null) ? request.getParameter(name) 153 : multipartRequest.getParameter(name); 154 } 155 156 return res; 157 } 158 159 160 168 public static Enumeration getParameterNames(HttpServletRequest request) { 169 MultipartRequest multipartRequest = (MultipartRequest) request 170 .getAttribute("multipartRequest"); 171 172 return (multipartRequest == null) ? request.getParameterNames() 173 : multipartRequest.getParameterNames(); 174 } 175 176 177 190 public static String [] getParameterValues(HttpServletRequest request, 191 String name) { 192 MultipartRequest multipartRequest = (MultipartRequest) request 193 .getAttribute("multipartRequest"); 194 195 return (multipartRequest == null) ? request.getParameterValues(name) 196 : multipartRequest.getParameterValues(name); 197 } 198 199 200 210 public static Vector getParametersStartingWith(HttpServletRequest request, 211 String str) { 212 MultipartRequest multipartRequest = (MultipartRequest) request 213 .getAttribute("multipartRequest"); 214 Vector result = new Vector (); 215 Enumeration e = (multipartRequest == null) 216 ? request.getParameterNames() 217 : multipartRequest.getParameterNames(); 218 219 while (e.hasMoreElements()) { 220 String param = (String ) e.nextElement(); 221 222 if (param.startsWith(str)) { 223 if (!result.contains(param)) { 224 result.addElement(param); 225 } 226 } 227 } 228 229 e = request.getAttributeNames(); 230 231 while (e.hasMoreElements()) { 232 String param = (String ) e.nextElement(); 233 234 if (param.startsWith(str)) { 235 if (!result.contains(param)) { 236 result.addElement(param); 237 } 238 } 239 } 240 241 return result; 242 } 243 } 244 | Popular Tags |