FileDocCategorySizeDatePackage
CatalinaProperties.javaAPI DocApache Tomcat 6.0.144794Fri Jul 20 04:20:32 BST 2007org.apache.catalina.startup

CatalinaProperties

public class CatalinaProperties extends Object
Utility class to read the bootstrap Catalina configuration.
author
Remy Maucherat
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

Fields Summary
private static org.apache.juli.logging.Log
log
private static Properties
properties
Constructors Summary
Methods Summary
private static java.lang.StringgetCatalinaBase()
Get the value of the catalina.base environment variable.

        return System.getProperty("catalina.base", getCatalinaHome());
    
private static java.lang.StringgetCatalinaHome()
Get the value of the catalina.home environment variable.

        return System.getProperty("catalina.home",
                                  System.getProperty("user.dir"));
    
private static java.lang.StringgetConfigUrl()
Get the value of the configuration URL.

        return System.getProperty("catalina.config");
    
public static java.lang.StringgetProperty(java.lang.String name)
Return specified property value.



     

        loadProperties();

    
	
        return properties.getProperty(name);

    
public static java.lang.StringgetProperty(java.lang.String name, java.lang.String defaultValue)
Return specified property value.


        return properties.getProperty(name, defaultValue);

    
private static voidloadProperties()
Load properties.


        InputStream is = null;
        Throwable error = null;

        try {
            String configUrl = getConfigUrl();
            if (configUrl != null) {
                is = (new URL(configUrl)).openStream();
            }
        } catch (Throwable t) {
            // Ignore
        }

        if (is == null) {
            try {
                File home = new File(getCatalinaBase());
                File conf = new File(home, "conf");
                File properties = new File(conf, "catalina.properties");
                is = new FileInputStream(properties);
            } catch (Throwable t) {
                // Ignore
            }
        }

        if (is == null) {
            try {
                is = CatalinaProperties.class.getResourceAsStream
                    ("/org/apache/catalina/startup/catalina.properties");
            } catch (Throwable t) {
                // Ignore
            }
        }

        if (is != null) {
            try {
                properties = new Properties();
                properties.load(is);
                is.close();
            } catch (Throwable t) {
                error = t;
            }
        }

        if ((is == null) || (error != null)) {
            // Do something
            log.warn("Failed to load catalina.properties", error);
            // That's fine - we have reasonable defaults.
            properties=new Properties();
        }

        // Register the properties as system properties
        Enumeration enumeration = properties.propertyNames();
        while (enumeration.hasMoreElements()) {
            String name = (String) enumeration.nextElement();
            String value = properties.getProperty(name);
            if (value != null) {
                System.setProperty(name, value);
            }
        }