1 22 23 package org.jboss.web.php; 24 25 import java.io.IOException ; 26 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpServletResponse ; 29 30 31 38 public final class SAPI 39 { 40 41 public static int write(HttpServletResponse res, 42 byte[] buf, int len) 43 { 44 try { 45 res.getOutputStream().write(buf, 0, len); 46 return len; 47 } catch (IOException e) { 48 return -1; 49 } 50 } 51 52 public static int read(HttpServletRequest req, 53 byte[] buf, int len) 54 { 55 try { 56 return req.getInputStream().read(buf, 0, len); 57 } catch (IOException e) { 58 return -1; 59 } 60 } 61 62 public static void log(Handler h, String msg) 63 { 64 h.log("php: " + msg); 65 } 66 67 public static int flush(HttpServletResponse res) 68 { 69 try { 70 res.getOutputStream().flush(); 71 return 0; 72 } catch (IOException e) { 73 return -1; 74 } 75 } 76 77 public static void header(boolean set, 78 HttpServletResponse res, 79 String name, String value) 80 { 81 if (name.equalsIgnoreCase("Content-type")) { 82 res.setContentType(value); 83 } 84 else if (name.equalsIgnoreCase("Location")) { 85 try { 86 res.sendRedirect(value); 87 } catch (IOException e) { 88 } 90 } 91 else { 92 if (set) 93 res.setHeader(name, value); 94 else 95 res.addHeader(name, value); 96 } 97 } 98 99 public static void status(HttpServletResponse res, 100 int sc) 101 { 102 res.setStatus(sc); 103 } 104 105 public static String [] env(ScriptEnvironment e) 106 { 107 return e.getEnvironmentArray(); 108 } 109 110 public static String cookies(ScriptEnvironment e) 111 { 112 return (String )e.getEnvironment().get("HTTP_COOKIE"); 113 } 114 115 116 } 117 | Popular Tags |