Example #1
0
 protected Object exec(Object[] args, Context context) {
   int nargs = args.length;
   if (nargs != 1 && nargs != 2) {
     undefined(args, context);
     return null;
   }
   HttpServletRequest request = (HttpServletRequest) args[0];
   String enc;
   if (nargs == 1) {
     enc = ServletEncoding.getDefaultInputEncoding(context);
   } else {
     enc = (String) args[1];
   }
   String contentType = request.getContentType();
   if (contentType != null && contentType.startsWith("multipart/form-data")) {
     throw new RuntimeException("not yet implemented");
   } else {
     try {
       ByteArrayOutputStream bout = new ByteArrayOutputStream();
       byte[] buf = new byte[512];
       int n;
       InputStream in = request.getInputStream();
       while ((n = in.read(buf, 0, buf.length)) != -1) {
         bout.write(buf, 0, n);
       }
       in.close();
       String qs = new String(bout.toByteArray());
       Map map = URLEncoding.parseQueryString(qs, enc);
       return new ServletParameter(map);
     } catch (IOException e) {
       throw new PnutsException(e, context);
     }
   }
 }
Example #2
0
 protected Object exec(Object[] args, Context context) {
   int nargs = args.length;
   String str;
   String encoding;
   if (nargs == 1) {
     str = (String) args[0];
     encoding = ServletEncoding.getDefaultInputEncoding(context);
   } else if (nargs == 2) {
     str = (String) args[0];
     encoding = (String) args[1];
   } else {
     undefined(args, context);
     return null;
   }
   try {
     return new ServletParameter(URLEncoding.parseQueryString(str, encoding));
   } catch (UnsupportedEncodingException e) {
     throw new PnutsException(e, context);
   }
 }