1 package de.webman.generator.eventhandler; 2 3 import java.io.*; 4 import java.net.*; 5 6 import com.teamkonzept.lib.*; 7 import com.teamkonzept.web.TKEvent; 8 import com.teamkonzept.web.TKHttpInterface; 9 import com.teamkonzept.webman.ProcessStarter; 10 import de.webman.acl.LoginFactory; 11 import com.teamkonzept.webman.mainint.WebmanExceptionHandler; 12 import com.teamkonzept.webman.WebManEvent; 13 import com.teamkonzept.webman.mainint.events.*; 14 import de.webman.util.log4j.WebmanCategory; 15 16 26 public class GRGenerateHandler extends DefaultEventHandler implements ParameterTypes 27 { 28 private static GRGenerateHandler instance = new GRGenerateHandler(); 29 30 31 private static boolean generationInProgress = false; 32 33 boolean usePushlet = false; 34 35 private GRGenerateHandler() 36 { 37 } 38 39 public static GRGenerateHandler getInstance() 40 { 41 return instance; 42 } 43 44 public static boolean isGenerationInProgress() 45 { 46 return generationInProgress; 47 } 48 49 public void handleEvent(TKEvent evt) throws TKException 50 { 51 try 52 { 53 WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(), GENERATOR); 54 synchronized (this) { 56 if (!generationInProgress) 57 generationInProgress = true; 58 else 59 throw new TKUserException("Generation in Progress", GENERATION_IN_PROGRESS, USER_SEVERITY, false, null); 60 } 61 TKHttpInterface httpInf = evt.getHttpInterface(); 62 63 GRHTMLWrapper out = new GRHTMLWrapper(new PrintWriter(httpInf.getOutputStream()), httpInf.getContextPath()); 64 PrintWriter log = new PrintWriter(httpInf.getLogStream()); 65 66 out.start("Generator", 67 LoginFactory.getInstance().getLogin(evt.getRemoteUser()).getName()); 68 String siteNodeID = evt.getParameter(PARAMETER, "SITE_NODE_ID"); 70 String instanceID = evt.getParameter(PARAMETER, "INSTANCE_ID"); 71 String partialParam = ""; 72 String contentInstance=" instance=" + instanceID; 73 if (evt.getName().equalsIgnoreCase("GR_GENERATE_CE")) 74 { 75 partialParam += contentInstance; } 77 if (evt.getName().equals("GR_GENERATE_PROD")) 78 { 79 partialParam += " ignoreWorkflow"; 81 } 82 String user = " user="; 83 if (evt.getName().equalsIgnoreCase("GR_GENERATE_RED")) 84 { 85 user += WebmanCategory.EDITOR; 87 } 88 else 89 user += WebmanCategory.ALL; 90 partialParam += user; 91 if (siteNodeID != null && !siteNodeID.equals("")) 92 partialParam = " id=" + siteNodeID; 93 String ref = evt.getParameter(PARAMETER, "REF"); 94 if (ref != null && !ref.equals("")) 95 partialParam = " refs=" + ref; 96 boolean success = false; 97 ProcessStarter ps = new ProcessStarter(out, log); 98 String gendir = null; 99 try 101 { 102 PropertyManager man = PropertyManager.getPropertyManager("GENERATION"); 103 gendir = man.getValue("GENDIR"); 104 } 105 catch (Throwable t) 106 { 107 gendir = null; } 110 try 111 { 112 if (gendir == null) 113 gendir = httpInf.getDocumentRoot() ; 114 success = ps.start("WebManGen", 115 httpInf.getDocumentRoot()+ partialParam + " gendir=" + gendir, 116 ProcessStarter.getWMClasspath(httpInf.getDocumentRoot())); 117 } 118 catch (Exception e) 119 { 120 out.println(e); 121 log.println(e); 122 } 123 124 out.end(success); 125 out.close(); 126 log.close(); 127 } 128 catch (Throwable e) 129 { 130 throw WebmanExceptionHandler.getException(e); 132 } 133 finally 134 { 135 generationInProgress = false; 136 } 137 } 138 139 public boolean isHandler(TKEvent evt) 140 { 141 return evt.getName().equalsIgnoreCase("GR_GENERATE") || evt.getName().equalsIgnoreCase("GR_GENERATE_PROD") 142 || evt.getName().equalsIgnoreCase("GR_GENERATE_RED") || evt.getName().equals("GR_GENERATE_CE"); 143 } 144 145 } 146 | Popular Tags |