01: // CheckpointFrame.java
02: // $Id: CheckpointFrame.java,v 1.6 2000/08/16 21:37:44 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // please first read the full copyright statement in file COPYRIGHT.HTML
05:
06: package org.w3c.jigsaw.resources;
07:
08: import org.w3c.tools.resources.FramedResource;
09: import org.w3c.tools.resources.ProtocolException;
10: import org.w3c.tools.resources.Resource;
11: import org.w3c.tools.resources.ResourceException;
12: import org.w3c.tools.resources.ResourceFrame;
13:
14: import org.w3c.www.http.HTTP;
15: import org.w3c.www.http.HttpMessage;
16:
17: import org.w3c.jigsaw.frames.HTTPFrame;
18:
19: import org.w3c.jigsaw.http.Reply;
20: import org.w3c.jigsaw.http.Request;
21:
22: import org.w3c.jigsaw.html.HtmlGenerator;
23:
24: import java.util.Date;
25:
26: public class CheckpointFrame extends HTTPFrame {
27:
28: public void registerResource(FramedResource resource) {
29: super .registerOtherResource(resource);
30: }
31:
32: public CheckpointResource getChekpointResource() {
33: if (getResource() instanceof CheckpointResource)
34: return (CheckpointResource) getResource();
35: else
36: return null;
37: }
38:
39: /**
40: * Get the content of that resources.
41: * Will display some usefull commands to start/stop the attached thread
42: * @param request The request to handle.
43: * @exception ProtocolException If request processing failed.
44: * @exception ResourceException If this resource got a fatal error.
45: */
46:
47: protected Reply getOtherResource(Request request)
48: throws ProtocolException, ResourceException {
49: CheckpointResource chkpr = getChekpointResource();
50: if (chkpr == null)
51: throw new ResourceException(
52: "this frame is not attached to a "
53: + "CheckpointResource. ("
54: + getResource().getIdentifier() + ")");
55: String query = request.getQueryString();
56: if (query != null) {
57: if (query.equals("start")) {
58: // Start the thread if needed
59: chkpr.activate();
60: } else if (query.equals("stop")) {
61: // Stop the thread
62: chkpr.stop();
63: }
64: }
65: // Emit output:
66: HtmlGenerator g = new HtmlGenerator("CheckpointResource");
67: addStyleSheet(g);
68: g.append("<h1>CheckpointResource status</h1>");
69: g
70: .append("<p>Checkpoint is currently ",
71: ((chkpr.thread == null) ? " stopped "
72: : "running"), ".");
73: g.append("<hr>You can:<p><dl>");
74: g.append("<dt><a href=\"", chkpr.getURLPath(),
75: "?start\">start</a><dd>Start the checkpointer.");
76: g.append("<dt><a href=\"", chkpr.getURLPath(),
77: "?stop\">stop</a><dd>Stop the checkpointer.");
78: g.append("</dl><hr>Last checkpoint at <strong>",
79: ((chkpr.checkpoint == null) ? "no checkpoint run yet"
80: : chkpr.checkpoint.toString()), "</strong>.");
81: Reply reply = createDefaultReply(request, HTTP.OK);
82: reply.setNoCache();
83: reply.setStream(g);
84: return reply;
85: }
86:
87: }
|