Mercurial Hosting > luan
comparison src/luan/lib/HttpLib.java @ 76:97b03fc807ad
add HttpLib and WebServlet
git-svn-id: https://luan-java.googlecode.com/svn/trunk@77 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 15 Feb 2013 04:52:16 +0000 |
parents | |
children | 4bf3d0c0b6b9 |
comparison
equal
deleted
inserted
replaced
75:aa7538ae5fb6 | 76:97b03fc807ad |
---|---|
1 package luan.lib; | |
2 | |
3 import java.io.PrintStream; | |
4 import java.io.IOException; | |
5 import java.util.Map; | |
6 import java.util.Set; | |
7 import java.util.Arrays; | |
8 import javax.servlet.ServletOutputStream; | |
9 import javax.servlet.http.HttpServletRequest; | |
10 import javax.servlet.http.HttpServletResponse; | |
11 import luan.LuanState; | |
12 import luan.LuanFunction; | |
13 import luan.LuanElement; | |
14 import luan.LuanException; | |
15 import luan.LuanTable; | |
16 | |
17 | |
18 public final class HttpLib { | |
19 | |
20 public static final String NAME = "http"; | |
21 public static final String FN_NAME = "serve_http"; | |
22 | |
23 public static void service(LuanState luan,HttpServletRequest request,HttpServletResponse response) | |
24 throws LuanException, IOException | |
25 { | |
26 LuanFunction fn = (LuanFunction)luan.global.get(FN_NAME); | |
27 ServletOutputStream sout = response.getOutputStream(); | |
28 luan.out = new PrintStream(sout); | |
29 | |
30 LuanTable module = new LuanTable(); | |
31 luan.global.put(NAME,module); | |
32 | |
33 LuanTable parameters = new LuanTable(); | |
34 LuanTable parameter_lists = new LuanTable(); | |
35 @SuppressWarnings("unchecked") | |
36 Map<String,String[]> paramMap = request.getParameterMap(); | |
37 for( Map.Entry<String,String[]> entry : paramMap.entrySet() ) { | |
38 String name = entry.getKey(); | |
39 String[] values = entry.getValue(); | |
40 parameters.put(name,values[0]); | |
41 parameter_lists.put( name, new LuanTable(Arrays.asList((Object[])values)) ); | |
42 } | |
43 module.put("parameters",parameters); | |
44 module.put("parameter_lists",parameter_lists); | |
45 | |
46 luan.call(fn,LuanElement.JAVA,FN_NAME); | |
47 } | |
48 /* | |
49 private final HttpServletRequest request; | |
50 private final HttpServletResponse response; | |
51 | |
52 private HttpLib(HttpServletRequest request,HttpServletResponse response) { | |
53 this.request = request; | |
54 this.response = response; | |
55 } | |
56 */ | |
57 } |