Source Code Cross Referenced for TomcatProperties.java in  » IDE-Netbeans » tomcat5 » org » netbeans » modules » tomcat5 » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » tomcat5 » org.netbeans.modules.tomcat5.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.tomcat5.util;
043:
044:        import java.beans.PropertyChangeEvent;
045:        import java.beans.PropertyChangeListener;
046:        import java.io.File;
047:        import java.io.FilenameFilter;
048:        import java.io.IOException;
049:        import java.io.OutputStream;
050:        import java.net.MalformedURLException;
051:        import java.util.ArrayList;
052:        import java.util.List;
053:        import java.util.logging.Level;
054:        import java.util.logging.Logger;
055:        import org.netbeans.api.java.platform.JavaPlatform;
056:        import org.netbeans.api.java.platform.JavaPlatformManager;
057:        import org.netbeans.api.java.platform.Specification;
058:        import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
059:        import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
060:        import org.netbeans.modules.tomcat5.TomcatFactory;
061:        import org.netbeans.modules.tomcat5.TomcatManager;
062:        import org.netbeans.modules.tomcat5.TomcatManager.TomcatVersion;
063:        import org.netbeans.modules.tomcat5.customizer.CustomizerSupport;
064:        import org.openide.filesystems.FileLock;
065:        import org.openide.filesystems.FileObject;
066:        import org.openide.filesystems.FileSystem;
067:        import org.openide.filesystems.FileUtil;
068:        import org.openide.filesystems.Repository;
069:        import org.openide.modules.InstalledFileLocator;
070:        import org.openide.util.Exceptions;
071:        import org.openide.util.NbBundle;
072:        import org.openide.util.Utilities;
073:
074:        /**
075:         * Utility class that makes it easier to access and set Tomcat instance properties.
076:         *
077:         * @author sherold
078:         */
079:        public class TomcatProperties {
080:
081:            private static final Logger LOGGER = Logger
082:                    .getLogger(TomcatProperties.class.getName());
083:
084:            /** Java platform property which is used as a java platform ID */
085:            public static final String PLAT_PROP_ANT_NAME = "platform.ant.name"; //NOI18N
086:
087:            public static final String DEBUG_TYPE_SOCKET = "SEL_debuggingType_socket"; // NOI18N
088:            public static final String DEBUG_TYPE_SHARED = "SEL_debuggingType_shared"; // NOI18N
089:
090:            public static final String BUNDLED_TOMCAT_SETTING = "J2EE/BundledTomcat/Setting"; // NOI18N
091:
092:            // properties    
093:            private static final String PROP_URL = InstanceProperties.URL_ATTR;
094:            private static final String PROP_USERNAME = InstanceProperties.USERNAME_ATTR;
095:            private static final String PROP_PASSWORD = InstanceProperties.PASSWORD_ATTR;
096:            public static final String PROP_SERVER_PORT = InstanceProperties.HTTP_PORT_NUMBER;
097:            private static final String PROP_DISPLAY_NAME = InstanceProperties.DISPLAY_NAME_ATTR;
098:            public static final String PROP_SHUTDOWN = "admin_port"; //NOI18N
099:            public static final String PROP_MONITOR = "monitor_enabled"; // NOI18N   
100:            public static final String PROP_PROXY_ENABLED = "proxy_enabled"; // NOI18N   
101:            private static final String PROP_CUSTOM_SCRIPT = "custom_script_enabled"; // NOI18N
102:            private static final String PROP_SCRIPT_PATH = "script_path"; // NOI18N
103:            private static final String PROP_FORCE_STOP = "forceStopOption"; // NOI18N    
104:            private static final String PROP_DEBUG_TYPE = "debug_type"; // NOI18N
105:            private static final String PROP_DEBUG_PORT = "debugger_port"; // NOI18N
106:            private static final String PROP_SHARED_MEM = "shared_memory"; // NOI18N    
107:            private static final String PROP_JAVA_PLATFORM = "java_platform"; // NOI18N
108:            private static final String PROP_JAVA_OPTS = "java_opts"; // NOI18N
109:            private static final String PROP_SEC_MANAGER = "securityStartupOption"; // NOI18N    
110:            private static final String PROP_SOURCES = "sources"; // NOI18N
111:            private static final String PROP_JAVADOCS = "javadocs"; // NOI18N
112:            private static final String PROP_OPEN_LOG = "openContextLogOnRun"; // NOI18N
113:            /** server.xml check timestamp */
114:            private static final String PROP_TIMESTAMP = "timestamp"; // NOI18N
115:            private static final String PROP_HOST = "host"; // NOI18N
116:            public static final String PROP_RUNNING_CHECK_TIMEOUT = "runningCheckTimeout"; // NOI18N
117:            private static final String PROP_INSTANCE_ID = "instance_id"; // NOI18N
118:            public static final String PROP_AUTOREGISTERED = "autoregistered"; // NOI18N
119:            private static final String PROP_DRIVER_DEPLOYMENT = "driverDeploymentEnabled"; // NOI18N
120:
121:            // default values
122:            private static final boolean DEF_VALUE_SEC_MANAGER = false;
123:            private static final boolean DEF_VALUE_CUSTOM_SCRIPT = false;
124:            private static final String DEF_VALUE_SCRIPT_PATH = ""; // NOI18N
125:            private static final boolean DEF_VALUE_FORCE_STOP = false;
126:            private static final String DEF_VALUE_JAVA_OPTS = ""; // NOI18N
127:            private static final String DEF_VALUE_DEBUG_TYPE = Utilities
128:                    .isWindows() ? DEBUG_TYPE_SHARED : DEBUG_TYPE_SOCKET;
129:            private static final boolean DEF_VALUE_MONITOR = true;
130:            private static final boolean DEF_VALUE_PROXY_ENABLED = true;
131:            private static final int DEF_VALUE_DEBUG_PORT = 11550;
132:            private static final int DEF_VALUE_DEBUG_PORT_BUNDLED = 11555;
133:            private static final int DEF_VALUE_SERVER_PORT = 8080;
134:            public static final int DEF_VALUE_SHUTDOWN_PORT = 8005;
135:
136:            public static final int DEF_VALUE_BUNDLED_SERVER_PORT = 8084;
137:            public static final int DEF_VALUE_BUNDLED_SHUTDOWN_PORT = 8025;
138:
139:            private static final String DEF_VALUE_SHARED_MEM = "tomcat_shared_memory_id"; // NOI18N
140:            private static final boolean DEF_VALUE_OPEN_LOG = true;
141:            private static final String DEF_VALUE_HOST = "localhost"; // NOI18N
142:            public static final int DEF_VALUE_RUNNING_CHECK_TIMEOUT = 2000;
143:            private static final String DEF_VALUE_DISPLAY_NAME = NbBundle
144:                    .getMessage(TomcatProperties.class,
145:                            "LBL_DefaultDisplayName");
146:            private static final boolean DEF_VALUE_DRIVER_DEPLOYMENT = true;
147:            private static final int DEF_VALUE_DEPLOYMENT_TIMEOUT = 120;
148:
149:            private TomcatManager tm;
150:            private InstanceProperties ip;
151:            private File homeDir;
152:            private File baseDir;
153:
154:            /** Creates a new instance of TomcatProperties */
155:            public TomcatProperties(TomcatManager tm)
156:                    throws IllegalArgumentException {
157:                this .tm = tm;
158:                this .ip = tm.getInstanceProperties();
159:                String catalinaHome = null;
160:                String catalinaBase = null;
161:                String uri = ip.getProperty(PROP_URL); // NOI18N
162:                final String home = "home="; // NOI18N
163:                final String base = ":base="; // NOI18N
164:                final String uriString = "http://"; // NOI18N
165:                int uriOffset = uri.indexOf(uriString);
166:                int homeOffset = uri.indexOf(home) + home.length();
167:                int baseOffset = uri.indexOf(base, homeOffset);
168:                if (homeOffset >= home.length()) {
169:                    int homeEnd = baseOffset > 0 ? baseOffset
170:                            : (uriOffset > 0 ? uriOffset - 1 : uri.length());
171:                    int baseEnd = uriOffset > 0 ? uriOffset - 1 : uri.length();
172:                    catalinaHome = uri.substring(homeOffset, homeEnd);
173:                    if (baseOffset > 0) {
174:                        catalinaBase = uri.substring(
175:                                baseOffset + base.length(), baseEnd);
176:                    }
177:                    // Bundled Tomcat home and base dirs can be specified as attributes
178:                    // specified in BUNDLED_TOMCAT_SETTING file. Tomcat manager URL can 
179:                    // then look like "tomcat:home=$bundled_home:base=$bundled_base" and
180:                    // therefore remains valid even if Tomcat version changes. (issue# 40659)
181:                    if (catalinaHome.length() > 0
182:                            && catalinaHome.charAt(0) == '$') {
183:                        FileSystem fs = Repository.getDefault()
184:                                .getDefaultFileSystem();
185:                        FileObject fo = fs.findResource(BUNDLED_TOMCAT_SETTING);
186:                        if (fo != null) {
187:                            catalinaHome = fo.getAttribute(
188:                                    catalinaHome.substring(1)).toString();
189:                            if (catalinaBase != null
190:                                    && catalinaBase.length() > 0
191:                                    && catalinaBase.charAt(0) == '$') {
192:                                catalinaBase = fo.getAttribute(
193:                                        catalinaBase.substring(1)).toString();
194:                            }
195:                        }
196:                    }
197:                }
198:                if (catalinaHome == null) {
199:                    throw new IllegalArgumentException(
200:                            "CATALINA_HOME must not be null."); // NOI18N
201:                }
202:                homeDir = new File(catalinaHome);
203:                if (!homeDir.isAbsolute()) {
204:                    InstalledFileLocator ifl = InstalledFileLocator
205:                            .getDefault();
206:                    homeDir = ifl.locate(catalinaHome, null, false);
207:                }
208:                if (!homeDir.exists()) {
209:                    throw new IllegalArgumentException(
210:                            "CATALINA_HOME directory does not exist."); // NOI18N
211:                }
212:                if (catalinaBase != null) {
213:                    baseDir = new File(catalinaBase);
214:                    if (!baseDir.isAbsolute()) {
215:                        InstalledFileLocator ifl = InstalledFileLocator
216:                                .getDefault();
217:                        baseDir = ifl.locate(catalinaBase, null, false);
218:                        if (baseDir == null) {
219:                            baseDir = new File(System
220:                                    .getProperty("netbeans.user"), catalinaBase); // NOI18N
221:                        }
222:                    }
223:                }
224:
225:                //        //parse the old format for backward compatibility
226:                //        if (uriOffset > 0) {
227:                //            String theUri = uri.substring (uriOffset + uriString.length ());
228:                //            int portIndex = theUri.indexOf (':');
229:                //            String host = theUri.substring (0, portIndex - 1);
230:                //            setHost (host);
231:                //            //System.out.println("host:"+host);
232:                //            int portEnd = theUri.indexOf ('/');
233:                //            portEnd = portEnd > 0 ? portEnd : theUri.length ();
234:                //            String port = theUri.substring (portIndex, portEnd - 1);
235:                //            //System.out.println("port:"+port);
236:                //            try {
237:                //                setServerPort (Integer.valueOf (port));
238:                //            } catch (NumberFormatException nef) {
239:                //                org.openide.ErrorManager.getDefault ().log (nef.getLocalizedMessage ());
240:                //            }
241:                //        }
242:                ip.addPropertyChangeListener(new PropertyChangeListener() {
243:                    public void propertyChange(PropertyChangeEvent evt) {
244:                        String name = evt.getPropertyName();
245:                        if (PROP_SERVER_PORT.equals(name)
246:                                || PROP_USERNAME.equals(name)
247:                                || PROP_PASSWORD.equals(name)) {
248:                            // update Ant deployment properties file if it exists
249:                            try {
250:                                storeAntDeploymentProperties(
251:                                        getAntDeploymentPropertiesFile(), false);
252:                            } catch (IOException ioe) {
253:                                Logger.getLogger(
254:                                        TomcatProperties.class.getName()).log(
255:                                        Level.INFO, null, ioe);
256:                            }
257:                        }
258:                    }
259:                });
260:            }
261:
262:            /** 
263:             * Stores the Ant deployment properties in the specified file.
264:             * @param create if false the deployment properties file won't be created if
265:             *               it does not exist.
266:             * @throws IOException if a problem occurs.
267:             */
268:            public void storeAntDeploymentProperties(File file, boolean create)
269:                    throws IOException {
270:                if (!create && !file.exists()) {
271:                    return;
272:                }
273:                EditableProperties antProps = new EditableProperties();
274:                antProps.setProperty("tomcat.home", homeDir.getAbsolutePath()); // NOI18N
275:                antProps.setProperty("tomcat.url", getWebUrl()); // NOI18N
276:                antProps.setProperty("tomcat.username", getUsername()); // NOI18N
277:                antProps.setProperty("tomcat.password", getPassword()); // NOI18N
278:                file.createNewFile();
279:                FileObject fo = FileUtil.toFileObject(file);
280:                FileLock lock = fo.lock();
281:                try {
282:                    OutputStream os = fo.getOutputStream(lock);
283:                    try {
284:                        antProps.store(os);
285:                    } finally {
286:                        os.close();
287:                    }
288:                } finally {
289:                    lock.releaseLock();
290:                }
291:            }
292:
293:            /** Returns file the Ant deployment properties are stored in. */
294:            public File getAntDeploymentPropertiesFile() {
295:                return new File(System.getProperty("netbeans.user"),
296:                        getInstanceID() + ".properties"); // NOI18N
297:            }
298:
299:            /** 
300:             * Unique instance identifier used to differentiate different Tomcat instances 
301:             * in a human-readable form, unlike InstanceProperties.URL_ATTR.
302:             */
303:            private String getInstanceID() {
304:                String name = ip.getProperty(PROP_INSTANCE_ID);
305:                if (name != null) {
306:                    return name;
307:                }
308:                // generate unique tomcat instance identifier (e.g. tomcat55, tomcat55_1, ...
309:                // for Tomcat 5.5.x and tomcat50, tomcat50_1... for Tomcat 5.0.x)
310:                String prefix;
311:                String serverID;
312:                switch (tm.getTomcatVersion()) {
313:                case TOMCAT_60:
314:                    prefix = "tomcat60"; // NIO18N
315:                    serverID = TomcatFactory.SERVER_ID_60;
316:                    break;
317:                case TOMCAT_55:
318:                    prefix = "tomcat55"; // NIO18N
319:                    serverID = TomcatFactory.SERVER_ID_55;
320:                    break;
321:                case TOMCAT_50:
322:                default:
323:                    prefix = "tomcat50"; // NIO18N
324:                    serverID = TomcatFactory.SERVER_ID_50;
325:                }
326:                String[] instanceURLs = Deployment.getDefault()
327:                        .getInstancesOfServer(serverID);
328:                for (int i = 0; name == null; i++) {
329:                    if (i == 0) {
330:                        name = prefix;
331:                    } else {
332:                        name = prefix + "_" + i; // NOI18N
333:                    }
334:                    for (String url : instanceURLs) {
335:                        if (!tm.getUri().equals(url)) {
336:                            InstanceProperties ip = InstanceProperties
337:                                    .getInstanceProperties(url);
338:                            if (ip != null) {
339:                                String anotherName = ip
340:                                        .getProperty(PROP_INSTANCE_ID);
341:                                if (name.equals(anotherName)) {
342:                                    name = null;
343:                                    break;
344:                                }
345:                            }
346:                        }
347:                    }
348:                }
349:                ip.setProperty(PROP_INSTANCE_ID, name);
350:                return name;
351:            }
352:
353:            /** Returns server web url e.g. http://localhost:8080 */
354:            public String getWebUrl() {
355:                return "http://" + getHost() + ":" + getServerPort(); // NOI18N
356:            }
357:
358:            /** Return CATALINA_HOME directory.*/
359:            public File getCatalinaHome() {
360:                return homeDir;
361:            }
362:
363:            /** Return CATALINA_BASE directory or null if not defined. */
364:            public File getCatalinaBase() {
365:                return baseDir;
366:            }
367:
368:            /** Return CATALINA_BASE directory if defined, CATALINA_HOME otherwise. */
369:            public File getCatalinaDir() {
370:                return baseDir == null ? homeDir : baseDir;
371:            }
372:
373:            /** Returns the lib directory where for example the JDBC drivers should be deployed.
374:             */
375:            public File getLibsDir() {
376:                String libsDir = tm.isTomcat50() || tm.isTomcat55() ? "common/lib"
377:                        : "lib"; // NOI18N
378:                return new File(getCatalinaHome(), libsDir);
379:            }
380:
381:            /** Returns the folder where the HTTP Monitor jar files should be placed */
382:            public File getMonitorLibFolder() {
383:                if (tm.isBundledTomcat()) {
384:                    return new File(baseDir, "nblib"); // NOI18N
385:                }
386:                return tm.isTomcat60() ? new File(homeDir, "lib") // NOI18N
387:                        : new File(homeDir, "common/lib"); // NOI18N
388:            }
389:
390:            /**
391:             * Return the default Tomcat Java endorsed directory.
392:             */
393:            public File getJavaEndorsedDir() {
394:                if (TomcatVersion.TOMCAT_60 == tm.getTomcatVersion()) {
395:                    return new File(getCatalinaHome(), "endorsed"); // NOI18N
396:                } else {
397:                    return new File(getCatalinaHome(), "common/endorsed"); // NOI18N
398:                }
399:            }
400:
401:            public String getUsername() {
402:                String val = ip.getProperty(PROP_USERNAME);
403:                return val != null ? val : ""; // NOI18N
404:            }
405:
406:            public void setUsername(String value) {
407:                ip.setProperty(PROP_USERNAME, value);
408:            }
409:
410:            public String getPassword() {
411:                String val = ip.getProperty(PROP_PASSWORD);
412:                return val != null ? val : ""; // NOI18N
413:            }
414:
415:            public void setPassword(String value) {
416:                ip.setProperty(PROP_PASSWORD, value);
417:            }
418:
419:            public JavaPlatform getJavaPlatform() {
420:                String currentJvm = ip.getProperty(PROP_JAVA_PLATFORM);
421:                JavaPlatformManager jpm = JavaPlatformManager.getDefault();
422:                JavaPlatform[] installedPlatforms = jpm.getPlatforms(null,
423:                        new Specification("J2SE", null)); // NOI18N
424:                for (int i = 0; i < installedPlatforms.length; i++) {
425:                    String platformName = (String) installedPlatforms[i]
426:                            .getProperties().get(PLAT_PROP_ANT_NAME);
427:                    if (platformName != null && platformName.equals(currentJvm)) {
428:                        return installedPlatforms[i];
429:                    }
430:                }
431:                // return default platform if none was set
432:                return jpm.getDefaultPlatform();
433:            }
434:
435:            public void setJavaPlatform(JavaPlatform javaPlatform) {
436:                ip.setProperty(PROP_JAVA_PLATFORM, (String) javaPlatform
437:                        .getProperties().get(PLAT_PROP_ANT_NAME));
438:            }
439:
440:            public String getJavaOpts() {
441:                String val = ip.getProperty(PROP_JAVA_OPTS);
442:                return val != null ? val : DEF_VALUE_JAVA_OPTS;
443:            }
444:
445:            public void setJavaOpts(String javaOpts) {
446:                ip.setProperty(PROP_JAVA_OPTS, javaOpts);
447:            }
448:
449:            public boolean getSecManager() {
450:                String val = ip.getProperty(PROP_SEC_MANAGER);
451:                return val != null ? Boolean.valueOf(val).booleanValue()
452:                        : DEF_VALUE_SEC_MANAGER;
453:            }
454:
455:            public void setSecManager(boolean enabled) {
456:                ip.setProperty(PROP_SEC_MANAGER, Boolean.toString(enabled));
457:            }
458:
459:            public boolean getCustomScript() {
460:                String val = ip.getProperty(PROP_CUSTOM_SCRIPT);
461:                return val != null ? Boolean.valueOf(val).booleanValue()
462:                        : DEF_VALUE_CUSTOM_SCRIPT;
463:            }
464:
465:            public void setCustomScript(boolean enabled) {
466:                ip.setProperty(PROP_CUSTOM_SCRIPT, Boolean.toString(enabled));
467:            }
468:
469:            public String getScriptPath() {
470:                String val = ip.getProperty(PROP_SCRIPT_PATH);
471:                return val != null ? val : DEF_VALUE_SCRIPT_PATH;
472:            }
473:
474:            public void setScriptPath(String path) {
475:                ip.setProperty(PROP_SCRIPT_PATH, path);
476:            }
477:
478:            public boolean getForceStop() {
479:                if (Utilities.isWindows()) {
480:                    return false;
481:                }
482:                String val = ip.getProperty(PROP_FORCE_STOP);
483:                return val != null ? Boolean.valueOf(val).booleanValue()
484:                        : DEF_VALUE_FORCE_STOP;
485:            }
486:
487:            public void setForceStop(boolean enabled) {
488:                ip.setProperty(PROP_FORCE_STOP, Boolean.toString(enabled));
489:            }
490:
491:            public String getDebugType() {
492:                String val = ip.getProperty(PROP_DEBUG_TYPE);
493:                if ((DEBUG_TYPE_SHARED.equalsIgnoreCase(val) && Utilities
494:                        .isWindows())
495:                        || DEBUG_TYPE_SOCKET.equalsIgnoreCase(val)) {
496:                    return val;
497:                }
498:                return DEF_VALUE_DEBUG_TYPE;
499:            }
500:
501:            public void setDebugType(String type) {
502:                ip.setProperty(PROP_DEBUG_TYPE, type);
503:            }
504:
505:            public boolean getMonitor() {
506:                String val = ip.getProperty(PROP_MONITOR);
507:                return val != null ? Boolean.valueOf(val).booleanValue()
508:                        : DEF_VALUE_MONITOR;
509:            }
510:
511:            public void setMonitor(boolean enabled) {
512:                ip.setProperty(PROP_MONITOR, Boolean.toString(enabled));
513:            }
514:
515:            public boolean getProxyEnabled() {
516:                String val = ip.getProperty(PROP_PROXY_ENABLED);
517:                return val != null ? Boolean.valueOf(val).booleanValue()
518:                        : DEF_VALUE_PROXY_ENABLED;
519:            }
520:
521:            public void setProxyEnabled(boolean enabled) {
522:                ip.setProperty(PROP_PROXY_ENABLED, Boolean.toString(enabled));
523:            }
524:
525:            public int getDebugPort() {
526:                String val = ip.getProperty(PROP_DEBUG_PORT);
527:
528:                if (val != null) {
529:                    try {
530:                        return Integer.parseInt(val);
531:                    } catch (NumberFormatException nfe) {
532:                        Logger.getLogger(TomcatProperties.class.getName()).log(
533:                                Level.INFO, null, nfe);
534:                    }
535:                }
536:
537:                if (tm.isBundledTomcat()) {
538:                    return DEF_VALUE_DEBUG_PORT_BUNDLED;
539:                } else {
540:                    return DEF_VALUE_DEBUG_PORT;
541:                }
542:            }
543:
544:            public void setDebugPort(int port) {
545:                ip.setProperty(PROP_DEBUG_PORT, Integer.toString(port));
546:            }
547:
548:            public int getServerPort() {
549:                String val = ip.getProperty(PROP_SERVER_PORT);
550:                if (val != null) {
551:                    try {
552:                        int port = Integer.parseInt(val);
553:                        if (port >= 0 && port <= 65535) {
554:                            return port;
555:                        }
556:                    } catch (NumberFormatException nfe) {
557:                        Logger.getLogger(TomcatProperties.class.getName()).log(
558:                                Level.INFO, null, nfe);
559:                    }
560:                }
561:                return tm.isBundledTomcat() ? DEF_VALUE_BUNDLED_SERVER_PORT
562:                        : DEF_VALUE_SERVER_PORT;
563:            }
564:
565:            /** this needs to be kept in sync with value in the server.xml conf file */
566:            public void setServerPort(int port) {
567:                ip.setProperty(PROP_SERVER_PORT, Integer.toString(port));
568:            }
569:
570:            public int getShutdownPort() {
571:                String val = ip.getProperty(PROP_SHUTDOWN);
572:                if (val != null) {
573:                    try {
574:                        int port = Integer.parseInt(val);
575:                        if (port >= 0 && port <= 65535) {
576:                            return port;
577:                        }
578:                    } catch (NumberFormatException nfe) {
579:                        Logger.getLogger(TomcatProperties.class.getName()).log(
580:                                Level.INFO, null, nfe);
581:                    }
582:                }
583:                return tm.isBundledTomcat() ? DEF_VALUE_BUNDLED_SHUTDOWN_PORT
584:                        : DEF_VALUE_SHUTDOWN_PORT;
585:            }
586:
587:            /** this needs to be kept in sync with value in the server.xml conf file */
588:            public void setShutdownPort(int port) {
589:                ip.setProperty(PROP_SHUTDOWN, Integer.toString(port));
590:            }
591:
592:            public String getSharedMem() {
593:                String val = ip.getProperty(PROP_SHARED_MEM);
594:                return val != null && val.length() > 0 ? val
595:                        : DEF_VALUE_SHARED_MEM;
596:            }
597:
598:            public void setSharedMem(String val) {
599:                ip.setProperty(PROP_SHARED_MEM, val);
600:            }
601:
602:            public int getDeploymentTimeout() {
603:                String val = ip
604:                        .getProperty(InstanceProperties.DEPLOYMENT_TIMEOUT);
605:                if (val != null) {
606:                    try {
607:                        int timeout = Integer.parseInt(val);
608:                        if (timeout >= 1) {
609:                            return timeout;
610:                        }
611:                    } catch (NumberFormatException nfe) {
612:                        Logger.getLogger(TomcatProperties.class.getName()).log(
613:                                Level.INFO, null, nfe);
614:                    }
615:                }
616:                return DEF_VALUE_DEPLOYMENT_TIMEOUT;
617:            }
618:
619:            public void setDeploymentTimeout(int timeout) {
620:                ip.setProperty(InstanceProperties.DEPLOYMENT_TIMEOUT, Integer
621:                        .toString(timeout));
622:            }
623:
624:            public boolean getDriverDeployment() {
625:                String val = ip.getProperty(PROP_DRIVER_DEPLOYMENT);
626:                return val != null ? Boolean.valueOf(val).booleanValue()
627:                        : DEF_VALUE_DRIVER_DEPLOYMENT;
628:            }
629:
630:            public void setDriverDeployment(boolean enabled) {
631:                ip.setProperty(PROP_DRIVER_DEPLOYMENT, Boolean
632:                        .toString(enabled));
633:            }
634:
635:            public List/*<URL>*/getClasses() {
636:                String[] nbFilter = new String[] { "httpmonitor",
637:                        "schema2beans",
638:                        /*
639:                         * The following two jars contains eclipse JDT parser. We have to
640:                         * exclude it to not to clash with our jsp parser. See issue #115529.
641:                         */
642:                        "jasper-compiler-jdt", "jasper-jdt" };
643:
644:                String[] implFilter = new String[] { "-impl.jar" };
645:
646:                // tomcat libs
647:                List retValue = listUrls(new File(homeDir, tm.libFolder()),
648:                        nbFilter); // NOI18N
649:
650:                if (tm.isTomcat60()) {
651:                    try {
652:                        retValue.add(new File(homeDir, "bin/tomcat-juli.jar")
653:                                .toURI().toURL()); // NOI18N
654:                    } catch (MalformedURLException e) {
655:                        LOGGER.log(Level.WARNING,
656:                                "$CATALINA_HOME/bin/tomcat-juli.jar not found",
657:                                e); // NOI18N
658:                    }
659:                }
660:
661:                // jwsdp libs
662:                retValue.addAll(listUrls(new File(homeDir, "jaxws/lib"),
663:                        implFilter)); // NOI18N
664:                retValue.addAll(listUrls(new File(homeDir, "jaxb/lib"),
665:                        implFilter)); // NOI18N
666:                retValue.addAll(listUrls(new File(homeDir, "jwsdp-shared/lib"),
667:                        implFilter)); // NOI18N
668:                retValue.addAll(listUrls(new File(homeDir, "jaxp/lib"),
669:                        implFilter)); // NOI18N
670:                retValue.addAll(listUrls(new File(homeDir, "jaxrpc/lib"),
671:                        implFilter)); // NOI18N
672:                retValue.addAll(listUrls(new File(homeDir, "jaxr/lib"),
673:                        implFilter)); // NOI18N
674:                retValue.addAll(listUrls(new File(homeDir, "saaj/lib"),
675:                        implFilter)); // NOI18N
676:                retValue.addAll(listUrls(new File(homeDir, "sjsxp/lib"),
677:                        implFilter)); // NOI18N
678:
679:                // wsit
680:                retValue.addAll(listUrls(new File(homeDir, "shared/lib"),
681:                        implFilter)); // NOI18N
682:
683:                // other
684:                retValue.addAll(listUrls(new File(homeDir, "jstl/lib"),
685:                        implFilter)); // NOI18N
686:                retValue.addAll(listUrls(new File(baseDir, "shared/lib"),
687:                        nbFilter)); // NOI18N
688:                return retValue;
689:            }
690:
691:            public List/*<URL>*/getSources() {
692:                String path = ip.getProperty(PROP_SOURCES);
693:                if (path == null) {
694:                    return new ArrayList();
695:                }
696:                return CustomizerSupport.tokenizePath(path);
697:            }
698:
699:            public void setSources(List/*<URL>*/path) {
700:                ip.setProperty(PROP_SOURCES, CustomizerSupport.buildPath(path));
701:                tm.getTomcatPlatform().notifyLibrariesChanged();
702:            }
703:
704:            public List/*<URL>*/getJavadocs() {
705:                String path = ip.getProperty(PROP_JAVADOCS);
706:                if (path == null) {
707:                    ArrayList list = new ArrayList();
708:                    try {
709:                        // tomcat docs
710:                        File jspApiDoc = new File(homeDir,
711:                                "webapps/tomcat-docs/jspapi"); // NOI18N
712:                        File servletApiDoc = new File(homeDir,
713:                                "webapps/tomcat-docs/servletapi"); // NOI18N
714:                        if (jspApiDoc.exists() && servletApiDoc.exists()) {
715:                            list.add(Utils.fileToUrl(jspApiDoc));
716:                            list.add(Utils.fileToUrl(servletApiDoc));
717:                        } else {
718:                            File j2eeDoc = InstalledFileLocator.getDefault()
719:                                    .locate("docs/javaee5-doc-api.zip", null,
720:                                            false); // NOI18N
721:                            if (j2eeDoc != null) {
722:                                list.add(Utils.fileToUrl(j2eeDoc));
723:                            }
724:                        }
725:                        // jwsdp docs
726:                        File docs = new File(homeDir, "docs/api"); // NOI18N
727:                        if (docs.exists()) {
728:                            list.add(Utils.fileToUrl(docs));
729:                        }
730:                    } catch (MalformedURLException e) {
731:                        Exceptions.printStackTrace(e);
732:                    }
733:                    return list;
734:                }
735:                return CustomizerSupport.tokenizePath(path);
736:            }
737:
738:            public void setJavadocs(List/*<URL>*/path) {
739:                ip
740:                        .setProperty(PROP_JAVADOCS, CustomizerSupport
741:                                .buildPath(path));
742:                tm.getTomcatPlatform().notifyLibrariesChanged();
743:            }
744:
745:            public void setOpenContextLogOnRun(boolean val) {
746:                ip.setProperty(PROP_OPEN_LOG, Boolean.valueOf(val).toString());
747:            }
748:
749:            public boolean getOpenContextLogOnRun() {
750:                Object val = ip.getProperty(PROP_OPEN_LOG);
751:                if (val != null) {
752:                    return Boolean.valueOf(val.toString()).booleanValue();
753:                }
754:                return DEF_VALUE_OPEN_LOG;
755:            }
756:
757:            public void setTimestamp(long timestamp) {
758:                ip.setProperty(PROP_TIMESTAMP, Long.toString(timestamp));
759:            }
760:
761:            /** Return last server.xml check timestamp, or -1 if not set */
762:            public long getTimestamp() {
763:                String val = ip.getProperty(PROP_TIMESTAMP);
764:                if (val != null) {
765:                    try {
766:                        return Long.parseLong(val);
767:                    } catch (NumberFormatException nfe) {
768:                        Logger.getLogger(TomcatProperties.class.getName()).log(
769:                                Level.INFO, null, nfe);
770:                    }
771:                }
772:                return -1;
773:            }
774:
775:            /**
776:             * Return server.xml file from the catalina base folder if the base folder is used 
777:             * or from the catalina home folder otherwise.
778:             * <p>
779:             * <b>BEWARE</b>: If the catalina base folder is used but has not bee generated yet,
780:             * the server.xml file from the catalina home folder will be returned.
781:             * </p>
782:             */
783:            public File getServerXml() {
784:                String confServerXml = "conf/server.xml"; // NIO18N
785:                File serverXml = null;
786:                if (baseDir != null) {
787:                    serverXml = new File(baseDir, confServerXml);
788:                }
789:                if (serverXml == null || !serverXml.exists()) {
790:                    serverXml = new File(getCatalinaHome(), confServerXml);
791:                }
792:                return serverXml;
793:            }
794:
795:            public String getHost() {
796:                String val = ip.getProperty(PROP_HOST);
797:                return val != null ? val : DEF_VALUE_HOST;
798:            }
799:
800:            public int getRunningCheckTimeout() {
801:                String val = ip.getProperty(PROP_RUNNING_CHECK_TIMEOUT);
802:                if (val != null) {
803:                    try {
804:                        return Integer.parseInt(val);
805:                    } catch (NumberFormatException nfe) {
806:                        Logger.getLogger(TomcatProperties.class.getName()).log(
807:                                Level.INFO, null, nfe);
808:                    }
809:                }
810:                return DEF_VALUE_RUNNING_CHECK_TIMEOUT;
811:            }
812:
813:            public String getDisplayName() {
814:                String val = ip.getProperty(PROP_DISPLAY_NAME);
815:                return val != null && val.length() > 0 ? val
816:                        : DEF_VALUE_DISPLAY_NAME;
817:            }
818:
819:            // private helper methods -------------------------------------------------
820:
821:            private static List/*<URL>*/listUrls(final File folder,
822:                    final String[] filter) {
823:                File[] jars = folder.listFiles(new FilenameFilter() {
824:                    public boolean accept(File dir, String name) {
825:                        if (!name.endsWith(".jar") || !dir.equals(folder)) {
826:                            return false;
827:                        }
828:                        for (int i = 0; i < filter.length; i++) {
829:                            if (name.indexOf(filter[i]) != -1) {
830:                                return false;
831:                            }
832:                        }
833:                        return true;
834:                    }
835:                });
836:                if (jars == null) {
837:                    return new ArrayList();
838:                }
839:                List/*<URL>*/urls = new ArrayList(jars.length);
840:                for (int i = 0; i < jars.length; i++) {
841:                    try {
842:                        urls.add(Utils.fileToUrl(jars[i]));
843:                    } catch (MalformedURLException e) {
844:                        Exceptions.printStackTrace(e);
845:                    }
846:                }
847:                return urls;
848:            }
849:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.