You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ga...@apache.org on 2005/09/12 01:50:14 UTC
svn commit: r280215 - in /incubator/roller/trunk:
src/org/roller/business/FileManagerImpl.java
src/org/roller/business/IndexManagerImpl.java
src/org/roller/config/RollerConfig.java web/WEB-INF/classes/roller.properties
Author: gangolli
Date: Sun Sep 11 16:50:09 2005
New Revision: 280215
URL: http://svn.apache.org/viewcvs?rev=280215&view=rev
Log:
Part 2 of checkin for ROL-613. Expand system properties in configuration property values after loading in RollerConfig. The list of configuration properties whose values get the expansion treatment is itself controlled by a configuration property config.expandedProperties that is defined in the roller.properties file. Remove the specific expansions in FileManagerImpl and IndexManagerImpl.
Modified:
incubator/roller/trunk/src/org/roller/business/FileManagerImpl.java
incubator/roller/trunk/src/org/roller/business/IndexManagerImpl.java
incubator/roller/trunk/src/org/roller/config/RollerConfig.java
incubator/roller/trunk/web/WEB-INF/classes/roller.properties
Modified: incubator/roller/trunk/src/org/roller/business/FileManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/FileManagerImpl.java?rev=280215&r1=280214&r2=280215&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/FileManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/roller/business/FileManagerImpl.java Sun Sep 11 16:50:09 2005
@@ -37,20 +37,17 @@
/**
* Create file manager.
- * @param roller Roller instance.
- * @param realPath Path to Servlet context directory
*/
public FileManagerImpl()
{
String uploaddir = RollerConfig.getProperty("uploads.dir");
String uploadurl = RollerConfig.getProperty("uploads.url");
-
+
+ // Note: System property expansion is now handled by RollerConfig.
+
if(uploaddir == null || uploaddir.trim().length() < 1)
- uploaddir = "${user.home}"+File.separator+"roller_data"+File.separator+"uploads";
-
- if(uploaddir.startsWith("${user.home}"))
- uploaddir = System.getProperty("user.home") + uploaddir.substring(12);
-
+ uploaddir = System.getProperty("user.home") + File.separator+"roller_data"+File.separator+"uploads";
+
if( ! uploaddir.endsWith(File.separator))
uploaddir += File.separator;
Modified: incubator/roller/trunk/src/org/roller/business/IndexManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/IndexManagerImpl.java?rev=280215&r1=280214&r2=280215&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/IndexManagerImpl.java (original)
+++ incubator/roller/trunk/src/org/roller/business/IndexManagerImpl.java Sun Sep 11 16:50:09 2005
@@ -88,13 +88,8 @@
this.searchEnabled = false;
// we also need to know what our index directory is
+ // Note: system property expansion is now handled by RollerConfig
String indexDir = RollerConfig.getProperty("search.index.dir");
- if (indexDir.indexOf("${user.home}") != -1)
- {
- indexDir = StringUtils.replace(
- indexDir, "${user.home}",
- System.getProperty("user.home"));
- }
this.indexDir = indexDir.replace('/', File.separatorChar);
Modified: incubator/roller/trunk/src/org/roller/config/RollerConfig.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/config/RollerConfig.java?rev=280215&r1=280214&r2=280215&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/config/RollerConfig.java (original)
+++ incubator/roller/trunk/src/org/roller/config/RollerConfig.java Sun Sep 11 16:50:09 2005
@@ -12,9 +12,11 @@
import java.io.StringWriter;
import java.util.Enumeration;
import java.util.Properties;
+import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.roller.util.PropertyExpander;
/**
@@ -24,35 +26,35 @@
* @author Allen Gilliland
*/
public class RollerConfig {
-
+
private static String default_config = "/roller.properties";
private static String custom_config = "/roller-custom.properties";
private static String custom_jvm_param = "roller.custom.config";
private static File custom_config_file = null;
-
+
private static Properties mConfig;
-
+
private static Log mLogger =
LogFactory.getFactory().getInstance(RollerConfig.class);
-
-
+
+
/*
- * Static block run once at class loading
- *
- * We load the default properties and any custom properties we find
- */
+ * Static block run once at class loading
+ *
+ * We load the default properties and any custom properties we find
+ */
static {
mConfig = new Properties();
-
+
try {
// we'll need this to get at our properties files in the classpath
Class config_class = Class.forName("org.roller.config.RollerConfig");
-
+
// first, lets load our default properties
InputStream is = config_class.getResourceAsStream(default_config);
mConfig.load(is);
mLogger.info("successfully loaded default properties.");
-
+
// now, see if we can find our custom config
is = config_class.getResourceAsStream(custom_config);
if(is != null) {
@@ -61,12 +63,12 @@
} else {
mLogger.info("no custom properties file found in classpath");
}
-
+
// finally, check for an external config file
String env_file = System.getProperty(custom_jvm_param);
if(env_file != null && env_file.length() > 0) {
custom_config_file = new File(env_file);
-
+
// make sure the file exists, then try and load it
if(custom_config_file != null && custom_config_file.exists()) {
is = new FileInputStream(custom_config_file);
@@ -77,15 +79,34 @@
mLogger.warn("failed to load custom properties from "+
custom_config_file.getAbsolutePath());
}
-
+
} else {
mLogger.info("no custom properties file specified via jvm option");
}
-
+
+ // Now expand system properties for properties in the config.expandedProperties list,
+ // replacing them by their expanded values.
+ String expandedPropertiesDef = (String) mConfig.get("config.expandedProperties");
+ if (expandedPropertiesDef != null) {
+ String[] expandedProperties = expandedPropertiesDef.split(",");
+ for (int i = 0; i < expandedProperties.length; i++) {
+ String propName = expandedProperties[i].trim();
+ String initialValue = (String) mConfig.get(propName);
+ if (initialValue != null) {
+ String expandedValue = PropertyExpander.expandSystemProperties(initialValue);
+ mConfig.put(propName,expandedValue);
+ if (mLogger.isDebugEnabled()) {
+ mLogger.info("Expanded value of " + propName + " from '" +
+ initialValue + "' to '" + expandedValue + "'");
+ }
+ }
+ }
+ }
+
// some debugging for those that want it
if(mLogger.isDebugEnabled()) {
mLogger.debug("RollerConfig looks like this ...");
-
+
String key = null;
Enumeration keys = mConfig.keys();
while(keys.hasMoreElements()) {
@@ -93,18 +114,18 @@
mLogger.debug(key+"="+mConfig.getProperty(key));
}
}
-
+
} catch (Exception e) {
e.printStackTrace();
}
-
+
}
-
-
+
+
// no, you may not instantiate this class :p
private RollerConfig() {}
-
-
+
+
/**
* Retrieve a property value
*
@@ -115,23 +136,23 @@
mLogger.debug("Fetching property ["+key+"="+mConfig.getProperty(key)+"]");
return mConfig.getProperty(key);
}
-
-
+
+
/**
* Retrieve a property as a boolean ... defaults to false if there is an error
**/
public static boolean getBooleanProperty(String name) {
-
+
// get the value first, then convert
String value = RollerConfig.getProperty(name);
-
+
if(value == null)
return false;
-
+
return (new Boolean(value)).booleanValue();
}
-
-
+
+
/**
* Retrieve all property keys
*
@@ -140,8 +161,8 @@
public static Enumeration keys() {
return mConfig.keys();
}
-
-
+
+
/**
* Set the "uploads.dir" property at runtime.
*
@@ -150,13 +171,13 @@
* uploads to the webapp context and we can only get that path at runtime.
*/
public static void setUploadsDir(String path) {
-
+
// only do this if the user wants to use the webapp context
if("${webapp.context}".equals(mConfig.getProperty("uploads.dir")))
mConfig.setProperty("uploads.dir", path);
}
-
-
+
+
/**
* Set the "context.realpath" property at runtime.
*
@@ -167,8 +188,8 @@
* This property is *not* persisted in any way.
*/
public static void setContextPath(String path) {
-
+
mConfig.setProperty("context.realpath", path);
}
-
+
}
Modified: incubator/roller/trunk/web/WEB-INF/classes/roller.properties
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/web/WEB-INF/classes/roller.properties?rev=280215&r1=280214&r2=280215&view=diff
==============================================================================
--- incubator/roller/trunk/web/WEB-INF/classes/roller.properties (original)
+++ incubator/roller/trunk/web/WEB-INF/classes/roller.properties Sun Sep 11 16:50:09 2005
@@ -24,6 +24,14 @@
# properties in this file are accessed like this ...
# RollerConfig.getProperty("propname");
+
+#---------------------------------
+# Property expansion settings
+
+## Values of the properties in this list get system property expansion applied to them when loaded.
+config.expandedProperties=uploads.dir,search.index.dir
+
+
#----------------------------------
# Upload settings