KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tomcat5 > util > TomcatProperties


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tomcat5.util;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.FilenameFilter JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.net.MalformedURLException JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.logging.Level JavaDoc;
33 import java.util.logging.Logger JavaDoc;
34 import org.netbeans.api.java.platform.JavaPlatform;
35 import org.netbeans.api.java.platform.JavaPlatformManager;
36 import org.netbeans.api.java.platform.Specification;
37 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
38 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
39 import org.netbeans.modules.tomcat5.TomcatFactory;
40 import org.netbeans.modules.tomcat5.TomcatManager;
41 import org.netbeans.modules.tomcat5.TomcatManager.TomcatVersion;
42 import org.netbeans.modules.tomcat5.customizer.CustomizerSupport;
43 import org.openide.ErrorManager;
44 import org.openide.filesystems.FileLock;
45 import org.openide.filesystems.FileObject;
46 import org.openide.filesystems.FileSystem;
47 import org.openide.filesystems.FileUtil;
48 import org.openide.filesystems.Repository;
49 import org.openide.modules.InstalledFileLocator;
50 import org.openide.util.NbBundle;
51 import org.openide.util.Utilities;
52 /**
53  * Utility class that makes it easier to access and set Tomcat instance properties.
54  *
55  * @author sherold
56  */

57 public class TomcatProperties {
58     
59     private static final Logger JavaDoc LOGGER = Logger.getLogger(TomcatProperties.class.getName());
60     
61     /** Java platform property which is used as a java platform ID */
62     public static final String JavaDoc PLAT_PROP_ANT_NAME = "platform.ant.name"; //NOI18N
63

64     public static final String JavaDoc DEBUG_TYPE_SOCKET = "SEL_debuggingType_socket"; // NOI18N
65
public static final String JavaDoc DEBUG_TYPE_SHARED = "SEL_debuggingType_shared"; // NOI18N
66

67     public static final String JavaDoc BUNDLED_TOMCAT_SETTING = "J2EE/BundledTomcat/Setting"; // NOI18N
68

69     // properties
70
private static final String JavaDoc PROP_URL = InstanceProperties.URL_ATTR;
71     private static final String JavaDoc PROP_USERNAME = InstanceProperties.USERNAME_ATTR;
72     private static final String JavaDoc PROP_PASSWORD = InstanceProperties.PASSWORD_ATTR;
73     public static final String JavaDoc PROP_SERVER_PORT = InstanceProperties.HTTP_PORT_NUMBER;
74     private static final String JavaDoc PROP_DISPLAY_NAME = InstanceProperties.DISPLAY_NAME_ATTR;
75     public static final String JavaDoc PROP_SHUTDOWN = "admin_port"; //NOI18N
76
public static final String JavaDoc PROP_MONITOR = "monitor_enabled"; // NOI18N
77
public static final String JavaDoc PROP_PROXY_ENABLED = "proxy_enabled"; // NOI18N
78
private static final String JavaDoc PROP_CUSTOM_SCRIPT = "custom_script_enabled"; // NOI18N
79
private static final String JavaDoc PROP_SCRIPT_PATH = "script_path"; // NOI18N
80
private static final String JavaDoc PROP_FORCE_STOP = "forceStopOption"; // NOI18N
81
private static final String JavaDoc PROP_DEBUG_TYPE = "debug_type"; // NOI18N
82
private static final String JavaDoc PROP_DEBUG_PORT = "debugger_port"; // NOI18N
83
private static final String JavaDoc PROP_SHARED_MEM = "shared_memory"; // NOI18N
84
private static final String JavaDoc PROP_JAVA_PLATFORM = "java_platform"; // NOI18N
85
private static final String JavaDoc PROP_JAVA_OPTS = "java_opts"; // NOI18N
86
private static final String JavaDoc PROP_SEC_MANAGER = "securityStartupOption"; // NOI18N
87
private static final String JavaDoc PROP_SOURCES = "sources"; // NOI18N
88
private static final String JavaDoc PROP_JAVADOCS = "javadocs"; // NOI18N
89
private static final String JavaDoc PROP_OPEN_LOG = "openContextLogOnRun"; // NOI18N
90
/** server.xml check timestamp */
91     private static final String JavaDoc PROP_TIMESTAMP = "timestamp"; // NOI18N
92
private static final String JavaDoc PROP_HOST = "host"; // NOI18N
93
public static final String JavaDoc PROP_RUNNING_CHECK_TIMEOUT = "runningCheckTimeout"; // NOI18N
94
private static final String JavaDoc PROP_INSTANCE_ID = "instance_id"; // NOI18N
95

96     
97     // default values
98
private static final boolean DEF_VALUE_SEC_MANAGER = false;
99     private static final boolean DEF_VALUE_CUSTOM_SCRIPT = false;
100     private static final String JavaDoc DEF_VALUE_SCRIPT_PATH = ""; // NOI18N
101
private static final boolean DEF_VALUE_FORCE_STOP = false;
102     private static final String JavaDoc DEF_VALUE_JAVA_OPTS = ""; // NOI18N
103
private static final String JavaDoc DEF_VALUE_DEBUG_TYPE = Utilities.isWindows() ? DEBUG_TYPE_SHARED
104                                                                               : DEBUG_TYPE_SOCKET;
105     private static final boolean DEF_VALUE_MONITOR = true;
106     private static final boolean DEF_VALUE_PROXY_ENABLED = true;
107     private static final int DEF_VALUE_DEBUG_PORT = 11555;
108     private static final int DEF_VALUE_SERVER_PORT = 8080;
109     public static final int DEF_VALUE_SHUTDOWN_PORT = 8005;
110     
111     public static final int DEF_VALUE_BUNDLED_SERVER_PORT = 8084;
112     public static final int DEF_VALUE_BUNDLED_SHUTDOWN_PORT = 8025;
113     
114     private static final String JavaDoc DEF_VALUE_SHARED_MEM = "tomcat_shared_memory_id"; // NOI18N
115
private static final boolean DEF_VALUE_OPEN_LOG = true;
116     private static final String JavaDoc DEF_VALUE_HOST = "localhost"; // NOI18N
117
public static final int DEF_VALUE_RUNNING_CHECK_TIMEOUT = 2000;
118     private static final String JavaDoc DEF_VALUE_DISPLAY_NAME =
119             NbBundle.getMessage(TomcatProperties.class, "LBL_DefaultDisplayName");
120     
121     private TomcatManager tm;
122     private InstanceProperties ip;
123     private File JavaDoc homeDir;
124     private File JavaDoc baseDir;
125     
126     /** Creates a new instance of TomcatProperties */
127     public TomcatProperties(TomcatManager tm) throws IllegalArgumentException JavaDoc {
128         this.tm = tm;
129         this.ip = tm.getInstanceProperties();
130         String JavaDoc catalinaHome = null;
131         String JavaDoc catalinaBase = null;
132         String JavaDoc uri = ip.getProperty(PROP_URL); // NOI18N
133
final String JavaDoc home = "home="; // NOI18N
134
final String JavaDoc base = ":base="; // NOI18N
135
final String JavaDoc uriString = "http://"; // NOI18N
136
int uriOffset = uri.indexOf (uriString);
137         int homeOffset = uri.indexOf (home) + home.length ();
138         int baseOffset = uri.indexOf (base, homeOffset);
139         if (homeOffset >= home.length ()) {
140             int homeEnd = baseOffset > 0 ? baseOffset : (uriOffset > 0 ? uriOffset - 1 : uri.length ());
141             int baseEnd = uriOffset > 0 ? uriOffset - 1 : uri.length ();
142             catalinaHome= uri.substring (homeOffset, homeEnd);
143             if (baseOffset > 0) {
144                 catalinaBase = uri.substring (baseOffset + base.length (), baseEnd);
145             }
146             // Bundled Tomcat home and base dirs can be specified as attributes
147
// specified in BUNDLED_TOMCAT_SETTING file. Tomcat manager URL can
148
// then look like "tomcat:home=$bundled_home:base=$bundled_base" and
149
// therefore remains valid even if Tomcat version changes. (issue# 40659)
150
if (catalinaHome.length() > 0 && catalinaHome.charAt(0) == '$') {
151                 FileSystem fs = Repository.getDefault().getDefaultFileSystem();
152                 FileObject fo = fs.findResource(BUNDLED_TOMCAT_SETTING);
153                 if (fo != null) {
154                     catalinaHome = fo.getAttribute(catalinaHome.substring(1)).toString();
155                     if (catalinaBase != null && catalinaBase.length() > 0
156                         && catalinaBase.charAt(0) == '$') {
157                         catalinaBase = fo.getAttribute(catalinaBase.substring(1)).toString();
158                     }
159                 }
160             }
161         }
162         if (catalinaHome == null) {
163             throw new IllegalArgumentException JavaDoc("CATALINA_HOME must not be null."); // NOI18N
164
}
165         homeDir = new File JavaDoc(catalinaHome);
166         if (!homeDir.isAbsolute ()) {
167             InstalledFileLocator ifl = InstalledFileLocator.getDefault();
168             homeDir = ifl.locate(catalinaHome, null, false);
169         }
170         if (!homeDir.exists()) {
171             throw new IllegalArgumentException JavaDoc("CATALINA_HOME directory does not exist."); // NOI18N
172
}
173         if (catalinaBase != null) {
174             baseDir = new File JavaDoc(catalinaBase);
175             if (!baseDir.isAbsolute ()) {
176                 InstalledFileLocator ifl = InstalledFileLocator.getDefault();
177                 baseDir = ifl.locate(catalinaBase, null, false);
178                 if (baseDir == null) {
179                     baseDir = new File JavaDoc(System.getProperty("netbeans.user"), catalinaBase); // NOI18N
180
}
181             }
182         }
183         
184 // //parse the old format for backward compatibility
185
// if (uriOffset > 0) {
186
// String theUri = uri.substring (uriOffset + uriString.length ());
187
// int portIndex = theUri.indexOf (':');
188
// String host = theUri.substring (0, portIndex - 1);
189
// setHost (host);
190
// //System.out.println("host:"+host);
191
// int portEnd = theUri.indexOf ('/');
192
// portEnd = portEnd > 0 ? portEnd : theUri.length ();
193
// String port = theUri.substring (portIndex, portEnd - 1);
194
// //System.out.println("port:"+port);
195
// try {
196
// setServerPort (Integer.valueOf (port));
197
// } catch (NumberFormatException nef) {
198
// org.openide.ErrorManager.getDefault ().log (nef.getLocalizedMessage ());
199
// }
200
// }
201
ip.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
202             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
203                 String JavaDoc name = evt.getPropertyName();
204                 if (PROP_SERVER_PORT.equals(name) || PROP_USERNAME.equals(name)
205                     || PROP_PASSWORD.equals(name)) {
206                     // update Ant deployment properties file if it exists
207
try {
208                         storeAntDeploymentProperties(getAntDeploymentPropertiesFile(), false);
209                     } catch(IOException JavaDoc ioe) {
210                         ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
211                     }
212                 }
213             }
214         });
215     }
216     
217     /**
218      * Stores the Ant deployment properties in the specified file.
219      * @param create if false the deployment properties file won't be created if
220      * it does not exist.
221      * @throws IOException if a problem occurs.
222      */

