KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************************
2  * ResponderKRANKSTATUS.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.URLEncoder JavaDoc;
14 import java.util.Enumeration 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.HttpSession JavaDoc;
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22 import org.openlaszlo.compiler.Canvas;
23 import org.openlaszlo.compiler.CompilationError;
24 import org.openlaszlo.cm.CompilationManager;
25 import org.openlaszlo.utils.*;
26 import org.openlaszlo.xml.internal.XMLUtils;
27 import org.apache.log4j.Logger;
28 import org.openlaszlo.servlets.KrankListener;
29
30 public final class ResponderKRANKSTATUS extends ResponderAdmin
31 {
32     private static Logger mLogger = Logger.getLogger(ResponderKRANKSTATUS.class);
33
34     /**
35        set abort=true in the request params to abort the krank thread
36      */

37     protected void respondAdmin(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
38         throws IOException
39     {
40         String JavaDoc abort = req.getParameter("abort");
41         String JavaDoc lps = req.getContextPath();
42         String JavaDoc msg = req.getParameter("msg");
43         String JavaDoc lzourl = StringUtils.replace(req.getRequestURI(), ".lzx", ".lzo");
44         KrankListener kl = CompilationManager.sKrankListener;
45         res.setContentType("text/html");
46         ServletOutputStream JavaDoc out = res.getOutputStream();
47         
48         if ("true".equals(abort)) {
49             CompilationManager.abortKrankProcess();
50             String JavaDoc xmlString = "<abort " +
51                 "lps=\"" + XMLUtils.escapeXml(lps) + "\" ";
52             if (msg != null)
53                 xmlString += "msg=\"" + XMLUtils.escapeXml(msg) + "\" ";
54             xmlString += ">" +
55                 ResponderAPP_CONSOLE.getRequestXML(req, null) +
56                 "</abort>";
57             String JavaDoc pathname =
58                 org.openlaszlo.server.LPS.getTemplateDirectory() +
59                 File.separator + "krank-abort.xslt";
60             TransformUtils.applyTransform(pathname, xmlString, out);
61         } else {
62             if (kl.isBusy()) {
63                 kl.setDuration(System.currentTimeMillis() - kl.starttime());
64             }
65             String JavaDoc xmlString = "<krank " +
66                 "appName=\"" + XMLUtils.escapeXml(""+kl.getAppname()) + "\" " +
67                 "seconds=\"" + kl.getDuration()/1000 + "\" " +
68                 "lzourl=\"" + lzourl + "\" ";
69             if (kl.isAborted())
70                 xmlString += "isAborted=\"" + XMLUtils.escapeXml(""+kl.isAborted()) + "\" ";
71             if (kl.isBusy()) {
72                 xmlString += "isBusy=\"" + XMLUtils.escapeXml(""+kl.isBusy()) + "\" ";
73             }
74             if (kl.isFinished())
75                 xmlString += "isFinished=\"" + XMLUtils.escapeXml(""+kl.isFinished()) + "\" ";
76             if (kl.isIdle())
77                 xmlString += "isIdle=\"" + XMLUtils.escapeXml(""+kl.isIdle()) + "\" ";
78             xmlString += ">" +
79                 ResponderAPP_CONSOLE.getRequestXML(req, null) +
80                 "</krank>";
81             String JavaDoc pathname =
82                 org.openlaszlo.server.LPS.getTemplateDirectory() +
83                 File.separator + "kranking.xslt";
84             TransformUtils.applyTransform(pathname, xmlString, out);
85         }
86         FileUtils.close(out);
87     }
88
89     public int getMimeType()
90     {
91         return MIME_TYPE_HTML;
92     }
93
94 }
95
Popular Tags