Author: lukaszlenart Date: Tue Oct 22 13:42:51 2013 New Revision: 1534634 URL: http://svn.apache.org/r1534634 Log: WW-4152 Solves problem with NPE as a side effect of concurrency issue, removes old code, use simpler dependency graph
Added: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesConfigurationProvider.java - copied, changed from r1534132, struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/LegacyPropertiesConfigurationProvider.java struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/PropertiesConfigurationProviderTest.java - copied, changed from r1534132, struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/LegacyPropertiesConfigurationProviderTest.java Removed: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/LegacyPropertiesConfigurationProvider.java struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/LegacyPropertiesConfigurationProviderTest.java Modified: struts/struts2/trunk/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/resources/struts.properties struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultPropertiesProvider.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DelegatingSettings.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesSettings.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/TestSettings.java struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocatableProperties.java struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocationImpl.java Modified: struts/struts2/trunk/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/resources/struts.properties URL: http://svn.apache.org/viewvc/struts/struts2/trunk/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/resources/struts.properties?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/resources/struts.properties (original) +++ struts/struts2/trunk/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/resources/struts.properties Tue Oct 22 13:42:51 2013 @@ -4,11 +4,6 @@ ###(can be overridden by a struts.properties file in the root of the classpath) ### -### Specifies the Configuration used to configure Struts 2.0 -### one could extend org.apache.struts2.config.Configuration -### to build one's customize way of getting the configurations parameters into Struts 2.0 -# struts.configuration=org.apache.struts2.config.DefaultConfiguration - ### This can be used to set your default locale and encoding scheme # struts.locale=en_US struts.i18n.encoding=UTF-8 Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultPropertiesProvider.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultPropertiesProvider.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultPropertiesProvider.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultPropertiesProvider.java Tue Oct 22 13:42:51 2013 @@ -29,7 +29,7 @@ import com.opensymphony.xwork2.util.loca /** * Loads the default properties, separate from the usual struts.properties loading */ -public class DefaultPropertiesProvider extends LegacyPropertiesConfigurationProvider { +public class DefaultPropertiesProvider extends PropertiesConfigurationProvider { public void destroy() { } @@ -37,17 +37,13 @@ public class DefaultPropertiesProvider e public void init(Configuration configuration) throws ConfigurationException { } - public void register(ContainerBuilder builder, LocatableProperties props) - throws ConfigurationException { - - Settings defaultSettings = null; + public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { try { - defaultSettings = new PropertiesSettings("org/apache/struts2/default"); + PropertiesSettings defaultSettings = new PropertiesSettings("org/apache/struts2/default"); + loadSettings(props, defaultSettings); } catch (Exception e) { throw new ConfigurationException("Could not find or error in org/apache/struts2/default.properties", e); } - - loadSettings(props, defaultSettings); } } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java Tue Oct 22 13:42:51 2013 @@ -21,15 +21,16 @@ package org.apache.struts2.config; +import com.opensymphony.xwork2.util.location.Location; +import com.opensymphony.xwork2.util.logging.Logger; +import com.opensymphony.xwork2.util.logging.LoggerFactory; +import org.apache.struts2.StrutsConstants; +import org.apache.struts2.security.DefaultSecurityGate; + import java.util.ArrayList; import java.util.Iterator; import java.util.StringTokenizer; -import org.apache.struts2.StrutsConstants; - -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerFactory; - /** @@ -38,17 +39,14 @@ import com.opensymphony.xwork2.util.logg * This class creates and delegates to other settings by using an internal * {@link DelegatingSettings} object. */ -public class DefaultSettings extends Settings { +public class DefaultSettings implements Settings { - /** - * The logging instance for this class. - */ - protected Logger log = LoggerFactory.getLogger(this.getClass()); + private static final Logger LOG = LoggerFactory.getLogger(DefaultSecurityGate.class); /** * The Settings object that handles API calls. */ - Settings delegate; + private Settings delegate; /** * Constructs an instance by loading the standard property files, @@ -67,53 +65,39 @@ public class DefaultSettings extends Set try { list.add(new PropertiesSettings("struts")); } catch (Exception e) { - log.warn("DefaultSettings: Could not find or error in struts.properties", e); + LOG.warn("DefaultSettings: Could not find or error in struts.properties", e); } - Settings[] settings = new Settings[list.size()]; - delegate = new DelegatingSettings(list.toArray(settings)); + delegate = new DelegatingSettings(list); // struts.custom.properties - try { - StringTokenizer customProperties = new StringTokenizer(delegate.getImpl(StrutsConstants.STRUTS_CUSTOM_PROPERTIES), ","); + String files = delegate.get(StrutsConstants.STRUTS_CUSTOM_PROPERTIES); + if (files != null) { + StringTokenizer customProperties = new StringTokenizer(files, ","); while (customProperties.hasMoreTokens()) { String name = customProperties.nextToken(); - try { list.add(new PropertiesSettings(name)); } catch (Exception e) { - log.error("DefaultSettings: Could not find " + name + ".properties. Skipping."); + LOG.error("DefaultSettings: Could not find " + name + ".properties. Skipping."); } } - settings = new Settings[list.size()]; - delegate = new DelegatingSettings(list.toArray(settings)); - } catch (IllegalArgumentException e) { - // Assume it's OK, since IllegalArgumentException is thrown - // when Settings is unable to find a certain setting, - // like the struts.custom.properties, which is commented out + delegate = new DelegatingSettings(list); } - } - // See superclass for Javadoc - public void setImpl(String name, String value) throws IllegalArgumentException, UnsupportedOperationException { - delegate.setImpl(name, value); + public Location getLocation(String name) { + return delegate.getLocation(name); } - // See superclass for Javadoc - public String getImpl(String aName) throws IllegalArgumentException { - return delegate.getImpl(aName); + public String get(String aName) throws IllegalArgumentException { + return delegate.get(aName); } - // See superclass for Javadoc - public boolean isSetImpl(String aName) { - return delegate.isSetImpl(aName); + public Iterator list() { + return delegate.list(); } - // See superclass for Javadoc - public Iterator listImpl() { - return delegate.listImpl(); - } } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DelegatingSettings.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DelegatingSettings.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DelegatingSettings.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DelegatingSettings.java Tue Oct 22 13:42:51 2013 @@ -21,8 +21,11 @@ package org.apache.struts2.config; +import com.opensymphony.xwork2.util.location.Location; + import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Set; @@ -36,72 +39,34 @@ import java.util.Set; * withholding any exception until all delegates have been called. * */ -class DelegatingSettings extends Settings { +class DelegatingSettings implements Settings { /** * The Settings objects. */ - Settings[] delegates; + List<Settings> delegates; /** * Creates a new DelegatingSettings object utilizing the list of {@link Settings} objects. * * @param delegates The Settings objects to use as delegates */ - public DelegatingSettings(Settings[] delegates) { + public DelegatingSettings(List<Settings> delegates) { this.delegates = delegates; } - // See superclass for Javadoc - public void setImpl(String name, String value) throws IllegalArgumentException, UnsupportedOperationException { - IllegalArgumentException e = null; - + public String get(String name) throws IllegalArgumentException { for (Settings delegate : delegates) { - try { - delegate.getImpl(name); // Throws exception if not found - delegate.setImpl(name, value); // Found it - return; // Done - } catch (IllegalArgumentException ex) { - e = ex; - - // Try next delegate + String value = delegate.get(name); + if (value != null) { + return value; } } - - throw e; + return null; } - // See superclass for Javadoc - public String getImpl(String name) throws IllegalArgumentException { - - IllegalArgumentException e = null; - for (Settings delegate : delegates) { - try { - return delegate.getImpl(name); // Throws exception if not found - } catch (IllegalArgumentException ex) { - e = ex; - - // Try next delegate - } - } - - throw e; - } - - // See superclass for Javadoc - public boolean isSetImpl(String aName) { - for (Settings delegate : delegates) { - if (delegate.isSetImpl(aName)) { - return true; - } - } - - return false; - } - - // See superclass for Javadoc - public Iterator listImpl() { + public Iterator list() { boolean workedAtAll = false; Set<Object> settingList = new HashSet<Object>(); @@ -109,7 +74,7 @@ class DelegatingSettings extends Setting for (Settings delegate : delegates) { try { - Iterator list = delegate.listImpl(); + Iterator list = delegate.list(); while (list.hasNext()) { settingList.add(list.next()); @@ -129,4 +94,14 @@ class DelegatingSettings extends Setting return settingList.iterator(); } } + + public Location getLocation(String name) { + for (Settings delegate : delegates) { + Location loc = delegate.getLocation(name); + if (loc != null) { + return loc; + } + } + return Location.UNKNOWN; + } } Copied: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesConfigurationProvider.java (from r1534132, struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/LegacyPropertiesConfigurationProvider.java) URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesConfigurationProvider.java?p2=struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesConfigurationProvider.java&p1=struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/LegacyPropertiesConfigurationProvider.java&r1=1534132&r2=1534634&rev=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/LegacyPropertiesConfigurationProvider.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesConfigurationProvider.java Tue Oct 22 13:42:51 2013 @@ -25,78 +25,28 @@ import com.opensymphony.xwork2.config.Co import com.opensymphony.xwork2.config.ConfigurationException; import com.opensymphony.xwork2.config.ConfigurationProvider; import com.opensymphony.xwork2.inject.ContainerBuilder; -import com.opensymphony.xwork2.inject.Context; -import com.opensymphony.xwork2.inject.Factory; import com.opensymphony.xwork2.util.location.LocatableProperties; -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerFactory; -import org.apache.struts2.StrutsConstants; import java.util.Iterator; -import java.util.Locale; -import java.util.StringTokenizer; -public class LegacyPropertiesConfigurationProvider implements ConfigurationProvider { - - /** - * The Logging instance for this class. - */ - private static final Logger LOG = LoggerFactory.getLogger(LegacyPropertiesConfigurationProvider.class); +public class PropertiesConfigurationProvider implements ConfigurationProvider { public void destroy() { - Settings.reset(); } - public void init(Configuration configuration) - throws ConfigurationException { - Settings.reset(); + public void init(Configuration configuration) throws ConfigurationException { } - - public void loadPackages() - throws ConfigurationException { + + public void loadPackages() throws ConfigurationException { } public boolean needsReload() { return false; } - public void register(ContainerBuilder builder, LocatableProperties props) - throws ConfigurationException { - - final Settings settings = Settings.getInstance(); - + public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { + final DefaultSettings settings = new DefaultSettings(); loadSettings(props, settings); - - // Set default locale by lazily resolving the locale property as needed into a Locale object - builder.factory(Locale.class, new Factory<Locale>() { - private Locale locale; - - public synchronized Locale create(Context context) throws Exception { - if (locale == null) { - String loc = context.getContainer().getInstance(String.class, StrutsConstants.STRUTS_LOCALE); - if (loc != null) { - StringTokenizer localeTokens = new StringTokenizer(loc, "_"); - String lang = null; - String country = null; - - if (localeTokens.hasMoreTokens()) { - lang = localeTokens.nextToken(); - } - - if (localeTokens.hasMoreTokens()) { - country = localeTokens.nextToken(); - } - locale = new Locale(lang, country); - } else { - if (LOG.isInfoEnabled()) { - LOG.info("No locale define, substituting the default VM locale"); - } - locale = Locale.getDefault(); - } - } - return locale; - } - }); } /** @@ -104,10 +54,9 @@ public class LegacyPropertiesConfigurati * @param settings */ protected void loadSettings(LocatableProperties props, final Settings settings) { - // We are calling the impl methods to get around the single instance of Settings that is expected - for (Iterator i = settings.listImpl(); i.hasNext(); ) { + for (Iterator i = settings.list(); i.hasNext(); ) { String name = (String) i.next(); - props.setProperty(name, settings.getImpl(name), settings.getLocationImpl(name)); + props.setProperty(name, settings.get(name), settings.getLocation(name)); } } } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesSettings.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesSettings.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesSettings.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/PropertiesSettings.java Tue Oct 22 13:42:51 2013 @@ -38,11 +38,11 @@ import java.util.Iterator; /** * A class to handle settings via a properties file. */ -class PropertiesSettings extends Settings { +class PropertiesSettings implements Settings { - LocatableProperties settings; - static Logger LOG = LoggerFactory.getLogger(PropertiesSettings.class); + private static final Logger LOG = LoggerFactory.getLogger(PropertiesSettings.class); + private LocatableProperties settings; /** * Creates a new properties config given the name of a properties file. The name is expected to NOT have @@ -87,27 +87,12 @@ class PropertiesSettings extends Setting /** - * Sets a property in the properties file. - * - * @see #set(String, String) - */ - public void setImpl(String aName, String aValue) { - settings.setProperty(aName, aValue); - } - - /** * Gets a property from the properties file. * * @see #get(String) */ - public String getImpl(String aName) throws IllegalArgumentException { - String setting = settings.getProperty(aName); - - if (setting == null) { - throw new IllegalArgumentException("No such setting:" + aName); - } - - return setting; + public String get(String aName) throws IllegalArgumentException { + return settings.getProperty(aName); } /** @@ -115,29 +100,8 @@ class PropertiesSettings extends Setting * * @see #getLocation(String) */ - public Location getLocationImpl(String aName) throws IllegalArgumentException { - Location loc = settings.getPropertyLocation(aName); - - if (loc == null) { - if (!settings.containsKey(aName)) { - throw new IllegalArgumentException("No such setting:" + aName); - } - } - - return loc; - } - - /** - * Tests to see if a property exists in the properties file. - * - * @see #isSet(String) - */ - public boolean isSetImpl(String aName) { - if (settings.get(aName) != null) { - return true; - } else { - return false; - } + public Location getLocation(String aName) throws IllegalArgumentException { + return settings.getPropertyLocation(aName); } /** @@ -145,7 +109,8 @@ class PropertiesSettings extends Setting * * @see #list() */ - public Iterator listImpl() { + public Iterator list() { return settings.keySet().iterator(); } + } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java Tue Oct 22 13:42:51 2013 @@ -21,290 +21,36 @@ package org.apache.struts2.config; -import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.util.location.Location; -import com.opensymphony.xwork2.util.logging.Logger; -import com.opensymphony.xwork2.util.logging.LoggerFactory; -import org.apache.struts2.StrutsConstants; import java.util.Iterator; -import java.util.Locale; - /** * Settings retrieves and exposes default values used by the framework. - * An application can override a factory default and provide its own value for a setting. - * <p> - * Implementation of the class is pluggable (the default implementation is {@link DefaultSettings}). - * Pluggability gives applications to ability to customize how settings are retrieved. - * As an example, an application may wish to check some custom property store - * before delegating to the usual configuration and property files. - * <p> - * Key methods: - * <ul> - * <li>{@link #getLocale()}</li> - * <li>{@link #get(String)}</li> - * <li>{@link #set(String, String)}</li> - * <li>{@link #list()}</li> - * </ul> - * <p> - * Key methods for subclasses (plugins): - * <ul> - * <li>{@link #getImpl(String)}</li> - * <li>{@link #setImpl(String, String)}</li> - * <li>{@link #listImpl()}</li> - * <li>{@link #isSetImpl(String)}</li> - * </ul> - * @deprecated Since Struts 2.1.2 */ -class Settings { - - - /** - * A pluggable implementation of Settings, - * provided through the {@link #setInstance} method. - */ - static Settings settingsImpl; - - /** - * An instance of {@link DefaultSettings} - * to use when another implementation is not provided (plugged in). - */ - static Settings defaultImpl; - - /** - * Guard used to protect the defaultImpl initialisation. - */ - private static final Object DEFAULT_LOCK = new Object(); - - /** - * An instance of the default locale as specified by the <code>struts.locale</code> setting. - * - * @see #getLocale - */ - static Locale locale; - - /** - * The Logging instance for this class. - */ - private static final Logger LOG = LoggerFactory.getLogger(Settings.class); - - /** - * Registers a custom Settings implementation (plugin), - * and resets the cached locale. - * <p> - * This method can only be called once. - * - * @param config a Settings implementation - * @throws IllegalStateException if an error occurs when setting the settings implementation. - */ - public static void setInstance(Settings config) throws IllegalStateException { - settingsImpl = config; - locale = null; - } - - /** - * Provides the Settings object. - * <p> - * This method will substitute the default instance if another instance is not registered. - * - * @return the Settings object. - */ - public static Settings getInstance() { - return (settingsImpl == null) ? getDefaultInstance() : settingsImpl; - } - - /** - * Provides the Struts default locale. - * <p> - * This method utilizes the <code>struts.locale</code> setting, which should be given - * as the Java {@link java.util.Locale#toString() toString()} representation of a Locale object - * ("en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr_MAC", and so forth). - * <p> - * If a <code>struts.locale</code> setting is not registered, - * then the default virtual machine locale is substituted and cached. - * - * @return the Struts default locale if specified or the VM default locale. - * @see java.util.Locale#getDefault() - */ - public static Locale getLocale() { - // Locale processing has been moved to the LegacyPropertiesConfigurationProvider - - return locale; - } - - /** - * Determines whether or not a setting has a registered value. - * <p> - * This method is useful for testing for the existance of setting without - * throwing an IllegalArgumentException. - * - * @param name the name of a setting to test. - * @return <code>true</code> if the setting exists and has a value, <code>false</code> otherwise. - */ - public static boolean isSet(String name) { - return getInstance().isSetImpl(name); - } +interface Settings { /** - * Provides a setting value as a String. - * <p> - * The method will throw an <code>IllegalArgumentException</code> if an error occurs - * while retrieveing the property or if the property doesn't exist. + * Retrieve value for provided name * - * @param name the name of the setting to retrieve. - * @return the setting value as a String. - * @throws IllegalArgumentException if an error occurs retrieving the property or the property does not exist. + * @param name The name of the setting value to retrieve + * @return The setting value as a String or null */ - public static String get(String name) throws IllegalArgumentException { - return getInstance().getImpl(name); - } + String get(String name); /** - * Provides the Location of a setting. - * <p> - * The Location is utilized as part of precise error reporting. - * <p> - * This method will throw an <code>IllegalArgumentException</code> if an error occurs - * while retrieving the value or if the setting doesn't exist. - * - * @param name the name of the property to get. - * @return the Location of a property. - * @throws IllegalArgumentException if an error occurs retrieving the property or the property does not exist. - */ - public static Location getLocation(String name) throws IllegalArgumentException { - return getInstance().getLocationImpl(name); - } - - /** - * Provides an Iterator of all properties names. - * - * @return an Iterator of all properties names. - */ - public static Iterator list() { - return getInstance().listImpl(); - } - - /** - * Implements the {@link #isSet(String)} method. - * - * @param name Identifier for the setting value to change - * @return True if the setting exists and has a value, false otherwise. - * @see #isSet(String) - */ - public boolean isSetImpl(String name) { - // this is dumb.. maybe it should just throw an unsupported op like the rest of the *Impl - // methods in this class. - return false; - } - - /** - * Registers a value for a setting. - * <p> - * This method raises an exception if an error occurs when setting the value or if the - * settings implementation does not support setting values. - * - * @param name the name of the setting. - * @param value the value to register for the setting. - * @throws IllegalArgumentException if an error occurs when setting the value. - * @throws UnsupportedOperationException if the config implementation does not support setting values. - */ - public static void set(String name, String value) throws IllegalArgumentException, UnsupportedOperationException { - getInstance().setImpl(name, value); - } - - /** - * Implements the {@link #set(String, String)} method. - * - * @param name Identifer for the setting to change. - * @param value The new value for the setting. - * @throws IllegalArgumentException if an error occurs when setting the value. - * @throws UnsupportedOperationException if the config implementation does not support setting values. - * @see #set(String, String) - */ - public void setImpl(String name, String value) throws IllegalArgumentException, UnsupportedOperationException { - throw new UnsupportedOperationException("Settings: This implementation does not support setting a value."); - } - - /** - * Implements the {@link #get(String)} method. - * - * @param name The name of the setting value to retreive - * @return The setting value as a String - * @throws IllegalArgumentException if an error occurs when retrieving the value - * @see #get(String) - */ - public String getImpl(String name) throws IllegalArgumentException { - return null; - } - - /** - * Implements the {@link #getLocation(String)} method. + * Returns {@link com.opensymphony.xwork2.util.location.Location} of given setting * * @param name Name of the setting to locate - * @return The location of the setting - * @throws IllegalArgumentException if an error occurs when retrieving the value - * @see #getLocation(String) + * @return The location of the setting or null */ - public Location getLocationImpl(String name) throws IllegalArgumentException { - return null; - } + Location getLocation(String name); /** - * Implements the {@link #list()} method. + * Returns {@link java.util.Iterator} with all values * - * @see #list() * @return A list of the settings as an iterator */ - public Iterator listImpl() { - throw new UnsupportedOperationException("Settings: This implementation does not support listing the registered settings"); - } - - /** - * Creates a default Settings object. - * <p> - * A default implementation may be specified by the <code>struts.configuration</code> setting; - * otherwise, this method instantiates {@link DefaultSettings} as the default implementation. - * - * @return A default Settings object. - */ - private static Settings getDefaultInstance() { - if (defaultImpl == null) { - synchronized (DEFAULT_LOCK) { - if (defaultImpl == null) { - // Create bootstrap implementation - defaultImpl = new DefaultSettings(); - - // Create default implementation - try { - String className = get(StrutsConstants.STRUTS_CONFIGURATION); - - if (!className.equals(defaultImpl.getClass().getName())) { - try { - // singleton instances shouldn't be built accessing request or session-specific context data - defaultImpl = (Settings) ObjectFactory.getObjectFactory().buildBean(Thread.currentThread().getContextClassLoader().loadClass(className), null); - } catch (Exception e) { - LOG.error("Settings: Could not instantiate the struts.configuration object, substituting the default implementation.", e); - } - } - } catch (IllegalArgumentException ex) { - // ignore - } - } - } - } - - return defaultImpl; - } - - /** - * Resets the default and any plugin Setting instance to null. - */ - public static void reset() { - synchronized (DEFAULT_LOCK) { - defaultImpl = null; - } - settingsImpl = null; - } + Iterator list(); } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java Tue Oct 22 13:42:51 2013 @@ -60,7 +60,7 @@ import org.apache.struts2.StrutsExceptio import org.apache.struts2.StrutsStatics; import org.apache.struts2.config.BeanSelectionProvider; import org.apache.struts2.config.DefaultPropertiesProvider; -import org.apache.struts2.config.LegacyPropertiesConfigurationProvider; +import org.apache.struts2.config.PropertiesConfigurationProvider; import org.apache.struts2.config.StrutsXmlConfigurationProvider; import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.apache.struts2.dispatcher.multipart.MultiPartRequest; @@ -374,7 +374,7 @@ public class Dispatcher { } private void init_LegacyStrutsProperties() { - configurationManager.addContainerProvider(new LegacyPropertiesConfigurationProvider()); + configurationManager.addContainerProvider(new PropertiesConfigurationProvider()); } private void init_TraditionalXmlConfigurations() { Copied: struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/PropertiesConfigurationProviderTest.java (from r1534132, struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/LegacyPropertiesConfigurationProviderTest.java) URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/PropertiesConfigurationProviderTest.java?p2=struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/PropertiesConfigurationProviderTest.java&p1=struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/LegacyPropertiesConfigurationProviderTest.java&r1=1534132&r2=1534634&rev=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/LegacyPropertiesConfigurationProviderTest.java (original) +++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/PropertiesConfigurationProviderTest.java Tue Oct 22 13:42:51 2013 @@ -21,24 +21,21 @@ package org.apache.struts2.config; -import java.util.Iterator; -import java.util.Locale; - -import org.apache.struts2.StrutsConstants; -import org.apache.struts2.StrutsTestCase; - +import com.opensymphony.xwork2.inject.Container; +import com.opensymphony.xwork2.inject.ContainerBuilder; import com.opensymphony.xwork2.util.LocalizedTextUtil; import com.opensymphony.xwork2.util.location.LocatableProperties; -import com.opensymphony.xwork2.inject.ContainerBuilder; -import com.opensymphony.xwork2.inject.Container; import junit.framework.TestCase; +import org.apache.struts2.StrutsConstants; + +import java.util.Locale; /** * Unit test for {@link SettingsTest}. * */ -public class LegacyPropertiesConfigurationProviderTest extends TestCase { +public class PropertiesConfigurationProviderTest extends TestCase { public void testRegister_DifferentLocale() { @@ -46,12 +43,13 @@ public class LegacyPropertiesConfigurati builder.constant("foo", "bar"); builder.constant("struts.locale", "DE_de"); - LegacyPropertiesConfigurationProvider prov = new LegacyPropertiesConfigurationProvider(); + PropertiesConfigurationProvider prov = new PropertiesConfigurationProvider(); prov.register(builder, new LocatableProperties()); Container container = builder.create(true); - Locale locale = container.getInstance(Locale.class); + String localeStr = container.getInstance(String.class, StrutsConstants.STRUTS_LOCALE); + Locale locale = LocalizedTextUtil.localeFromString(localeStr, Locale.FRANCE); assertNotNull(locale); assertEquals("DE", locale.getCountry()); @@ -64,16 +62,30 @@ public class LegacyPropertiesConfigurati ContainerBuilder builder = new ContainerBuilder(); builder.constant("foo", "bar"); - LegacyPropertiesConfigurationProvider prov = new LegacyPropertiesConfigurationProvider(); + PropertiesConfigurationProvider prov = new PropertiesConfigurationProvider(); prov.register(builder, new LocatableProperties()); Container container = builder.create(true); - Locale locale = container.getInstance(Locale.class); + String localeStr = container.getInstance(String.class, StrutsConstants.STRUTS_LOCALE); + Locale locale = LocalizedTextUtil.localeFromString(localeStr, Locale.getDefault()); assertNotNull(locale); Locale vmLocale = Locale.getDefault(); assertEquals(locale, vmLocale); } + public void testDefaultSettings() throws Exception { + // given + PropertiesConfigurationProvider prov = new PropertiesConfigurationProvider(); + LocatableProperties props = new LocatableProperties(); + prov.register(new ContainerBuilder(), props); + + // when + Object encoding = props.get(StrutsConstants.STRUTS_I18N_ENCODING); + + // then + assertEquals("ISO-8859-1", encoding); + } + } Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java (original) +++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/SettingsTest.java Tue Oct 22 13:42:51 2013 @@ -21,13 +21,12 @@ package org.apache.struts2.config; -import java.util.Iterator; -import java.util.Locale; - +import com.opensymphony.xwork2.util.LocalizedTextUtil; import org.apache.struts2.StrutsConstants; import org.apache.struts2.StrutsTestCase; -import com.opensymphony.xwork2.util.LocalizedTextUtil; +import java.util.Iterator; +import java.util.Locale; /** @@ -37,34 +36,38 @@ import com.opensymphony.xwork2.util.Loca public class SettingsTest extends StrutsTestCase { public void testSettings() { - assertEquals("12345", Settings.get(StrutsConstants.STRUTS_MULTIPART_MAXSIZE)); - assertEquals("\temp", Settings.get(StrutsConstants.STRUTS_MULTIPART_SAVEDIR)); + Settings settings = new DefaultSettings(); - assertEquals("test,org/apache/struts2/othertest", Settings.get( StrutsConstants.STRUTS_CUSTOM_PROPERTIES)); - assertEquals("testvalue", Settings.get("testkey")); - assertEquals("othertestvalue", Settings.get("othertestkey")); + assertEquals("12345", settings.get(StrutsConstants.STRUTS_MULTIPART_MAXSIZE)); + assertEquals("\temp", settings.get(StrutsConstants.STRUTS_MULTIPART_SAVEDIR)); - int count = getKeyCount(); + assertEquals("test,org/apache/struts2/othertest", settings.get( StrutsConstants.STRUTS_CUSTOM_PROPERTIES)); + assertEquals("testvalue", settings.get("testkey")); + assertEquals("othertestvalue", settings.get("othertestkey")); + + int count = getKeyCount(settings); assertEquals(12, count); } public void testDefaultResourceBundlesLoaded() { - assertEquals("testmessages,testmessages2", Settings.get(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES)); + Settings settings = new DefaultSettings(); + + assertEquals("testmessages,testmessages2", settings.get(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES)); assertEquals("This is a test message", LocalizedTextUtil.findDefaultText("default.testmessage", Locale.getDefault())); assertEquals("This is another test message", LocalizedTextUtil.findDefaultText("default.testmessage2", Locale.getDefault())); } public void testSetSettings() { - Settings.setInstance(new TestSettings()); + Settings settings = new TestSettings(); String keyName = "a.long.property.key.name"; - assertEquals(keyName, Settings.get(keyName)); - assertEquals(2, getKeyCount()); + assertEquals(keyName, settings.get(keyName)); + assertEquals(2, getKeyCount(settings)); } - private int getKeyCount() { + private int getKeyCount(Settings settings) { int count = 0; - Iterator keyNames = Settings.list(); + Iterator keyNames = settings.list(); while (keyNames.hasNext()) { keyNames.next(); Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/TestSettings.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/TestSettings.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/TestSettings.java (original) +++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/config/TestSettings.java Tue Oct 22 13:42:51 2013 @@ -21,6 +21,8 @@ package org.apache.struts2.config; +import com.opensymphony.xwork2.util.location.Location; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -30,25 +32,29 @@ import java.util.List; * TestSettings * */ -public class TestSettings extends Settings { +public class TestSettings implements Settings { /** * Get a named setting. * * @throws IllegalArgumentException if there is no settings parameter with the given name. */ - public String getImpl(String aName) throws IllegalArgumentException { + public String get(String aName) throws IllegalArgumentException { return aName; } /** * List setting names */ - public Iterator listImpl() { + public Iterator list() { List testList = new ArrayList(); testList.add("123"); testList.add("testValue"); return testList.iterator(); } + + public Location getLocation(String name) { + return null; + } } Modified: struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java (original) +++ struts/struts2/trunk/plugins/sitegraph/src/main/java/org/apache/struts2/sitegraph/StrutsConfigRetriever.java Tue Oct 22 13:42:51 2013 @@ -29,7 +29,7 @@ import com.opensymphony.xwork2.util.logg import com.opensymphony.xwork2.util.logging.LoggerFactory; import org.apache.struts2.config.BeanSelectionProvider; import org.apache.struts2.config.DefaultPropertiesProvider; -import org.apache.struts2.config.LegacyPropertiesConfigurationProvider; +import org.apache.struts2.config.PropertiesConfigurationProvider; import org.apache.struts2.config.StrutsXmlConfigurationProvider; import org.apache.struts2.sitegraph.entities.FreeMarkerView; import org.apache.struts2.sitegraph.entities.JspView; @@ -75,7 +75,7 @@ public class StrutsConfigRetriever { cm.addContainerProvider(new DefaultPropertiesProvider()); cm.addContainerProvider(new StrutsXmlConfigurationProvider("struts-default.xml", false, null)); cm.addContainerProvider(configProvider); - cm.addContainerProvider(new LegacyPropertiesConfigurationProvider()); + cm.addContainerProvider(new PropertiesConfigurationProvider()); cm.addContainerProvider(new BeanSelectionProvider()); isXWorkStarted = true; } catch (IOException e) { Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocatableProperties.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocatableProperties.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocatableProperties.java (original) +++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocatableProperties.java Tue Oct 22 13:42:51 2013 @@ -19,18 +19,18 @@ import java.util.Properties; public class LocatableProperties extends Properties implements Locatable { Location location; - Map<String,Location> propLocations; - + Map<String, Location> propLocations; + public LocatableProperties() { - this(null); + this(Location.UNKNOWN); } - + public LocatableProperties(Location loc) { super(); this.location = loc; - this.propLocations = new HashMap<String,Location>(); + this.propLocations = new HashMap<String, Location>(); } - + @Override public void load(InputStream in) throws IOException { Reader reader = new InputStreamReader(in); @@ -40,12 +40,12 @@ public class LocatableProperties extends String val = pr.getPropertyValue(); int line = pr.getLineNumber(); String desc = convertCommentsToString(pr.getCommentLines()); - + Location loc = new LocationImpl(desc, location.getURI(), line, 0); setProperty(name, val, loc); } } - + String convertCommentsToString(List<String> lines) { StringBuilder sb = new StringBuilder(); if (lines != null && lines.size() > 0) { @@ -55,7 +55,7 @@ public class LocatableProperties extends } return sb.toString(); } - + public Object setProperty(String key, String value, Object locationObj) { Object obj = super.setProperty(key, value); if (location != null) { @@ -64,11 +64,16 @@ public class LocatableProperties extends } return obj; } - + public Location getPropertyLocation(String key) { - return propLocations.get(key); + Location loc = propLocations.get(key); + if (loc != null) { + return loc; + } else { + return Location.UNKNOWN; + } } - + public Location getLocation() { return location; } Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocationImpl.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocationImpl.java?rev=1534634&r1=1534633&r2=1534634&view=diff ============================================================================== --- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocationImpl.java (original) +++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/util/location/LocationImpl.java Tue Oct 22 13:42:51 2013 @@ -27,6 +27,7 @@ import java.util.List; * A simple immutable and serializable implementation of {@link Location}. */ public class LocationImpl implements Location, Serializable { + private final String uri; private final int line; private final int column;