223     public void storeAntDeploymentProperties(File JavaDoc file, boolean create) throws IOException JavaDoc {
224         if (!create && !file.exists()) {
225             return;
226         }
227         EditableProperties antProps = new EditableProperties();
228         antProps.setProperty("tomcat.home", homeDir.getAbsolutePath()); // NOI18N
229
antProps.setProperty("tomcat.url", getWebUrl()); // NOI18N
230
antProps.setProperty("tomcat.username", getUsername()); // NOI18N
231
antProps.setProperty("tomcat.password", getPassword()); // NOI18N
232
file.createNewFile();
233         FileObject fo = FileUtil.toFileObject(file);
234         FileLock lock = fo.lock();
235         try {
236             OutputStream JavaDoc os = fo.getOutputStream(lock);
237             try {
238                 antProps.store(os);
239             } finally {
240                 os.close();
241             }
242         } finally {
243             lock.releaseLock();
244         }
245     }
246     
247     /** Returns file the Ant deployment properties are stored in. */
248     public File JavaDoc getAntDeploymentPropertiesFile() {
249         return new File JavaDoc(System.getProperty("netbeans.user"), getInstanceID() + ".properties"); // NOI18N
250
}
251     
252     /**
253      * Unique instance identifier used to differentiate different Tomcat instances
254      * in a human-readable form, unlike InstanceProperties.URL_ATTR.
255      */

