KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > servlets > responders > ResponderWINDOW


1 /******************************************************************************
2  * ResponderWINDOW.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.servlets.responders;
11
12 import java.io.*;
13 import java.util.Properties JavaDoc;
14 import javax.servlet.ServletConfig JavaDoc;
15 import javax.servlet.ServletException JavaDoc;
16 import javax.servlet.ServletOutputStream JavaDoc;
17 import javax.servlet.http.HttpUtils JavaDoc;
18 import javax.servlet.http.HttpSession JavaDoc;
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21 import org.openlaszlo.compiler.Canvas;
22 import org.openlaszlo.utils.FileUtils;
23 import org.openlaszlo.utils.StringUtils;
24 import org.openlaszlo.utils.LZHttpUtils;
25 import org.apache.log4j.Logger;
26
27 public final class ResponderWINDOW extends ResponderCompile
28 {
29     private static Logger mLogger = Logger.getLogger(ResponderWINDOW.class);
30
31     /**
32      * Overridden method from ReponseCompile.
33      *
34      * @param req unused
35      */

36     protected long getLastModified(String JavaDoc fileName, HttpServletRequest JavaDoc req)
37     {
38         // We don't care about other dependencies since all we show is the
39
// top-level LZX file.
40
return new File(fileName).lastModified();
41     }
42
43     /**
44      * @param fileName Full pathname to file from request.
45      */

46     protected void respondImpl(String JavaDoc fileName, HttpServletRequest JavaDoc req,
47                                HttpServletResponse JavaDoc res)
48         throws IOException
49     {
50         mLogger.info("Responding with WINDOW for " + fileName);
51         if (fileName.endsWith(".lzo")) {
52             fileName = StringUtils.setCharAt(fileName, fileName.length() - 1, 'x');
53         }
54
55         ServletOutputStream JavaDoc out = res.getOutputStream();
56         try {
57             res.setContentType ("text/html");
58             writeHeader(out, null);
59             String JavaDoc name = req.getParameter("NAME");
60             if (name == null || name == "")
61                 name = "LaszloWindow";
62             String JavaDoc url = LZHttpUtils.getRequestURL(req).toString();
63             writeScriptWindow(out, url, name, getCanvas(fileName, req));
64             writeFooter(out);
65         } finally {
66             FileUtils.close(out);
67         }
68     }
69
70     /**
71      * Writes the html header tags for script window
72      * @param url The URL to show in the window
73      * @param name The name (TARGET) for the window
74      * @param out A PrintWriter
75      */

76     protected void writeScriptWindow (ServletOutputStream JavaDoc out, String JavaDoc url,
77                                       String JavaDoc name, Canvas canvas)
78         throws IOException
79     {
80         int wd = canvas.getWidth();
81         int ht = canvas.getHeight();
82
83         out.println ("<script>");
84         out.println (name + "= window.open('" + url + "', '"
85                           + name + "', ");
86         out.print (" 'width=" + wd + ",");
87         out.print ("height=" + ht + ",");
88         out.print ("toolbar=no,location=no,directories=no,");
89         out.print ("status=no,menubars=no,");
90         out.println ("scrollbars=no,resizable=no')");
91         out.println ("</script>");
92     }
93
94     public int getMimeType()
95     {
96         return MIME_TYPE_HTML;
97     }
98 }
99
Popular Tags