1 19 20 package org.netbeans.modules.tomcat5; 21 22 23 import java.io.File ; 24 import java.io.IOException ; 25 import org.netbeans.modules.tomcat5.config.gen.Context; 26 import org.netbeans.modules.tomcat5.config.gen.Engine; 27 import org.netbeans.modules.tomcat5.config.gen.Host; 28 import org.netbeans.modules.tomcat5.config.gen.SContext; 29 import org.netbeans.modules.tomcat5.config.gen.Server; 30 import org.netbeans.modules.tomcat5.config.gen.Service; 31 import org.openide.ErrorManager; 32 33 34 40 public class TomcatModuleConfig { 41 private static final String CONTEXT_XML_PATH = "/META-INF/context.xml"; 43 private File contextXml; 44 private File serverXml; 45 46 private long timestampContextXML; 47 private long timestampServerXML; 48 private String path; 49 50 51 private boolean hasLogger; 53 private String loggerClassName; 54 private String loggerDir; 55 private String loggerPrefix; 56 private String loggerSuffix; 57 private boolean loggerTimestamp; 58 59 66 public TomcatModuleConfig(String docBase, String path, String serverXmlPath) { 67 if (path.equals("/")) { 68 this.path = ""; } else { 70 this.path = path; 71 } 72 contextXml = new File (docBase + CONTEXT_XML_PATH); 73 serverXml = new File (serverXmlPath); 74 refresh(); 75 } 76 77 81 private Context getContext() { 82 try { 83 timestampContextXML = contextXml.lastModified(); 84 Context ctx = Context.createGraph(contextXml); 85 return ctx; 86 } catch (IOException ioe) { 87 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 88 return null; 89 } catch (RuntimeException e) { 90 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 91 return null; 92 } 93 } 94 95 99 private SContext getSContext() { 100 try { 101 timestampServerXML = serverXml.lastModified(); 102 Server server = Server.createGraph(serverXml); 103 104 Service[] service = server.getService(); 107 if (service.length > 0) { 108 Engine engine = service[0].getEngine(); 109 if (engine != null) { 110 Host[] host = engine.getHost(); 111 if (host.length > 0) { 112 SContext[] sContext = host[0].getSContext(); 113 for (int i = 0; i < sContext.length; i++) { 114 if (sContext[i].getAttributeValue("path").equals(path)) { return sContext[i]; 116 } 117 } 118 } 119 } 120 } 121 122 } catch (IOException ioe) { 123 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 124 } 125 return null; 126 } 127 128 135 public boolean hasLogger() { 136 return hasLogger; 137 } 138 139 144 public String loggerClassName() { 145 return loggerClassName; 146 } 147 148 153 public String loggerDir() { 154 return loggerDir; 155 } 156 157 162 public String loggerPrefix() { 163 return loggerPrefix; 164 } 165 166 171 public String loggerSuffix() { 172 return loggerSuffix; 173 } 174 175 182 public boolean loggerTimestamp() { 183 return loggerTimestamp; 184 } 185 186 189 public void refresh() { 190 if (contextXml.exists()) { 191 long newTimestamp = contextXml.lastModified(); 192 if (newTimestamp > timestampContextXML) { 193 timestampContextXML = newTimestamp; 194 Context ctx = getContext(); 195 if (ctx != null) { 196 hasLogger = ctx.isLogger(); 197 if (hasLogger) { 198 loggerClassName = ctx.getLoggerClassName(); 199 loggerDir = ctx.getLoggerDirectory(); 200 loggerPrefix = ctx.getLoggerPrefix(); 201 loggerSuffix = ctx.getLoggerSuffix(); 202 loggerTimestamp = Boolean.valueOf(ctx.getLoggerTimestamp()).booleanValue(); 203 return; 204 } 205 } 206 } 207 } else if (serverXml.exists()) { 208 long newTimestamp = serverXml.lastModified(); 209 if (newTimestamp > timestampServerXML) { 210 timestampServerXML = newTimestamp; 211 SContext sCtx = getSContext(); 212 if (sCtx != null) { 213 hasLogger = sCtx.isLogger(); 214 if (hasLogger) { 215 loggerClassName = sCtx.getAttributeValue(SContext.LOGGER, "className"); loggerDir = sCtx.getAttributeValue(SContext.LOGGER, "directory"); loggerPrefix = sCtx.getAttributeValue(SContext.LOGGER, "prefix"); loggerSuffix = sCtx.getAttributeValue(SContext.LOGGER, "suffix"); String timestamp = sCtx.getAttributeValue(SContext.LOGGER, "timestamp"); loggerTimestamp = Boolean.valueOf(timestamp).booleanValue(); 221 } 222 } 223 } 224 } else { 225 hasLogger = false; } 227 } 228 } 229 | Popular Tags |