Author: ate
Date: Fri Apr 18 04:40:38 2008
New Revision: 649469
URL: http://svn.apache.org/viewvc?rev=649469&view=rev
Log:
Adding correct usage of the "override" behavior for override.properties.
Loading property files with Commons Configuration using the "include" construct
does *not* provide real override behavior, but instead *appends* values of
duplicate keys!!!
This bean (for usage within the Spring assembly) fixes this by loading the
defined property files individually and using the Commons ConfigurationUtils to
*copy* the values.
NB: the JetspeedServlet currently uses similar "incorrect" loading of the
jetspeed.properties+override.properties, which I will correct as well (as well
as adding many more improvements).
Added:
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/ConfigurationProperties.java
(with props)
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/
(props changed)
Propchange:
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Apr 18 04:40:38 2008
@@ -1,2 +1,2 @@
-target
+target
surefire*.properties
Added:
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/ConfigurationProperties.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/ConfigurationProperties.java?rev=649469&view=auto
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/ConfigurationProperties.java
(added)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/ConfigurationProperties.java
Fri Apr 18 04:40:38 2008
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.components.util;
+
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.commons.configuration.ConfigurationUtils;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.core.io.Resource;
+
+/**
+ * <p>
+ * ConfigurationProperties is a Spring wrapper for Commons
PropertiesConfiguration
+ * allowing loading multiple properties files with overriding behavior as well
as
+ * predefining local/inline properties to be loaded first.
+ * </p>
+ * <p>
+ * Multiple properties files are loaded in sequence of definition and
<em>copied</em>
+ * over each other, instead of being added/appended as Commons Configuration
does by default
+ * when multiple definitions of the same property key is loaded.
+ * </p>
+ * @version $Id$
+ *
+ */
+public class ConfigurationProperties extends PropertiesConfiguration
implements InitializingBean
+{
+ private Resource[] locations;
+ private Properties[] localProperties;
+
+ public void setProperties(Properties properties) {
+ this.localProperties = new Properties[] {properties};
+ }
+
+ public void setLocation(Resource location) {
+ this.locations = new Resource[] {location};
+ }
+
+ public void setLocations(Resource[] locations) {
+ this.locations = locations;
+ }
+
+ public void afterPropertiesSet() throws Exception
+ {
+ if (localProperties != null)
+ {
+ for (Properties props : localProperties)
+ {
+ for (Map.Entry entry : props.entrySet())
+ {
+ setProperty((String)entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ if (this.locations != null)
+ {
+ for (int i = 0; i < this.locations.length; i++)
+ {
+ Resource location = this.locations[i];
+ InputStream is = null;
+ try
+ {
+ is = location.getInputStream();
+ PropertiesConfiguration config = this;
+ if (i > 0)
+ {
+ config = new PropertiesConfiguration();
+ }
+ config.load(is);
+ if (i > 0)
+ {
+ ConfigurationUtils.copy(config,this);
+ config.clear();
+ }
+ }
+ finally
+ {
+ if (is != null)
+ {
+ is.close();
+ }
+ }
+ }
+ }
+ }
+}
Propchange:
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/ConfigurationProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/ConfigurationProperties.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange:
portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/util/ConfigurationProperties.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]