01: package de.webman.generator.eventhandler;
02:
03: import java.io.*;
04: import java.net.*;
05: import java.util.*;
06:
07: import com.teamkonzept.lib.*;
08: import com.teamkonzept.web.TKEvent;
09: import com.teamkonzept.web.TKHttpInterface;
10: import com.teamkonzept.webman.*;
11: import com.teamkonzept.webman.mainint.*;
12: import com.teamkonzept.webman.mainint.events.*;
13: import de.webman.acl.LoginFactory;
14:
15: /**
16: * Starts the site transmitter
17: * @author $Author: torsten $
18: * @version $Revision: 1.7 $
19:
20: */
21: public class GRTransmitHandler extends DefaultEventHandler {
22:
23: private static GRTransmitHandler instance = new GRTransmitHandler();
24:
25: boolean usePushlet = false;
26:
27: private GRTransmitHandler() {
28: }
29:
30: public static GRTransmitHandler getInstance() {
31: return instance;
32: }
33:
34: public void handleEvent(TKEvent evt) throws TKException {
35: try {
36: WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(),
37: ContextConstants.GENERATOR);
38: if (GRGenerateHandler.isGenerationInProgress()) {
39: throw new TKUserException("Generation in Progress",
40: GENERATION_IN_PROGRESS, USER_SEVERITY, false,
41: null);
42: }
43: TKHttpInterface httpInf = evt.getHttpInterface();
44: PrintWriter log = new PrintWriter(httpInf.getLogStream());
45: boolean success = false;
46:
47: //Ausgaben in schönes HTML verpacken
48: GRHTMLWrapper out = new GRHTMLWrapper(new PrintWriter(
49: httpInf.getOutputStream()), httpInf
50: .getContextPath());
51:
52: try {
53: String args = "";
54: // getting config file through url
55: Hashtable params = httpInf.getParams();
56: String query = (String) params
57: .get("TK_PAR[configuration]");
58: if (query != null) {
59: args += "configuration=" + query;
60: }
61: query = (String) params.get("TK_PAR[showlog]");
62: if (query != null) {
63: args += (args.length() == 0 ? "showlog=" + query
64: : " showlog=" + query);
65: }
66: String docroot = httpInf.getDocumentRoot();
67:
68: out.start("Stager", LoginFactory.getInstance()
69: .getLogin(evt.getRemoteUser()).getName());
70:
71: // starting process
72: ProcessStarter ps = new ProcessStarter(out, log);
73: success = ps.start("webman.stager.SiteTransmitter",
74: args, ProcessStarter.getWMClasspath(docroot));
75: } catch (Exception e) {
76: out.println(e.toString());
77: log.println(e);
78: }
79:
80: out.end(success);
81: out.close();
82: log.close();
83: } catch (Throwable e) {
84: // TO DO : Analyze Exception !
85: throw WebmanExceptionHandler.getException(e);
86: }
87: }
88:
89: public boolean isHandler(TKEvent evt) {
90: return evt.getName().equalsIgnoreCase("GR_TRANSMIT");
91: }
92:
93: }
|