airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samin...@apache.org
Subject git commit: https://issues.apache.org/jira/browse/AIRAVATA-1047
Date Sat, 08 Mar 2014 22:54:04 GMT
Repository: airavata
Updated Branches:
  refs/heads/master 7b61c4801 -> 53acbbde5


https://issues.apache.org/jira/browse/AIRAVATA-1047


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/53acbbde
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/53acbbde
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/53acbbde

Branch: refs/heads/master
Commit: 53acbbde5d290d7aca927c4d3b5ed82aa7de7eb9
Parents: 7b61c48
Author: Saminda Wijeratne <samindaw@gmail.com>
Authored: Sat Mar 8 17:53:25 2014 -0500
Committer: Saminda Wijeratne <samindaw@gmail.com>
Committed: Sat Mar 8 17:53:25 2014 -0500

----------------------------------------------------------------------
 .../common/utils/ApplicationSettings.java       | 36 +++++++++++++++-----
 .../airavata/common/utils/StringUtil.java       | 20 +++++++++++
 2 files changed, 47 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/53acbbde/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
----------------------------------------------------------------------
diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
index 715c7d2..54225fa 100644
--- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
+++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/ApplicationSettings.java
@@ -103,14 +103,6 @@ public abstract class ApplicationSettings {
     		throw new ApplicationSettingsLoadException(propertyLoadException);
     	}
     }
-    
-    public static String getSetting(String key) throws ApplicationSettingsException{
-    	validateSuccessfulPropertyFileLoad();
-    	if (properties.containsKey(key)){
-    		return properties.getProperty(key);
-    	}
-    	throw new UnspecifiedApplicationSettingsException(key);
-    }
 
     /**
      * Returns the configuration value relevant for the given key.
@@ -121,6 +113,7 @@ public abstract class ApplicationSettings {
      * @return The configuration value. For above example caller will get a value like
      * http://192.2.33.12:8080/axis2/services/RegistryService?wsdl
      * @throws ApplicationSettingsException If an error occurred while reading configurations.
+     * @deprecated use #getSetting(String) instead
      */
     public static String getAbsoluteSetting(String key) throws ApplicationSettingsException
{
 
@@ -157,17 +150,41 @@ public abstract class ApplicationSettings {
         return matches;
     }
     
+    public static String getSetting(String key) throws ApplicationSettingsException{
+    	validateSuccessfulPropertyFileLoad();
+    	if (properties.containsKey(key)){
+    		return deriveAbsoluteValue(properties.getProperty(key));
+    	}
+    	throw new UnspecifiedApplicationSettingsException(key);
+    }
+    
     public static String getSetting(String key, String defaultValue){
     	try {
 			validateSuccessfulPropertyFileLoad();
 			if (properties.containsKey(key)){
-				return properties.getProperty(key);
+				return deriveAbsoluteValue(properties.getProperty(key));
 			}
 		} catch (ApplicationSettingsException e) {
 			//we'll ignore this error since a default value is provided
 		}
 		return defaultValue;
     }
+
+	private static String deriveAbsoluteValue(String property) {
+		if (property!=null){
+			Map<Integer, String> containedParameters = StringUtil.getContainedParameters(property);
+			List<String> parametersAlreadyProcessed=new ArrayList<String>();
+			for (String parameter : containedParameters.values()) {
+				if (!parametersAlreadyProcessed.contains(parameter)) {
+					String parameterName = parameter.substring(2,parameter.length() - 1);
+					String parameterValue = getSetting(parameterName,parameter);
+					property = property.replaceAll(Pattern.quote(parameter), parameterValue);
+					parametersAlreadyProcessed.add(parameter);
+				}
+			}
+		}
+		return property;
+	}
     
     public static void setSetting(String key, String value) throws ApplicationSettingsException{
     	properties.setProperty(key, value);
@@ -289,4 +306,5 @@ public abstract class ApplicationSettings {
 			}
 		}
 	}
+	
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/53acbbde/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java
----------------------------------------------------------------------
diff --git a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java
b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java
index 0ea3867..d4eda58 100644
--- a/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java
+++ b/modules/commons/utils/src/main/java/org/apache/airavata/common/utils/StringUtil.java
@@ -24,7 +24,9 @@ package org.apache.airavata.common.utils;
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -32,6 +34,24 @@ public class StringUtil {
 	public static final String DELIMETER=",";
 	public static final String QUOTE="\"";
 	
+	public static Map<Integer, String> getContainedParameters(String s) {
+		Map<Integer,String> parameterMap=new HashMap<Integer,String>();
+		int i=0;
+		for(i=0;i<s.length();i++){
+			if (s.charAt(i)=='$' && (i+1)<s.length() && s.charAt(i+1)=='{'){
+				int i2=s.indexOf('{', i+2);
+				int e=s.indexOf('}', i+2);
+				if (e!=-1){
+					if (i2==-1 || e<i2){
+						parameterMap.put(i, s.substring(i,e+1));
+						i=e;
+					}
+				}
+			}
+		}
+		return parameterMap;
+	}
+	
 	// Merits for the following function should go to 
 	// http://blog.houen.net/java-get-url-from-string/ 
 	public static List<String> getURLS(String text) {


Mime
View raw message