01: /******************************************************************************
02: * ResponderWINDOW.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.HttpUtils;
11: import javax.servlet.http.HttpSession;
12: import javax.servlet.http.HttpServletRequest;
13: import javax.servlet.http.HttpServletResponse;
14: import org.openlaszlo.compiler.Canvas;
15: import org.openlaszlo.utils.FileUtils;
16: import org.openlaszlo.utils.StringUtils;
17: import org.openlaszlo.utils.LZHttpUtils;
18: import org.apache.log4j.Logger;
19:
20: public final class ResponderWINDOW extends ResponderCompile {
21: private static Logger mLogger = Logger
22: .getLogger(ResponderWINDOW.class);
23:
24: /**
25: * Overridden method from ReponseCompile.
26: *
27: * @param req unused
28: */
29: protected long getLastModified(String fileName,
30: HttpServletRequest req) {
31: // We don't care about other dependencies since all we show is the
32: // top-level LZX file.
33: return new File(fileName).lastModified();
34: }
35:
36: /**
37: * @param fileName Full pathname to file from request.
38: */
39: protected void respondImpl(String fileName, HttpServletRequest req,
40: HttpServletResponse res) throws IOException {
41: mLogger.info(
42: /* (non-Javadoc)
43: * @i18n.test
44: * @org-mes="Responding with WINDOW for " + p[0]
45: */
46: org.openlaszlo.i18n.LaszloMessages.getMessage(
47: ResponderWINDOW.class.getName(), "051018-55",
48: new Object[] { fileName }));
49: if (fileName.endsWith(".lzo")) {
50: fileName = StringUtils.setCharAt(fileName, fileName
51: .length() - 1, 'x');
52: }
53:
54: ServletOutputStream out = res.getOutputStream();
55: try {
56: res.setContentType("text/html");
57: writeHeader(out, null);
58: String name = req.getParameter("NAME");
59: if (name == null || name == "")
60: name = "LaszloWindow";
61: String url = LZHttpUtils.getRequestURL(req).toString();
62: writeScriptWindow(out, url, name, getCanvas(fileName, req));
63: writeFooter(out);
64: } finally {
65: FileUtils.close(out);
66: }
67: }
68:
69: /**
70: * Writes the html header tags for script window
71: * @param url The URL to show in the window
72: * @param name The name (TARGET) for the window
73: * @param out A PrintWriter
74: */
75: protected void writeScriptWindow(ServletOutputStream out,
76: String url, String name, Canvas canvas) throws IOException {
77: int wd = canvas.getWidth();
78: int ht = canvas.getHeight();
79:
80: out.println("<script>");
81: out.println(name + "= window.open('" + url + "', '" + name
82: + "', ");
83: out.print(" 'width=" + wd + ",");
84: out.print("height=" + ht + ",");
85: out.print("toolbar=no,location=no,directories=no,");
86: out.print("status=no,menubars=no,");
87: out.println("scrollbars=no,resizable=no')");
88: out.println("</script>");
89: }
90:
91: public int getMimeType() {
92: return MIME_TYPE_HTML;
93: }
94: }
|