01: /*
02: * makeQueryString.java
03: *
04: * Copyright (c) 1997-2005 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.net;
10:
11: import java.io.UnsupportedEncodingException;
12: import java.util.Map;
13: import org.pnuts.net.URLEncoding;
14: import pnuts.lang.Context;
15: import pnuts.lang.PnutsException;
16: import pnuts.lang.PnutsFunction;
17:
18: /*
19: * makeQueryString(map, encoding)
20: */
21: public class makeQueryString extends PnutsFunction {
22:
23: public makeQueryString() {
24: super ("makeQueryString");
25: }
26:
27: public boolean defined(int narg) {
28: return narg == 2;
29: }
30:
31: protected Object exec(Object[] args, Context context) {
32: int nargs = args.length;
33: Map map;
34: String encoding;
35: if (nargs == 2) {
36: map = (Map) args[0];
37: encoding = (String) args[1];
38: } else {
39: undefined(args, context);
40: return null;
41: }
42: try {
43: return URLEncoding.makeQueryString(map, encoding);
44: } catch (UnsupportedEncodingException e) {
45: throw new PnutsException(e, context);
46: }
47: }
48:
49: public String toString() {
50: return "makeQueryString(map, encoding)";
51: }
52: }
|