01: /******************************************************************************
02: * ResponderCACHEINFO.java
03: * ****************************************************************************/package org.openlaszlo.servlets.responders;
04:
05: import java.io.*;
06: import java.util.Properties;
07: import javax.servlet.ServletConfig;
08: import javax.servlet.ServletException;
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11: import javax.servlet.ServletOutputStream;
12: import org.openlaszlo.utils.FileUtils;
13: import org.openlaszlo.cache.RequestCache;
14: import org.openlaszlo.cache.Cache;
15: import org.openlaszlo.cm.CompilationManager;
16: import org.openlaszlo.sc.ScriptCompiler;
17: import org.apache.log4j.Logger;
18:
19: public final class ResponderCACHEINFO extends ResponderAdmin {
20: private static Logger mLogger = Logger
21: .getLogger(ResponderCACHEINFO.class);
22:
23: protected void respondAdmin(HttpServletRequest req,
24: HttpServletResponse res) throws IOException {
25: res.setContentType("text/xml");
26: ServletOutputStream out = res.getOutputStream();
27: String details = req.getParameter("details");
28: String sc = req.getParameter("sc"); // get script compiler param
29: try {
30: String msg = cacheInfo(details != null, sc != null);
31: out.println(msg);
32: } finally {
33: FileUtils.close(out);
34: }
35: }
36:
37: /**
38: * send cache info out the response in XML
39: */
40: public static String cacheInfo(boolean doDetails, boolean doSC)
41: throws IOException {
42: Cache mediaCache = ResponderMEDIA.getCache();
43: Cache dataCache = ResponderDATA.getCache();
44: CompilationManager compilerCache = ResponderCompile
45: .getCompilationManager();
46: Cache compilerMediaCache = null;
47: Cache scriptCache = ScriptCompiler.getScriptCompilerCache();
48:
49: if (compilerCache != null) {
50: compilerMediaCache = compilerCache.getCompilerMediaCache();
51: }
52:
53: StringBuffer buf = new StringBuffer("");
54: buf.append("<lps-cacheinfo>\n");
55: if (mediaCache != null) {
56: mediaCache.dumpXML(buf, "media-cache", doDetails);
57: }
58: if (dataCache != null) {
59: dataCache.dumpXML(buf, "data-cache", doDetails);
60: }
61: if (compilerCache != null) {
62: compilerCache.dumpXML(buf, "compiler-cache", doDetails);
63: }
64: if (compilerMediaCache != null) {
65: compilerMediaCache.dumpXML(buf, "compiler-media-cache",
66: doDetails);
67: }
68: if (doSC) {
69: if (scriptCache != null) {
70: scriptCache.dumpXML(buf, "script-cache", doDetails);
71: }
72: }
73:
74: buf.append("</lps-cacheinfo>\n");
75: return buf.toString();
76: }
77:
78: public int getMimeType() {
79: return MIME_TYPE_XML;
80: }
81: }
|