KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************************
2  * ResponderCACHEINFO.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.http.HttpServletRequest JavaDoc;
17 import javax.servlet.http.HttpServletResponse JavaDoc;
18 import javax.servlet.ServletOutputStream JavaDoc;
19 import org.openlaszlo.utils.FileUtils;
20 import org.openlaszlo.cache.RequestCache;
21 import org.openlaszlo.cache.Cache;
22 import org.openlaszlo.cm.CompilationManager;
23 import org.openlaszlo.sc.ScriptCompiler;
24 import org.apache.log4j.Logger;
25
26 public final class ResponderCACHEINFO extends ResponderAdmin
27 {
28     private static Logger mLogger = Logger.getLogger(ResponderCACHEINFO.class);
29
30     protected void respondAdmin(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
31         throws IOException
32     {
33         res.setContentType ("text/xml");
34         ServletOutputStream JavaDoc out = res.getOutputStream();
35         String JavaDoc details = req.getParameter("details");
36         String JavaDoc sc = req.getParameter("sc"); // get script compiler param
37
try {
38             String JavaDoc msg = cacheInfo(details != null, sc != null);
39             out.println(msg);
40         } finally {
41             FileUtils.close(out);
42         }
43     }
44
45     /**
46      * send cache info out the response in XML
47      */

48     public static String JavaDoc cacheInfo(boolean doDetails, boolean doSC)
49         throws IOException
50     {
51         Cache mediaCache = ResponderMEDIA.getCache();
52         Cache dataCache = ResponderDATA.getCache();
53         CompilationManager compilerCache = ResponderCompile.getCompilationManager();
54         Cache compilerMediaCache = null;
55         Cache scriptCache = ScriptCompiler.getScriptCompilerCache();
56
57         if (compilerCache != null) {
58             compilerMediaCache = compilerCache.getCompilerMediaCache();
59         }
60
61         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("");
62         buf.append("<lps-cacheinfo>\n");
63         if (mediaCache != null) {
64             mediaCache.dumpXML(buf, "media-cache", doDetails);
65         }
66         if (dataCache != null) {
67             dataCache.dumpXML(buf, "data-cache", doDetails);
68         }
69         if (compilerCache != null) {
70             compilerCache.dumpXML(buf, "compiler-cache", doDetails);
71         }
72         if (compilerMediaCache != null) {
73             compilerMediaCache.dumpXML(buf, "compiler-media-cache", doDetails);
74         }
75         if (doSC) {
76             if (scriptCache != null) {
77                 scriptCache.dumpXML(buf, "script-cache", doDetails);
78             }
79         }
80
81         buf.append("</lps-cacheinfo>\n");
82         return buf.toString();
83     }
84
85     public int getMimeType()
86     {
87         return MIME_TYPE_XML;
88     }
89 }
90
Popular Tags