01: /******************************************************************************
02: * ResponderXML.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import java.util.Properties;
07: import javax.servlet.ServletConfig;
08: import javax.servlet.ServletException;
09: import javax.servlet.ServletOutputStream;
10: import javax.servlet.http.HttpSession;
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.apache.log4j.Logger;
16:
17: public final class ResponderXML extends ResponderCompile {
18: private static Logger mLogger = Logger
19: .getLogger(ResponderXML.class);
20:
21: /**
22: * Overridden method from ReponseCompile.
23: *
24: * @param req unused
25: */
26: protected long getLastModified(String fileName,
27: HttpServletRequest req) {
28: // We don't care about other dependencies since all we show is the
29: // top-level LZX file.
30: return new File(fileName).lastModified();
31: }
32:
33: /**
34: * @param fileName Full pathname to file from request.
35: */
36: protected void respondImpl(String fileName, HttpServletRequest req,
37: HttpServletResponse res) throws IOException {
38: mLogger.info(
39: /* (non-Javadoc)
40: * @i18n.test
41: * @org-mes="Responding with XML for " + p[0]
42: */
43: org.openlaszlo.i18n.LaszloMessages.getMessage(
44: ResponderXML.class.getName(), "051018-52",
45: new Object[] { fileName }));
46: if (fileName.endsWith(".lzo")) {
47: fileName = StringUtils.setCharAt(fileName, fileName
48: .length() - 1, 'x');
49: }
50:
51: ServletOutputStream out = res.getOutputStream();
52: try {
53: res.setContentType("text/xml");
54: out.print(FileUtils.readFileString(new File(fileName)));
55: } finally {
56: FileUtils.close(out);
57: }
58: }
59:
60: public int getMimeType() {
61: return MIME_TYPE_XML;
62: }
63: }
|