KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************************
2  * ResponderFILTER.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.net.URL JavaDoc;
14 import java.util.Properties JavaDoc;
15 import javax.servlet.RequestDispatcher JavaDoc;
16 import javax.servlet.ServletConfig JavaDoc;
17 import javax.servlet.ServletException JavaDoc;
18 import javax.servlet.ServletOutputStream JavaDoc;
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21 import org.openlaszlo.utils.LZHttpUtils;
22 import org.openlaszlo.utils.StringUtils;
23 import org.apache.log4j.Logger;
24
25 public final class ResponderFILTER extends ResponderCompile
26 {
27     private static Logger mLogger = Logger.getLogger(ResponderFILTER.class);
28
29     /**
30      * Overridden method from ReponseCompile.
31      *
32      * @param req unused
33      */

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

44     protected void respondImpl(String JavaDoc fileName, HttpServletRequest JavaDoc req,
45                                HttpServletResponse JavaDoc res)
46         throws IOException
47     {
48         mLogger.info("Responding with FILTER for " + fileName);
49         if (fileName.endsWith(".lzo")) {
50             fileName = StringUtils.setCharAt(fileName, fileName.length() - 1, 'x');
51         }
52
53         try {
54             // Give the filter our compilation mgr and tell it our uri
55
// and filename requested. (would like to send req, but Tomcat 3.3
56
// bug prevents it. neato.
57
URL JavaDoc url = LZHttpUtils.getRequestURL(req);
58             req.setAttribute ("LZF_URL", url.toString());
59             req.setAttribute ("LZF_FILENAME", fileName);
60             req.setAttribute ("LZF_COMPMGR", mCompMgr);
61             String JavaDoc FILTER = req.getParameter("filter");
62             mLogger.debug("FILTER is " + FILTER);
63             RequestDispatcher JavaDoc dispatcher = mContext.getRequestDispatcher(FILTER);
64             if (dispatcher==null) {
65                 res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
66                               "Bad or undefined filter: " + FILTER);
67                 mLogger.debug("Bad or undefined filter: " + FILTER);
68                 return;
69             }
70             dispatcher.forward(req, res);
71
72         } catch (IOException e) {
73             // FIXME: [2002-12-31 bloch]
74
// Chances are, this is the client closing the
75
// connection. We should probably just bag here
76
// rather than attempting to respond again
77
// For sure, printing the stack trace is wrong.
78
e.printStackTrace();
79         } catch (Exception JavaDoc e) {
80             respondWithException(res, e);
81         }
82     }
83
84     public int getMimeType()
85     {
86         return MIME_TYPE_HTML;
87     }
88
89 }
90
Popular Tags