01: /******************************************************************************
02: * ResponderSOURCE.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import java.net.URL;
07: import java.util.Properties;
08: import javax.servlet.ServletConfig;
09: import javax.servlet.ServletException;
10: import javax.servlet.ServletOutputStream;
11: import javax.servlet.http.HttpServletRequest;
12: import javax.servlet.http.HttpServletResponse;
13: import org.openlaszlo.utils.FileUtils;
14: import org.openlaszlo.utils.StringUtils;
15: import org.openlaszlo.xml.internal.XMLUtils;
16: import org.apache.log4j.Logger;
17:
18: public final class ResponderSOURCE extends ResponderCompile {
19: private static Logger mLogger = Logger
20: .getLogger(ResponderSOURCE.class);
21:
22: /**
23: * Overridden method from ReponseCompile.
24: *
25: * @param req unused
26: */
27: protected long getLastModified(String fileName,
28: HttpServletRequest req) {
29: // We don't care about other dependencies since all we show is the
30: // top-level LZX file.
31: return new File(fileName).lastModified();
32: }
33:
34: /**
35: * @param fileName Full pathname to file from request.
36: */
37: protected void respondImpl(String fileName, HttpServletRequest req,
38: HttpServletResponse res) throws IOException {
39: mLogger.info(
40: /* (non-Javadoc)
41: * @i18n.test
42: * @org-mes="Responding with SOURCE for " + p[0]
43: */
44: org.openlaszlo.i18n.LaszloMessages.getMessage(
45: ResponderSOURCE.class.getName(), "051018-53",
46: new Object[] { fileName }));
47: if (fileName.endsWith(".lzo")) {
48: fileName = StringUtils.setCharAt(fileName, fileName
49: .length() - 1, 'x');
50: }
51:
52: ServletOutputStream out = res.getOutputStream();
53:
54: try {
55: res.setContentType("text/html");
56: writeHeader(out, null);
57: writeText(out, FileUtils.readFileString(new File(fileName)));
58: writeFooter(out);
59: } finally {
60: FileUtils.close(out);
61: }
62: }
63:
64: /**
65: * Writes the Text entry
66: * @param out A PrintWriter
67: * @param text A <tt>String</tt> containing the .lzx text
68: * @param message Message(s) generated during the compilation process
69: */
70: private void writeText(ServletOutputStream out, String text)
71: throws IOException {
72: out.println("<pre class=\"code\">");
73: // TODO: [2003-04-03 bloch] should rename SWFHTML to HTML
74: // since that's a better description.
75: out.println(XMLUtils.escapeXmlForSWFHTML(text));
76: out.println("</pre>");
77: }
78:
79: public int getMimeType() {
80: return MIME_TYPE_HTML;
81: }
82: }
|