Author: mrdon
Date: Fri Nov 17 02:56:40 2006
New Revision: 476106
URL: http://svn.apache.org/viewvc?view=rev&rev=476106
Log:
Adding location-aware properties file loading
WW-1510 XW-436
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/LegacyPropertiesConfigurationProvider.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/config/StrutsXmlConfigurationProvider.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
struts/struts2/trunk/core/src/test/java/org/apache/struts2/TestConfigurationProvider.java
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java?view=diff&rev=476106&r1=476105&r2=476106
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/BeanSelectionProvider.java
Fri Nov 17 02:56:40 2006
@@ -46,6 +46,7 @@
import com.opensymphony.xwork2.util.ObjectTypeDeterminer;
import com.opensymphony.xwork2.util.ObjectTypeDeterminerFactory;
import com.opensymphony.xwork2.util.XWorkConverter;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
/**
* Selects the implementations of key framework extension points, using the
loaded
@@ -148,7 +149,7 @@
return false;
}
- public void register(ContainerBuilder builder, Properties props) {
+ public void register(ContainerBuilder builder, LocatableProperties props) {
alias(ObjectFactory.class, StrutsConstants.STRUTS_OBJECTFACTORY,
builder, props);
alias(XWorkConverter.class, StrutsConstants.STRUTS_XWORKCONVERTER,
builder, props);
alias(ActionProxyFactory.class,
StrutsConstants.STRUTS_ACTIONPROXYFACTORY, builder, props);
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java?view=diff&rev=476106&r1=476105&r2=476106
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
Fri Nov 17 02:56:40 2006
@@ -44,6 +44,7 @@
import com.opensymphony.xwork2.util.ResolverUtil;
import com.opensymphony.xwork2.util.TextUtils;
import com.opensymphony.xwork2.util.ResolverUtil.Test;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
/**
* Loads the configuration by scanning the classpath looking for classes that
end in
@@ -370,7 +371,7 @@
}
}
- public void register(ContainerBuilder builder, Properties props) throws
ConfigurationException {
+ public void register(ContainerBuilder builder, LocatableProperties props)
throws ConfigurationException {
// Nothing
}
}
Modified:
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/LegacyPropertiesConfigurationProvider.java?view=diff&rev=476106&r1=476105&r2=476106
==============================================================================
---
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/LegacyPropertiesConfigurationProvider.java
Fri Nov 17 02:56:40 2006
@@ -40,6 +40,7 @@
import com.opensymphony.xwork2.inject.Context;
import com.opensymphony.xwork2.inject.Factory;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
public class LegacyPropertiesConfigurationProvider implements
ConfigurationProvider {
@@ -60,7 +61,7 @@
return false;
}
- public void register(ContainerBuilder builder, Properties props)
+ public void register(ContainerBuilder builder, LocatableProperties props)
throws ConfigurationException {
final Settings settings = Settings.getInstance();
@@ -69,7 +70,7 @@
String name = (String) i.next();
props.put(name, settings.get(name));
if (StrutsConstants.STRUTS_DEVMODE.equals(name)) {
- props.put("devMode", settings.get(name));
+ props.setProperty("devMode", 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?view=diff&rev=476106&r1=476105&r2=476106
==============================================================================
---
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
Fri Nov 17 02:56:40 2006
@@ -29,13 +29,17 @@
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.StrutsException;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
+import com.opensymphony.xwork2.util.location.Location;
+import com.opensymphony.xwork2.util.location.LocationImpl;
+
/**
* A class to handle settings via a properties file.
*/
class PropertiesSettings extends Settings {
- Properties settings;
+ LocatableProperties settings;
static Log LOG = LogFactory.getLog(PropertiesSettings.class);
@@ -47,14 +51,15 @@
* @param name the name of the properties file, excluding the
".properties" extension.
*/
public PropertiesSettings(String name) {
- settings = new Properties();
-
+
URL settingsUrl =
Thread.currentThread().getContextClassLoader().getResource(name +
".properties");
-
+
if (settingsUrl == null) {
LOG.debug(name + ".properties missing");
return;
}
+
+ settings = new LocatableProperties(new LocationImpl(null,
settingsUrl.toString()));
// Load settings
try {
@@ -87,6 +92,23 @@
}
return setting;
+ }
+
+ /**
+ * Gets the location of a property from the properties file.
+ *
+ * @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;
}
/**
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?view=diff&rev=476106&r1=476105&r2=476106
==============================================================================
---
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
Fri Nov 17 02:56:40 2006
@@ -29,6 +29,7 @@
import org.apache.struts2.StrutsConstants;
import com.opensymphony.xwork2.ObjectFactory;
+import com.opensymphony.xwork2.util.location.Location;
/**
@@ -131,13 +132,27 @@
*
* @param name the name of the property to get.
* @return the property as an Object.
- * @throws IllegalArgumentException if an error occurs retrieveing the
property or the property does not exist.
+ * @throws IllegalArgumentException if an error occurs retrieving the
property or the property does not exist.
*/
public static String get(String name) throws IllegalArgumentException {
String val = getInstance().getImpl(name);
return val;
}
+
+ /**
+ * Returns the location of a a property. This will throw an
<tt>IllegalArgumentException</tt> if an error occurs
+ * while retrieveing the property or if the property 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 {
+ Location loc = getInstance().getLocationImpl(name);
+
+ return loc;
+ }
/**
* Returns an Iterator of all properties names.
@@ -187,6 +202,15 @@
* @see #get(String)
*/
public String getImpl(String aName) throws IllegalArgumentException {
+ return null;
+ }
+
+ /**
+ * Implementation of the [EMAIL PROTECTED] #getLocation(String)} method.
+ *
+ * @see #getLocation(String)
+ */
+ public Location getLocationImpl(String aName) throws
IllegalArgumentException {
return null;
}
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java?view=diff&rev=476106&r1=476105&r2=476106
==============================================================================
---
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
(original)
+++
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/StrutsXmlConfigurationProvider.java
Fri Nov 17 02:56:40 2006
@@ -42,6 +42,7 @@
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;
/**
* Override Xwork class so we can use an arbitrary config file
@@ -88,7 +89,7 @@
* @see
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider#register(com.opensymphony.xwork2.inject.ContainerBuilder,
java.util.Properties)
*/
@Override
- public void register(ContainerBuilder containerBuilder, Properties props)
throws ConfigurationException {
+ public void register(ContainerBuilder containerBuilder,
LocatableProperties props) throws ConfigurationException {
if (servletContext != null &&
!containerBuilder.contains(ServletContext.class)) {
containerBuilder.factory(ServletContext.class, new Factory() {
public Object create(Context context) throws Exception {
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?view=diff&rev=476106&r1=476105&r2=476106
==============================================================================
---
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
Fri Nov 17 02:56:40 2006
@@ -77,6 +77,7 @@
import com.opensymphony.xwork2.util.XWorkContinuationConfig;
import com.opensymphony.xwork2.util.location.Location;
import com.opensymphony.xwork2.util.location.LocationUtils;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
import com.opensymphony.xwork2.util.profiling.UtilTimerStack;
import freemarker.template.Template;
@@ -328,7 +329,7 @@
public void loadPackages() throws ConfigurationException {}
public boolean needsReload() { return false; }
- public void register(ContainerBuilder builder, Properties props)
throws ConfigurationException {
+ public void register(ContainerBuilder builder, LocatableProperties
props) throws ConfigurationException {
props.putAll(initParams);
}
});
Modified:
struts/struts2/trunk/core/src/test/java/org/apache/struts2/TestConfigurationProvider.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/TestConfigurationProvider.java?view=diff&rev=476106&r1=476105&r2=476106
==============================================================================
---
struts/struts2/trunk/core/src/test/java/org/apache/struts2/TestConfigurationProvider.java
(original)
+++
struts/struts2/trunk/core/src/test/java/org/apache/struts2/TestConfigurationProvider.java
Fri Nov 17 02:56:40 2006
@@ -45,6 +45,7 @@
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.interceptor.ParametersInterceptor;
import com.opensymphony.xwork2.mock.MockResult;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
/**
@@ -163,7 +164,7 @@
return false;
}
- public void register(ContainerBuilder builder, Properties props) throws
ConfigurationException {
+ public void register(ContainerBuilder builder, LocatableProperties props)
throws ConfigurationException {
if (!builder.contains(ObjectFactory.class)) {
builder.factory(ObjectFactory.class);
}
Modified:
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java?view=diff&rev=476106&r1=476105&r2=476106
==============================================================================
---
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java
(original)
+++
struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/ExecuteAndWaitInterceptorTest.java
Fri Nov 17 02:56:40 2006
@@ -50,6 +50,7 @@
import com.opensymphony.xwork2.inject.ContainerBuilder;
import com.opensymphony.xwork2.interceptor.ParametersInterceptor;
import com.opensymphony.xwork2.mock.MockResult;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
/**
* Test case for ExecuteAndWaitInterceptor.
@@ -232,7 +233,7 @@
configuration.addPackageConfig("", wait);
}
- public void register(ContainerBuilder builder, Properties props)
throws ConfigurationException {
+ public void register(ContainerBuilder builder, LocatableProperties
props) throws ConfigurationException {
builder.factory(ObjectFactory.class);
builder.factory(ActionProxyFactory.class,
DefaultActionProxyFactory.class);
}