1 4 5 9 10 package org.openlaszlo.servlets.responders; 11 12 import java.io.*; 13 import java.net.URL ; 14 import java.util.Properties ; 15 import javax.servlet.ServletConfig ; 16 import javax.servlet.ServletException ; 17 import javax.servlet.ServletOutputStream ; 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpServletResponse ; 20 import org.openlaszlo.utils.FileUtils; 21 import org.openlaszlo.utils.StringUtils; 22 import org.openlaszlo.xml.internal.XMLUtils; 23 import org.apache.log4j.Logger; 24 25 public final class ResponderSOURCE extends ResponderCompile 26 { 27 private static Logger mLogger = Logger.getLogger(ResponderSOURCE.class); 28 29 34 protected long getLastModified(String fileName, HttpServletRequest req) 35 { 36 return new File(fileName).lastModified(); 39 } 40 41 44 protected void respondImpl(String fileName, HttpServletRequest req, 45 HttpServletResponse res) 46 throws IOException 47 { 48 mLogger.info("Responding with SOURCE for " + fileName); 49 if (fileName.endsWith(".lzo")) { 50 fileName = StringUtils.setCharAt(fileName, fileName.length() - 1, 'x'); 51 } 52 53 ServletOutputStream out = res.getOutputStream(); 54 55 try { 56 res.setContentType ("text/html"); 57 writeHeader(out, null); 58 writeText(out, FileUtils.readFileString(new File(fileName))); 59 writeFooter(out); 60 } finally { 61 FileUtils.close(out); 62 } 63 } 64 65 71 private void writeText(ServletOutputStream out, String text) 72 throws IOException { 73 out.println ("<pre class=\"code\">"); 74 out.println (XMLUtils.escapeXmlForSWFHTML(text)); 77 out.println ("</pre>"); 78 } 79 80 81 public int getMimeType() 82 { 83 return MIME_TYPE_HTML; 84 } 85 } 86 | Popular Tags |