cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r510433 - in /cocoon/trunk/core/cocoon-configuration: cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/ cocoon-spring-configurator/src/changes/ cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configur...
Date Thu, 22 Feb 2007 07:43:24 GMT
Author: cziegeler
Date: Wed Feb 21 23:43:23 2007
New Revision: 510433

URL: http://svn.apache.org/viewvc?view=rev&rev=510433
Log:
Add possibility to define default values for a property in the property reference, like ${myproperty:defaultvalue}

Modified:
    cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyHelper.java
    cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/changes/changes.xml
    cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsBeanFactoryPostProcessor.java

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyHelper.java?view=diff&rev=510433&r1=510432&r2=510433
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyHelper.java
(original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-configuration-api/src/main/java/org/apache/cocoon/configuration/PropertyHelper.java
Wed Feb 21 23:43:23 2007
@@ -98,7 +98,32 @@
         return buffer.toString();
     }
 
-    protected static String getProperty(String name, Properties properties, Settings settings)
{
+    /**
+     * Return the value of the property.
+     * If a properties object is provided, this is searched first for a value.
+     * If no value is found and a settings object is provided, the settings object
+     * is searched for a value. If still no value is found, the system properties
+     * are searched.
+     * The key might contain a default value separated by a ':'! If no value is found
+     * and such a default value is provided, the default value is returned.
+     *
+     * @param key The key for the property.
+     * @param properties A set of properties.
+     * @param settings A settings object.
+     * @return Return the value or null.
+     * @since 1.0.1
+     */
+    public static String getProperty(String key, Properties properties, Settings settings)
{
+        final int pos = key.indexOf(':');
+        final String name;
+        final String defaultValue;
+        if ( pos != -1 ) {
+            name = key.substring(0, pos);
+            defaultValue = key.substring(pos+1);
+        } else {
+            name = key;
+            defaultValue = null;
+        }
         String value = null;
         if ( properties != null ) {
             value = properties.getProperty(name);
@@ -112,6 +137,9 @@
             } catch (SecurityException ex) {
                 // ignore this
             }
+        }
+        if ( value == null ) {
+            value = defaultValue;
         }
         return value;
     }

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/changes/changes.xml?view=diff&rev=510433&r1=510432&r2=510433
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/changes/changes.xml
(original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/changes/changes.xml
Wed Feb 21 23:43:23 2007
@@ -24,13 +24,18 @@
     +-->
 <document>
   <body>
-    <release version="1.0.1-M1" date="2007-00-00" description="unreleased">  
+    <release version="1.0.1" date="2007-00-00" description="unreleased">
+     <action dev="cziegeler" type="add">
+       Each property reference can have an optional default value, like
+       ${my.property.net:THE DEFAULT}. If no other definition for this
+       property is found, the default is used.
+     </action>  
      <action dev="cziegeler" type="add">
        Add a bean map that collects all beans from the Spring context
        conforming to a specified type.
      </action>
     </release>
-    <release version="1.0.0-M1" date="2007-00-00" description="unreleased">  
+    <release version="1.0.0" date="2007-00-00" description="unreleased">  
      <action dev="cziegeler" type="add">
         Improved the DefaultBlockResourcesHolder to act like a PropertyPlaceholderConfigurer.
         This allows access to the path of the deployed blocks in the configuration files

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsBeanFactoryPostProcessor.java?view=diff&rev=510433&r1=510432&r2=510433
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsBeanFactoryPostProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-spring-configurator/src/main/java/org/apache/cocoon/spring/configurator/impl/AbstractSettingsBeanFactoryPostProcessor.java
Wed Feb 21 23:43:23 2007
@@ -280,11 +280,17 @@
             try {
                 visitor.visitBeanDefinition(bd);
             } catch (BeanDefinitionStoreException ex) {
-                throw new BeanDefinitionStoreException(bd
-                        .getResourceDescription(), beanNames[i], ex
-                        .getMessage());
+                throw new BeanDefinitionStoreException(bd.getResourceDescription(),
+                        beanNames[i], ex.getMessage());
             }
         }
+    }
+
+    /**
+     * @see org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#resolvePlaceholder(java.lang.String,
java.util.Properties)
+     */
+    protected String resolvePlaceholder(String placeholder, Properties props) {
+        return PropertyHelper.getProperty(placeholder, props, null);
     }
 
     protected class CocoonSettingsResolvingBeanDefinitionVisitor



Mime
View raw message