01: /*
02: * getInitParameter.java
03: *
04: * Copyright (c) 2006 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.Context;
13: import pnuts.lang.PnutsFunction;
14: import pnuts.lang.PnutsException;
15: import javax.servlet.*;
16: import javax.servlet.http.*;
17: import java.util.*;
18: import java.io.*;
19: import org.pnuts.net.URLEncoding;
20:
21: /*
22: *
23: */
24: public class getInitParameter extends PnutsFunction {
25:
26: static getInitParameter instance = new getInitParameter();
27:
28: static PnutsFunction getInstance() {
29: return instance;
30: }
31:
32: public getInitParameter() {
33: super ("getInitParameter");
34: }
35:
36: public boolean defined(int narg) {
37: return narg == 1;
38: }
39:
40: protected Object exec(Object[] args, Context context) {
41: int nargs = args.length;
42: if (nargs == 1) {
43: Servlet servlet = (Servlet) context
44: .get(PnutsServlet.SYMBOL_THIS);
45: ServletConfig config = servlet.getServletConfig();
46: return config.getInitParameter((String) args[0]);
47: } else {
48: undefined(args, context);
49: return null;
50: }
51: }
52:
53: public String toString() {
54: return "function getInitParameter( key )";
55: }
56: }
|