1 4 5 9 10 package org.openlaszlo.servlets.responders; 11 12 import java.io.*; 13 import java.net.URLEncoder ; 14 import java.util.Enumeration ; 15 import java.util.Properties ; 16 import javax.servlet.ServletConfig ; 17 import javax.servlet.ServletException ; 18 import javax.servlet.ServletOutputStream ; 19 import javax.servlet.http.HttpSession ; 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpServletResponse ; 22 import org.openlaszlo.compiler.Canvas; 23 import org.openlaszlo.compiler.CompilationError; 24 import org.openlaszlo.utils.*; 25 import org.apache.log4j.Logger; 26 27 public final class ResponderHTML extends ResponderCompile 28 { 29 private static Logger mLogger = Logger.getLogger(ResponderHTML.class); 30 31 34 protected void respondImpl(String fileName, HttpServletRequest req, 35 HttpServletResponse res) 36 throws IOException 37 { 38 mLogger.info("Responding with HTML wrapper for " + fileName); 39 res.setContentType ("text/html"); 40 ServletOutputStream out = res.getOutputStream(); 41 try { 42 if (fileName.endsWith(".lzo")) { 46 fileName = fileName.substring(0, fileName.length() - 1) + "x"; 47 } 48 Canvas canvas = getCanvas(fileName, req); 49 51 writeCanvas(out, req, canvas, fileName); 53 } catch (CompilationError e) { 55 out.print("<pre>\n"+e.toHTML()+"\n<pre>"); 56 } finally { 57 FileUtils.close(out); 58 } 59 } 60 61 70 private void writeCanvas (ServletOutputStream out, HttpServletRequest req, 71 Canvas canvas, String fileName) 72 throws IOException 73 { 74 String styleSheetPathname = 75 org.openlaszlo.server.LPS.getTemplateDirectory() + 76 File.separator + "html-response.xslt"; 77 String xmlString = canvas.getXML(ResponderAPP_CONSOLE.getRequestXML(req, fileName)); 78 Properties properties = new Properties (); 79 TransformUtils.applyTransform(styleSheetPathname, properties, xmlString, out); 80 } 81 82 85 private String getQueryArgs(HttpServletRequest req) { 86 StringBuffer query = new StringBuffer (); 87 Enumeration e = req.getParameterNames(); 88 while (e.hasMoreElements()) { 89 String name = (String )e.nextElement(); 90 String val = req.getParameter(name); 91 if (!name.equals("lzt")) { 92 query.append("&"+name+"="+URLEncoder.encode(val)); 93 } 94 } 95 return query.toString(); 96 } 97 98 public int getMimeType() 99 { 100 return MIME_TYPE_HTML; 101 } 102 } 103 | Popular Tags |