01: /*
02: * formatDynamicPage.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.lang.*;
12: import java.io.*;
13:
14: public class formatDynamicPage extends PnutsFunction {
15:
16: static PnutsFunction r = new readDynamicPage();
17:
18: public formatDynamicPage() {
19: super ("formatDynamicPage");
20: }
21:
22: public boolean defined(int nargs) {
23: return nargs == 1 || nargs == 2;
24: }
25:
26: protected Object exec(Object[] args, Context context) {
27: int nargs = args.length;
28: if (nargs == 0 || nargs > 2) {
29: undefined(args, context);
30: }
31: Executable exec = (Executable) r.call(args, context);
32: Context ctx = new Context(context);
33: StringWriter sw = new StringWriter();
34: ctx.setWriter(sw);
35: exec.run(ctx);
36: return sw.toString();
37: }
38:
39: public String toString() {
40: return "function formatDynamicPage((String|InputStream|Reader|File|URL) input {, encoding })";
41: }
42: }
|