256     private String JavaDoc getInstanceID() {
257         String JavaDoc name = ip.getProperty(PROP_INSTANCE_ID);
258         if (name != null) {
259             return name;
260         }
261         // generate unique tomcat instance identifier (e.g. tomcat55, tomcat55_1, ...
262
// for Tomcat 5.5.x and tomcat50, tomcat50_1... for Tomcat 5.0.x)
263
String JavaDoc prefix;
264         String JavaDoc serverID;
265         switch (tm.getTomcatVersion()) {
266             case TOMCAT_60:
267                 prefix = "tomcat60"; // NIO18N
268
serverID = TomcatFactory.SERVER_ID_60;
269                 break;
270             case TOMCAT_55:
271                 prefix = "tomcat55"; // NIO18N
272
serverID = TomcatFactory.SERVER_ID_55;
273                 break;
274             case TOMCAT_50:
275             default:
276                 prefix = "tomcat50"; // NIO18N
277
serverID = TomcatFactory.SERVER_ID_50;
278         }
279         String JavaDoc[] instanceURLs = Deployment.getDefault().getInstancesOfServer(serverID);
280         for (int i = 0; name == null; i++) {
281             if (i == 0) {
282                 name = prefix;
283             } else {
284                 name = prefix + "_" + i; // NOI18N
285
}
286             for (String JavaDoc url: instanceURLs) {
287                 if (!tm.getUri().equals(url)) {
288                     InstanceProperties ip = InstanceProperties.getInstanceProperties(url);
289                     if (ip != null) {
290                         String JavaDoc anotherName = ip.getProperty(PROP_INSTANCE_ID);
291                         if (name.equals(anotherName)) {
292                             name = null;
293                             break;
294                         }
295                     }
296                 }
297             }
298         }
299         ip.setProperty(PROP_INSTANCE_ID, name);
300         return name;
301     }
302     
303     /** Returns server web url e.g. http://localhost:8080 */
304     public String JavaDoc getWebUrl() {
305         return "http://" + getHost() + ":" + getServerPort(); // NOI18N
306
}
307     
308     /** Return CATALINA_HOME directory.*/
309     public File JavaDoc getCatalinaHome() {
310         return homeDir;
311     }
312     
313     /** Return CATALINA_BASE directory or null if not defined. */
314     public File JavaDoc getCatalinaBase() {
315         return baseDir;
316     }
317     
318     /** Return CATALINA_BASE directory if defined, CATALINA_HOME otherwise. */
319     public File JavaDoc getCatalinaDir() {
320         return baseDir == null ? homeDir : baseDir;
321     }
322     
323     public String JavaDoc getUsername() {
324         String JavaDoc val = ip.getProperty(PROP_USERNAME);
325         return val != null ? val : ""; // NOI18N
326
}
327     
328     public void setUsername(String JavaDoc value) {
329         ip.setProperty(PROP_USERNAME, value);
330     }
331     
332     public String JavaDoc getPassword() {
333         String JavaDoc val = ip.getProperty(PROP_PASSWORD);
334         return val != null ? val : ""; // NOI18N
335
}
336     
337     public void setPassword(String JavaDoc value) {
338         ip.setProperty(PROP_PASSWORD, value);
339     }
340     
341     public JavaPlatform getJavaPlatform() {
342         String JavaDoc currentJvm = ip.getProperty(PROP_JAVA_PLATFORM);
343         JavaPlatformManager jpm = JavaPlatformManager.getDefault();
344         JavaPlatform[] installedPlatforms = jpm.getPlatforms(null, new Specification("J2SE", null)); // NOI18N
345
for (int i = 0; i < installedPlatforms.length; i++) {
346             String JavaDoc platformName = (String JavaDoc)installedPlatforms[i].getProperties().get(PLAT_PROP_ANT_NAME);
347             if (platformName != null && platformName.equals(currentJvm)) {
348                 return installedPlatforms[i];
349             }
350         }
351         // return default platform if none was set
352
return jpm.getDefaultPlatform();
353     }
354     
355     public void setJavaPlatform(JavaPlatform javaPlatform) {
356         ip.setProperty(PROP_JAVA_PLATFORM, (String JavaDoc)javaPlatform.getProperties().get(PLAT_PROP_ANT_NAME));
357     }
358     
359     public String JavaDoc getJavaOpts() {
360         String JavaDoc val = ip.getProperty(PROP_JAVA_OPTS);
361         return val != null ? val
362                            : DEF_VALUE_JAVA_OPTS;
363     }
364     
365     public void setJavaOpts(String JavaDoc javaOpts) {
366         ip.setProperty(PROP_JAVA_OPTS, javaOpts);
367     }
368     
369     public boolean getSecManager() {
370         String JavaDoc val = ip.getProperty(PROP_SEC_MANAGER);
371         return val != null ? Boolean.valueOf(val).booleanValue()
372                            : DEF_VALUE_SEC_MANAGER;
373     }
374     
375     public void setSecManager(boolean enabled) {
376         ip.setProperty(PROP_SEC_MANAGER, Boolean.toString(enabled));
377     }
378     
379     
380     public boolean getCustomScript() {
381         String JavaDoc val = ip.getProperty(PROP_CUSTOM_SCRIPT);
382         return val != null ? Boolean.valueOf(val).booleanValue()
383                            : DEF_VALUE_CUSTOM_SCRIPT;
384     }
385     
386     public void setCustomScript(boolean enabled) {
387         ip.setProperty(PROP_CUSTOM_SCRIPT, Boolean.toString(enabled));
388     }
389     
390     public String JavaDoc getScriptPath() {
391         String JavaDoc val = ip.getProperty(PROP_SCRIPT_PATH);
392         return val != null ? val
393                            : DEF_VALUE_SCRIPT_PATH;
394     }
395     
396     public void setScriptPath(String JavaDoc path) {
397         ip.setProperty(PROP_SCRIPT_PATH, path);
398     }
399     
400     public boolean getForceStop() {
401         if (Utilities.isWindows()) {
402             return false;
403         }
404         String JavaDoc val = ip.getProperty(PROP_FORCE_STOP);
405         return val != null ? Boolean.valueOf(val).booleanValue()
406                            : DEF_VALUE_FORCE_STOP;
407     }
408     
409     public void setForceStop(boolean enabled) {
410         ip.setProperty(PROP_FORCE_STOP, Boolean.toString(enabled));
411     }
412     
413     public String JavaDoc getDebugType() {
414         String JavaDoc val = ip.getProperty(PROP_DEBUG_TYPE);
415         if ((DEBUG_TYPE_SHARED.equalsIgnoreCase(val) && Utilities.isWindows())
416                 || DEBUG_TYPE_SOCKET.equalsIgnoreCase(val)) {
417             return val;
418         }
419         return DEF_VALUE_DEBUG_TYPE;
420     }
421     
422     public void setDebugType(String JavaDoc type) {
423         ip.setProperty(PROP_DEBUG_TYPE, type);
424     }
425     
426     public boolean getMonitor() {
427         String JavaDoc val = ip.getProperty(PROP_MONITOR);
428         return val != null ? Boolean.valueOf(val).booleanValue()
429                            : DEF_VALUE_MONITOR;
430     }
431     
432     public void setMonitor(boolean enabled) {
433         ip.setProperty(PROP_MONITOR, Boolean.toString(enabled));
434     }
435     
436     public boolean getProxyEnabled() {
437         String JavaDoc val = ip.getProperty(PROP_PROXY_ENABLED);
438         return val != null ? Boolean.valueOf(val).booleanValue()
439                            : DEF_VALUE_PROXY_ENABLED;
440     }
441     
442     public void setProxyEnabled(boolean enabled) {
443         ip.setProperty(PROP_PROXY_ENABLED, Boolean.toString(enabled));
444     }
445     
446     public int getDebugPort() {
447         String JavaDoc val = ip.getProperty(PROP_DEBUG_PORT);
448                 
449         if (val != null) {
450             try {
451                 return Integer.parseInt(val);
452             } catch (NumberFormatException JavaDoc nfe) {
453                 TomcatManager.ERR.notify(ErrorManager.INFORMATIONAL, nfe);
454             }
455         }
456         return DEF_VALUE_DEBUG_PORT;
457     }
458     
459     public void setDebugPort(int port) {
460         ip.setProperty(PROP_DEBUG_PORT, Integer.toString(port));
461     }
462     
463     
464     public int getServerPort() {
465         String JavaDoc val = ip.getProperty(PROP_SERVER_PORT);
466         if (val != null) {
467             try {
468                 int port = Integer.parseInt(val);
469                 if (port >= 0 && port <= 65535) {
470                     return port;
471                 }
472             } catch (NumberFormatException JavaDoc nfe) {
473                 TomcatManager.ERR.notify(ErrorManager.INFORMATIONAL, nfe);
474             }
475         }
476         return tm.isBundledTomcat() ? DEF_VALUE_BUNDLED_SERVER_PORT : DEF_VALUE_SERVER_PORT;
477     }
478     
479     /** this needs to be kept in sync with value in the server.xml conf file */
480     public void setServerPort(int port) {
481         ip.setProperty(PROP_SERVER_PORT, Integer.toString(port));
482     }
483     
484     public int getShutdownPort() {
485         String JavaDoc val = ip.getProperty(PROP_SHUTDOWN);
486         if (val != null) {
487             try {
488                 int port = Integer.parseInt(val);
489                 if (port >= 0 && port <= 65535) {
490                     return port;
491                 }
492             } catch (NumberFormatException JavaDoc nfe) {
493                 TomcatManager.ERR.notify(ErrorManager.INFORMATIONAL, nfe);
494             }
495         }
496         return tm.isBundledTomcat() ? DEF_VALUE_BUNDLED_SHUTDOWN_PORT : DEF_VALUE_SHUTDOWN_PORT;
497     }
498     
499     /** this needs to be kept in sync with value in the server.xml conf file */
500     public void setShutdownPort(int port) {
501         ip.setProperty(PROP_SHUTDOWN, Integer.toString(port));
502     }
503     
504     public String JavaDoc getSharedMem() {
505         String JavaDoc val = ip.getProperty(PROP_SHARED_MEM);
506         return val != null && val.length() > 0 ? val
507                                                : DEF_VALUE_SHARED_MEM;
508     }
509     
510     public void setSharedMem(String JavaDoc val) {
511         ip.setProperty(PROP_SHARED_MEM, val);
512     }
513     
514     public List JavaDoc/*<URL>*/ getClasses() {
515         String JavaDoc[] nbFilter = new String JavaDoc[] {
516             "httpmonitor", "schema2beans"
517         };
518         
519         String JavaDoc[] implFilter = new String JavaDoc[] {
520             "-impl.jar"
521         };
522         
523         // tomcat libs
524
List JavaDoc retValue = listUrls(new File JavaDoc(homeDir, tm.libFolder()), nbFilter); // NOI18N
525

526         if (tm.isTomcat60()) {
527             try {
528                 retValue.add(new File JavaDoc(homeDir, "bin/tomcat-juli.jar").toURI().toURL()); // NOI18N
529
} catch (MalformedURLException JavaDoc e) {
530                 LOGGER.log(Level.WARNING, "$CATALINA_HOME/bin/tomcat-juli.jar not found", e); // NOI18N
531
}
532         }
533
534         // jwsdp libs
535
retValue.addAll(listUrls(new File JavaDoc(homeDir, "jaxws/lib"), implFilter)); // NOI18N
536
retValue.addAll(listUrls(new File JavaDoc(homeDir, "jaxb/lib"), implFilter)); // NOI18N
537
retValue.addAll(listUrls(new File JavaDoc(homeDir, "jwsdp-shared/lib"), implFilter)); // NOI18N
538
retValue.addAll(listUrls(new File JavaDoc(homeDir, "jaxp/lib"), implFilter)); // NOI18N
539
retValue.addAll(listUrls(new File JavaDoc(homeDir, "jaxrpc/lib"), implFilter)); // NOI18N
540
retValue.addAll(listUrls(new File JavaDoc(homeDir, "jaxr/lib"), implFilter)); // NOI18N
541
retValue.addAll(listUrls(new File JavaDoc(homeDir, "saaj/lib"), implFilter)); // NOI18N
542
retValue.addAll(listUrls(new File JavaDoc(homeDir, "sjsxp/lib"), implFilter)); // NOI18N
543

544         // wsit
545
retValue.addAll(listUrls(new File JavaDoc(homeDir, "shared/lib"), implFilter)); // NOI18N
546

547         // other
548
retValue.addAll(listUrls(new File JavaDoc(homeDir, "jstl/lib"), implFilter)); // NOI18N
549
retValue.addAll(listUrls(new File JavaDoc(baseDir, "shared/lib"), nbFilter)); // NOI18N
550
return retValue;
551     }
552     
553     public List JavaDoc/*<URL>*/ getSources() {
554         String JavaDoc path = ip.getProperty(PROP_SOURCES);
555         if (path == null) {
556             return new ArrayList JavaDoc();
557         }
558         return CustomizerSupport.tokenizePath(path);
559     }
560                                                                                                                                                                            
561     public void setSources(List JavaDoc/*<URL>*/ path) {
562         ip.setProperty(PROP_SOURCES, CustomizerSupport.buildPath(path));
563         tm.getTomcatPlatform().notifyLibrariesChanged();
564     }
565     
566     public List JavaDoc/*<URL>*/ getJavadocs() {
567         String JavaDoc path = ip.getProperty(PROP_JAVADOCS);
568         if (path == null) {
569             ArrayList JavaDoc list = new ArrayList JavaDoc();
570             try {
571                 // tomcat docs
572
File JavaDoc jspApiDoc = new File JavaDoc(homeDir, "webapps/tomcat-docs/jspapi"); // NOI18N
573
File JavaDoc servletApiDoc = new File JavaDoc(homeDir, "webapps/tomcat-docs/servletapi"); // NOI18N
574
if (jspApiDoc.exists() && servletApiDoc.exists()) {
575                     list.add(Utils.fileToUrl(jspApiDoc));
576                     list.add(Utils.fileToUrl(servletApiDoc));
577                 } else {
578                     File JavaDoc j2eeDoc = InstalledFileLocator.getDefault().locate("docs/javaee5-doc-api.zip", null, false); // NOI18N
579
if (j2eeDoc != null) {
580                         list.add(Utils.fileToUrl(j2eeDoc));
581                     }
582                 }
583                 // jwsdp docs
584
File JavaDoc docs = new File JavaDoc(homeDir, "docs/api"); // NOI18N
585
if (docs.exists()) {
586                     list.add(Utils.fileToUrl(docs));
587                 }
588             } catch (MalformedURLException JavaDoc e) {
589                 ErrorManager.getDefault().notify(e);
590             }
591             return list;
592         }
593         return CustomizerSupport.tokenizePath(path);
594     }
595                                                                                                                                                                            
596     public void setJavadocs(List JavaDoc/*<URL>*/ path) {
597         ip.setProperty(PROP_JAVADOCS, CustomizerSupport.buildPath(path));
598         tm.getTomcatPlatform().notifyLibrariesChanged();
599     }
600     
601     public void setOpenContextLogOnRun(boolean val) {
602         ip.setProperty(PROP_OPEN_LOG, Boolean.valueOf(val).toString());
603     }
604     
605     public boolean getOpenContextLogOnRun() {
606         Object JavaDoc val = ip.getProperty(PROP_OPEN_LOG);
607         if (val != null) {
608             return Boolean.valueOf(val.toString()).booleanValue();
609         }
610         return DEF_VALUE_OPEN_LOG;
611     }
612     
613         
614     public void setTimestamp(long timestamp) {
615         ip.setProperty(PROP_TIMESTAMP, Long.toString(timestamp));
616     }
617     
618     /** Return last server.xml check timestamp, or -1 if not set */
619     public long getTimestamp() {
620         String JavaDoc val = ip.getProperty(PROP_TIMESTAMP);
621         if (val != null) {
622             try {
623                 return Long.parseLong(val);
624             } catch (NumberFormatException JavaDoc nfe) {
625                 TomcatManager.ERR.notify(ErrorManager.INFORMATIONAL, nfe);
626             }
627         }
628         return -1;
629     }
630     
631     /**
632      * Return server.xml file from the catalina base folder if the base folder is used
633      * or from the catalina home folder otherwise.
634      * <p>
635      * <b>BEWARE</b>: If the catalina base folder is used but has not bee generated yet,
636      * the server.xml file from the catalina home folder will be returned.
637      * </p>
638      */

