cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r1171046 - /cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java
Date Thu, 15 Sep 2011 10:48:21 GMT
Author: thorsten
Date: Thu Sep 15 10:48:21 2011
New Revision: 1171046

URL: http://svn.apache.org/viewvc?rev=1171046&view=rev
Log:
Extending the class which is a replacement for the former avalon parameters.

Modified:
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java

Modified: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java?rev=1171046&r1=1171045&r2=1171046&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/pipeline/components/parameters/Parameters.java
Thu Sep 15 10:48:21 2011
@@ -17,13 +17,14 @@
 package org.apache.cocoon.pipeline.components.parameters;
 
 import java.util.Map;
+import java.util.Set;
 
 public class Parameters {
 
     private Map<String, ? extends Object> values;
 
     public Parameters(Map<String, ? extends Object> configuration) {
-        this.values = configuration;
+        values = configuration;
     }
 
     public int getAsInteger(String key, int defaultValue) {
@@ -61,4 +62,64 @@ public class Parameters {
 
         return Long.valueOf((String) value);
     }
+
+    public Object getParameter(String name, Object defaultValue) {
+        if (name == null) {
+            return defaultValue;
+        }
+
+        final Object test = this.values.get(name);
+
+        if (test == null) {
+            return defaultValue;
+        } else {
+            return test;
+        }
+    }
+
+    public boolean getParameterAsBoolean(final String name,
+            final boolean defaultValue) {
+        final String value = (String) getParameter(name, null);
+        if (value == null) {
+            return defaultValue;
+        }
+        if (value.equalsIgnoreCase("true")) {
+            return true;
+        } else if (value.equalsIgnoreCase("false")) {
+            return false;
+        } else {
+            return defaultValue;
+        }
+    }
+
+    public Parameters merge(final Parameters other) {
+        for (String name :  other.keySet()) {
+            Object value = null;
+            try {
+                value = other.getParameter(name, null);
+            } catch (final Exception pe) {
+                value = null;
+            }
+            setParameter(name, value);
+        }
+        
+        return this;
+    }
+
+    private  Set<String> keySet() {
+        return this.values.keySet();
+    }
+
+    @SuppressWarnings("unchecked")
+    public String setParameter(String name, Object value) {
+        if (null == name) {
+            return null;
+        }
+        if (null == value) {
+            return (String) this.values.remove(name);
+        }
+        return (String) ((Map<String, Object>)values).put(name, value);
+
+    }
+
 }



Mime
View raw message