01: /*
02: * @(#)forward.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.net.URL;
14: import javax.servlet.*;
15: import javax.servlet.http.*;
16:
17: /*
18: * function forward(path)
19: */
20: public class forward extends PnutsFunction {
21:
22: public forward() {
23: super ("forward");
24: }
25:
26: public boolean defined(int nargs) {
27: return (nargs == 1);
28: }
29:
30: protected Object exec(Object args[], Context context) {
31: int nargs = args.length;
32: if (nargs == 1) {
33: Object arg = args[0];
34: ServletRequest request = (ServletRequest) context
35: .get(PnutsServlet.SERVLET_REQUEST);
36: if (request == null) {
37: throw new IllegalStateException();
38: }
39: ServletResponse response = (ServletResponse) context
40: .get(PnutsServlet.SERVLET_RESPONSE);
41: if (response == null) {
42: throw new IllegalStateException();
43: }
44: try {
45: if (arg instanceof String) {
46: request.getRequestDispatcher((String) arg).forward(
47: request, response);
48: } else {
49: throw new IllegalArgumentException();
50: }
51: } catch (Exception e) {
52: throw new PnutsException(e, context);
53: }
54: return null;
55: } else {
56: undefined(args, context);
57: return null;
58: }
59: }
60:
61: public String toString() {
62: return "function forward(path)";
63: }
64: }
|