639     public File JavaDoc getServerXml() {
640         String JavaDoc confServerXml = "conf/server.xml"; // NIO18N
641
File JavaDoc serverXml = null;
642         if (baseDir != null) {
643             serverXml = new File JavaDoc(baseDir, confServerXml);
644         }
645         if (serverXml == null || !serverXml.exists()) {
646             serverXml = new File JavaDoc(getCatalinaHome(), confServerXml);
647         }
648         return serverXml;
649     }
650     
651     public String JavaDoc getHost () {
652         String JavaDoc val = ip.getProperty(PROP_HOST);
653         return val != null ? val : DEF_VALUE_HOST;
654     }
655     
656     public int getRunningCheckTimeout() {
657         String JavaDoc val = ip.getProperty(PROP_RUNNING_CHECK_TIMEOUT);
658         if (val != null) {
659             try {
660                 return Integer.parseInt(val);
661             } catch (NumberFormatException JavaDoc nfe) {
662                 TomcatManager.ERR.notify(ErrorManager.INFORMATIONAL, nfe);
663             }
664         }
665         return DEF_VALUE_RUNNING_CHECK_TIMEOUT;
666     }
667     
668     public String JavaDoc getDisplayName() {
669         String JavaDoc val = ip.getProperty(PROP_DISPLAY_NAME);
670         return val != null && val.length() > 0 ? val
671                                                : DEF_VALUE_DISPLAY_NAME;
672     }
673     
674     // private helper methods -------------------------------------------------
675

676     private static List JavaDoc/*<URL>*/ listUrls(final File JavaDoc folder, final String JavaDoc[] filter) {
677         File JavaDoc[] jars = folder.listFiles(new FilenameFilter JavaDoc() {
678             public boolean accept(File JavaDoc dir, String JavaDoc name) {
679                 if (!name.endsWith(".jar") || !dir.equals(folder)) {
680                     return false;
681                 }
682                 for (int i = 0; i < filter.length; i++) {
683                     if (name.indexOf(filter[i]) != -1) {
684                         return false;
685                     }
686                 }
687                 return true;
688             }
689         });
690         if (jars == null) {
691             return new ArrayList JavaDoc();
692         }
693         List JavaDoc/*<URL>*/ urls = new ArrayList JavaDoc(jars.length);
694         for (int i = 0; i < jars.length; i++) {
695             try {
696                 urls.add(Utils.fileToUrl(jars[i]));
697             } catch (MalformedURLException JavaDoc e) {
698                 ErrorManager.getDefault().notify(e);
699             }
700         }
701         return urls;
702     }
703 }
704
Popular Tags