KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************************
2  * ResponderXML.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.HttpSession JavaDoc;
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20 import org.openlaszlo.utils.FileUtils;
21 import org.openlaszlo.utils.StringUtils;
22 import org.apache.log4j.Logger;
23
24 public final class ResponderXML extends ResponderCompile
25 {
26     private static Logger mLogger = Logger.getLogger(ResponderXML.class);
27
28     /**
29      * Overridden method from ReponseCompile.
30      *
31      * @param req unused
32      */

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

43     protected void respondImpl(String JavaDoc fileName, HttpServletRequest JavaDoc req,
44                                HttpServletResponse JavaDoc res)
45         throws IOException
46     {
47         mLogger.info("Responding with XML for " + fileName);
48         if (fileName.endsWith(".lzo")) {
49             fileName = StringUtils.setCharAt(fileName, fileName.length() - 1, 'x');
50         }
51     
52         ServletOutputStream JavaDoc out = res.getOutputStream();
53         try {
54             res.setContentType ("text/xml");
55             out.print(FileUtils.readFileString(new File(fileName)));
56         } finally {
57             FileUtils.close(out);
58         }
59     }
60
61     public int getMimeType()
62     {
63         return MIME_TYPE_XML;
64     }
65 }
66
Popular Tags