01: /*
02: * @(#)parseQueryString.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.servlet;
10:
11: import pnuts.servlet.*;
12: import pnuts.lang.*;
13: import java.io.*;
14: import javax.servlet.*;
15: import org.pnuts.net.URLEncoding;
16:
17: /*
18: * parseQueryString(str {, encoding})
19: */
20: public class parseQueryString extends PnutsFunction {
21:
22: public parseQueryString() {
23: super ("parseQueryString");
24: }
25:
26: public boolean defined(int narg) {
27: return (narg == 1 || narg == 2);
28: }
29:
30: protected Object exec(Object[] args, Context context) {
31: int nargs = args.length;
32: String str;
33: String encoding;
34: if (nargs == 1) {
35: str = (String) args[0];
36: encoding = ServletEncoding.getDefaultInputEncoding(context);
37: } else if (nargs == 2) {
38: str = (String) args[0];
39: encoding = (String) args[1];
40: } else {
41: undefined(args, context);
42: return null;
43: }
44: try {
45: return new ServletParameter(URLEncoding.parseQueryString(
46: str, encoding));
47: } catch (UnsupportedEncodingException e) {
48: throw new PnutsException(e, context);
49: }
50: }
51:
52: public String toString() {
53: return "function parseQueryString(str {, encoding })";
54: }
55: }
|