FileDocCategorySizeDatePackage
PropertiesSettings.javaAPI DocExample4646Mon Jul 23 13:26:54 BST 2007org.apache.struts2.config

PropertiesSettings

public class PropertiesSettings extends Settings
A class to handle settings via a properties file.

Fields Summary
com.opensymphony.xwork2.util.location.LocatableProperties
settings
static Log
LOG
Constructors Summary
public PropertiesSettings(String name)
Creates a new properties config given the name of a properties file. The name is expected to NOT have the ".properties" file extension. So when new PropertiesSettings("foo") is called this class will look in the classpath for the foo.properties file.

param
name the name of the properties file, excluding the ".properties" extension.



                                                              
       
        
        URL settingsUrl = ClassLoaderUtils.getResource(name + ".properties", getClass());
        
        if (settingsUrl == null) {
            LOG.debug(name + ".properties missing");
            settings = new LocatableProperties();
            return;
        }
        
        settings = new LocatableProperties(new LocationImpl(null, settingsUrl.toString()));

        // Load settings
        InputStream in = null;
        try {
            in = settingsUrl.openStream();
            settings.load(in);
        } catch (IOException e) {
            throw new StrutsException("Could not load " + name + ".properties:" + e, e);
        } finally {
            if(in != null) {
                try {
                    in.close();
                } catch(IOException io) {
                    LOG.warn("Unable to close input stream", io);
                }
            }
        }
    
Methods Summary
public java.lang.StringgetImpl(java.lang.String aName)
Gets a property from the properties file.

see
#get(String)

        String setting = settings.getProperty(aName);

        if (setting == null) {
            throw new IllegalArgumentException("No such setting:" + aName);
        }

        return setting;
    
public com.opensymphony.xwork2.util.location.LocationgetLocationImpl(java.lang.String aName)
Gets the location of a property from the properties file.

see
#getLocation(String)

        Location loc = settings.getPropertyLocation(aName);

        if (loc == null) {
            if (!settings.containsKey(aName)) {
                throw new IllegalArgumentException("No such setting:" + aName);
            } 
        }

        return loc;
    
public booleanisSetImpl(java.lang.String aName)
Tests to see if a property exists in the properties file.

see
#isSet(String)

        if (settings.get(aName) != null) {
            return true;
        } else {
            return false;
        }
    
public java.util.IteratorlistImpl()
Lists all keys in the properties file.

see
#list()

        return settings.keySet().iterator();
    
public voidsetImpl(java.lang.String aName, java.lang.String aValue)
Sets a property in the properties file.

see
#set(String, String)

        settings.setProperty(aName, aValue);