|
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.java,v 1.2 2002/07/21 12:09:16 vmassol 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
|
4969
|
public static String getQueryStringParameter(String theQueryString, String theParameter) {
|
|
33
|
4969
|
if (theQueryString == null) {
|
|
34
|
0
|
return ((String)(null));
|
|
35
|
|
}
|
|
36
|
4969
|
String value = null;
|
|
37
|
4969
|
int startIndex = theQueryString.indexOf(theParameter + "=");
|
|
38
|
4969
|
if (startIndex >= 0) {
|
|
39
|
2421
|
startIndex += theParameter.length() + 1;
|
|
40
|
2421
|
int endIndex = theQueryString.indexOf('&', startIndex);
|
|
41
|
2421
|
if (endIndex > startIndex) {
|
|
42
|
1547
|
value = theQueryString.substring(startIndex, endIndex);
|
|
43
|
874
|
} else if (endIndex == startIndex) {
|
|
44
|
8
|
value = "";
|
|
45
|
|
} else {
|
|
46
|
866
|
value = theQueryString.substring(startIndex);
|
|
47
|
|
}
|
|
48
|
2421
|
try {
|
|
49
|
2421
|
value = URLDecoder.decode(value);
|
|
50
|
|
} catch (Exception e) {
|
|
51
|
0
|
throw new ChainedRuntimeException("Error URL decoding [" + value + "]", e);
|
|
52
|
|
}
|
|
53
|
|
}
|
|
54
|
4969
|
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.java,v 1.2 2002/07/21 12:09:16 vmassol Exp $
|
|
63
|
|
*/
|
|
64
|
0
|
public ServletUtil() {
|
|
65
|
0
|
super();
|
|
66
|
|
}
|
|
67
|
|
}
|