cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r424946 - in /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon: components/treeprocessor/sitemap/SitemapLanguage.java configuration/impl/PropertyHelper.java configuration/impl/SettingsHelper.java
Date Mon, 24 Jul 2006 07:27:15 GMT
Author: cziegeler
Date: Mon Jul 24 00:27:15 2006
New Revision: 424946

URL: http://svn.apache.org/viewvc?rev=424946&view=rev
Log:
Property values can now contain references to other properties

Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/PropertyHelper.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/SettingsHelper.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?rev=424946&r1=424945&r2=424946&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
Mon Jul 24 00:27:15 2006
@@ -423,6 +423,7 @@
             settings = this.createSettings(settings, propertyDir, useDefaultIncludes, factory.getCurrentBeanFactory(itsContext),
globalSitemapVariables);
         } else if ( globalSitemapVariables != null ) {
             MutableSettings s = new MutableSettings(settings);
+            PropertyHelper.replaceAll(globalSitemapVariables, settings);
             s.configure(globalSitemapVariables);
             settings = s;
         }
@@ -1195,6 +1196,7 @@
         if ( globalSitemapVariables != null ) {
             properties.putAll(globalSitemapVariables);
         }
+        PropertyHelper.replaceAll(properties, parent);
         s.configure(properties);
 
         return s;

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/PropertyHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/PropertyHelper.java?rev=424946&r1=424945&r2=424946&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/PropertyHelper.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/PropertyHelper.java
Mon Jul 24 00:27:15 2006
@@ -16,6 +16,9 @@
  */
 package org.apache.cocoon.configuration.impl;
 
+import java.util.Iterator;
+import java.util.Properties;
+
 import org.apache.cocoon.configuration.Settings;
 
 /**
@@ -32,6 +35,14 @@
      * and return it.
      */
     public static String replace(String value, Settings settings) {
+        return replace(value, null, settings);
+    }
+
+    /**
+     * Replace all property references in the string with the current value
+     * and return it.
+     */
+    public static String replace(String value, Properties properties, Settings settings)
{
         // quick test for null or no references
         if ( value == null || value.indexOf("${") == -1 ) {
             return value;
@@ -67,7 +78,7 @@
                     prev = value.length();
                 } else {
                     final String propertyName = value.substring(pos + 2, endName);
-                    String propertyValue = getProperty(propertyName, settings);
+                    String propertyValue = getProperty(propertyName, properties, settings);
                     // compatibility fallback - if the value is null, just readd token
                     if (propertyValue == null) {
                         buffer.append("${");
@@ -88,9 +99,12 @@
         return buffer.toString();
     }
 
-    protected static String getProperty(String name, Settings settings) {
+    protected static String getProperty(String name, Properties properties, Settings settings)
{
         String value = null;
-        if ( settings != null ) {
+        if ( properties != null ) {
+            value = properties.getProperty(name);
+        }
+        if ( value == null && settings != null ) {
             value = settings.getProperty(name);
         }
         if ( value == null ) {
@@ -101,5 +115,25 @@
             }
         }
         return value;
+    }
+
+    /**
+     * Replace all references in the values contained in the properties.
+     * If the reference is not found in the properties it is searched in
+     * the settings.
+     * @param props
+     * @param settings
+     */
+    public static void replaceAll(Properties props, Settings settings) {
+       final Iterator kI = props.keySet().iterator();
+       while ( kI.hasNext() ) {
+           final String key = (String)kI.next();
+           // get value
+           String value = props.getProperty(key);
+           // replace
+           value = replace(value, props, settings);
+           // and put back
+           props.put(key, value);
+       }
     }
 }

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/SettingsHelper.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/SettingsHelper.java?rev=424946&r1=424945&r2=424946&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/SettingsHelper.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/configuration/impl/SettingsHelper.java
Mon Jul 24 00:27:15 2006
@@ -156,6 +156,7 @@
         } catch (SecurityException se) {
             // we ignore this
         }
+        PropertyHelper.replaceAll(properties, null);
         s.configure(properties);
 
         return s;



Mime
View raw message