Mercurial Hosting > luan
view src/luan/lib/HttpLib.java @ 88:6ca02b188dba
add LuanBit to clean up code;
add repr();
git-svn-id: https://luan-java.googlecode.com/svn/trunk@89 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 27 Feb 2013 23:50:32 +0000 |
parents | 6db8f286fa6c |
children | 8ef2d6701541 |
line wrap: on
line source
package luan.lib; import java.io.PrintStream; import java.io.IOException; import java.util.Map; import java.util.Set; import java.util.Arrays; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import luan.LuanState; import luan.LuanFunction; import luan.LuanElement; import luan.LuanException; import luan.LuanTable; public final class HttpLib { public static final String NAME = "http"; public static final String FN_NAME = "http.server"; public static void load(LuanState luan) throws LuanException { PackageLib.require(luan,NAME); Object fn = luan.get(HttpLib.FN_NAME); if( !(fn instanceof LuanFunction) ) throw luan.JAVA.exception( "function '"+HttpLib.FN_NAME+"' not defined" ); } public static void service(LuanState luan,HttpServletRequest request,HttpServletResponse response) throws LuanException, IOException { LuanFunction fn = (LuanFunction)luan.get(FN_NAME); ServletOutputStream sout = response.getOutputStream(); luan.out = new PrintStream(sout); LuanTable module = (LuanTable)luan.loaded().get(NAME); LuanTable parameters = new LuanTable(); LuanTable parameter_lists = new LuanTable(); @SuppressWarnings("unchecked") Map<String,String[]> paramMap = request.getParameterMap(); for( Map.Entry<String,String[]> entry : paramMap.entrySet() ) { String name = entry.getKey(); String[] values = entry.getValue(); parameters.put(name,values[0]); parameter_lists.put( name, new LuanTable(Arrays.asList((Object[])values)) ); } module.put("parameters",parameters); module.put("parameter_lists",parameter_lists); luan.JAVA.call(fn,FN_NAME); } /* private final HttpServletRequest request; private final HttpServletResponse response; private HttpLib(HttpServletRequest request,HttpServletResponse response) { this.request = request; this.response = response; } */ }