01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixxml;
21:
22: import java.io.IOException;
23:
24: import javax.servlet.ServletException;
25: import javax.servlet.ServletOutputStream;
26: import javax.servlet.http.HttpServlet;
27: import javax.servlet.http.HttpServletRequest;
28: import javax.servlet.http.HttpServletResponse;
29:
30: import org.w3c.dom.Document;
31:
32: import de.schlund.pfixxml.targets.cachestat.SPCacheStatistic;
33: import de.schlund.pfixxml.util.Xml;
34:
35: /**
36: * @author Joerg Haecker <haecker@schlund.de>
37: *
38: */
39: public class CacheStatisticServlet extends HttpServlet {
40:
41: private static final long serialVersionUID = -8894482678870959667L;
42: private static final int OUTPUTXML = 0;
43: private static final int OUTPUTTEXT = 1;
44:
45: /**
46: * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
47: * javax.servlet.http.HttpServletResponse)
48: */
49: protected void doGet(HttpServletRequest req, HttpServletResponse res)
50: throws ServletException, IOException {
51: int outmode = OUTPUTXML;
52:
53: String outputmode_param = req.getParameter("mode");
54:
55: if (outputmode_param != null) {
56: if (outputmode_param.equals("text")) {
57: outmode = OUTPUTTEXT;
58: }
59: }
60:
61: String output;
62:
63: if (outmode == OUTPUTXML) {
64: Document doc;
65: doc = SPCacheStatistic.getInstance()
66: .getCacheStatisticAsXML();
67: res.setContentType("text/xml");
68: output = Xml.serialize(doc, true, true);
69: } else if (outmode == OUTPUTTEXT) {
70: output = SPCacheStatistic.getInstance()
71: .getCacheStatisticAsString();
72: res.setContentType("text/plain");
73: } else {
74: throw new ServletException("No outputmode set.");
75: }
76: ServletOutputStream ostream = res.getOutputStream();
77: ostream.println(output);
78:
79: }
80:
81: /**
82: * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
83: * javax.servlet.http.HttpServletResponse)
84: */
85: protected void doPost(HttpServletRequest req,
86: HttpServletResponse res) throws ServletException,
87: IOException {
88: doGet(req, res);
89: }
90:
91: }
|