1
|
|
/* Generated by AspectJ version 1.0.5 */
|
2
|
|
package org.apache.cactus.server;
|
3
|
|
import java.net.URLDecoder;
|
4
|
|
import org.apache.cactus.util.ChainedRuntimeException;
|
5
|
|
|
6
|
|
/**
|
7
|
|
* All prupose utility methods for manipulating the Servlet API.
|
8
|
|
*
|
9
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
10
|
|
*
|
11
|
|
* @version $Id: ServletUtil.html,v 1.1 2003/04/14 12:27:33 sinisa Exp $
|
12
|
|
*/
|
13
|
|
public class ServletUtil {
|
14
|
|
/**
|
15
|
|
* A substitute method for <code>HttpServletRequest.getParameter()</code>.
|
16
|
|
* Contrary to <code>getParameter()</code>, this method does not
|
17
|
|
* access the request input stream (only the query string of the url).
|
18
|
|
*
|
19
|
|
* Note: We use this method internally to retrieve Cactus parameters passed
|
20
|
|
* by the client side. The issue with <code>getParameter()</code> is that
|
21
|
|
* if you use it, then you cannot call <code>getReader()</code> or
|
22
|
|
* <code>getInputStream()</code> (see the Servlet spec). However, if we
|
23
|
|
* want to allow for testing code that uses these 2 methods (and we do !)
|
24
|
|
* we need to use this method to get the internal Cactus parameters.
|
25
|
|
*
|
26
|
|
* @param theQueryString the query string to parse
|
27
|
|
* @param theParameter the name of the parameter to locate
|
28
|
|
* @return the value for theParameter in theQueryString, null if
|
29
|
|
* theParameter does not exist and "" if the parameter exists but
|
30
|
|
* has no value defined in the query string
|
31
|
|
*/
|
32
|
3801
|
public static String getQueryStringParameter(String theQueryString, String theParameter) {
|
33
|
3801
|
if (theQueryString == null) {
|
34
|
0
|
return ((String)(null));
|
35
|
|
}
|
36
|
3801
|
String value = null;
|
37
|
3801
|
int startIndex = theQueryString.indexOf(theParameter + "=");
|
38
|
3801
|
if (startIndex >= 0) {
|
39
|
1831
|
startIndex += theParameter.length() + 1;
|
40
|
1831
|
int endIndex = theQueryString.indexOf('&', startIndex);
|
41
|
1831
|
if (endIndex > startIndex) {
|
42
|
1155
|
value = theQueryString.substring(startIndex, endIndex);
|
43
|
676
|
} else if (endIndex == startIndex) {
|
44
|
6
|
value = "";
|
45
|
|
} else {
|
46
|
670
|
value = theQueryString.substring(startIndex);
|
47
|
|
}
|
48
|
1831
|
try {
|
49
|
1831
|
value = URLDecoder.decode(value);
|
50
|
|
} catch (Exception e) {
|
51
|
0
|
throw new ChainedRuntimeException("Error URL decoding [" + value + "]", e);
|
52
|
|
}
|
53
|
|
}
|
54
|
3801
|
return value;
|
55
|
|
}
|
56
|
|
|
57
|
|
/**
|
58
|
|
* All prupose utility methods for manipulating the Servlet API.
|
59
|
|
*
|
60
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
61
|
|
*
|
62
|
|
* @version $Id: ServletUtil.html,v 1.1 2003/04/14 12:27:33 sinisa Exp $
|
63
|
|
*/
|
64
|
0
|
public ServletUtil() {
|
65
|
0
|
super();
|
66
|
|
}
|
67
|
|
}
|