KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************************
2  * ResponderINFO_XML.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.Hashtable JavaDoc;
15 import java.util.Properties 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.media.MimeType;
22 import org.openlaszlo.utils.FileUtils;
23 import org.openlaszlo.utils.LZHttpUtils;
24 import org.openlaszlo.utils.StringUtils;
25 import org.openlaszlo.compiler.CompilationError;
26 import org.apache.log4j.Logger;
27
28 public final class ResponderINFO_XML extends ResponderCompile
29 {
30     private static Logger mLogger = Logger.getLogger(ResponderINFO_XML.class);
31
32     public void init(String JavaDoc reqName, ServletConfig JavaDoc config, Properties JavaDoc prop)
33         throws ServletException JavaDoc, IOException
34     {
35         super.init(reqName, config, prop);
36     }
37
38
39     /**
40      * @param fileName Full pathname to file from request.
41      */

42     protected void respondImpl(String JavaDoc fileName, HttpServletRequest JavaDoc req,
43                                HttpServletResponse JavaDoc res)
44         throws IOException
45     {
46         ServletOutputStream JavaDoc output = null;
47
48         if (fileName.endsWith(".lzo")) {
49             fileName = StringUtils.setCharAt(fileName,
50                                              fileName.length() - 1, 'x');
51         }
52
53         // Compile the file and send it out
54
try {
55             mLogger.info("Requesting info_xml for " + fileName);
56
57             output = res.getOutputStream();
58             Properties JavaDoc props = initCMgrProperties(req);
59             String JavaDoc info = mCompMgr.getInfoXML(fileName, props);
60             res.setContentType(MimeType.XML);
61
62             output.print(info);
63
64         } catch (Exception JavaDoc e) {
65             respondWithException(res, e);
66         } finally {
67             FileUtils.close(output);
68         }
69     }
70
71     public int getMimeType()
72     {
73         return MIME_TYPE_XML;
74     }
75
76     protected void handleCompilationError(CompilationError e,
77                                           HttpServletRequest JavaDoc req,
78                                           HttpServletResponse JavaDoc res)
79         throws IOException
80     {
81         respondWithErrorXML(res, e.getMessage());
82     }
83 }
84
Popular Tags