]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6973: Adding enhancement for property variable support.
authorremillet <remillet@yahoo.com>
Thu, 14 Jul 2016 23:46:31 +0000 (16:46 -0700)
committerremillet <remillet@yahoo.com>
Thu, 14 Jul 2016 23:46:31 +0000 (16:46 -0700)
services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java

index 52b5ebaebe491f0bc35673976ceb21edc45f26c3..9981244a6cd4d4652a187da1735c0234a162b343 100644 (file)
@@ -34,6 +34,9 @@ import java.util.regex.Matcher;
  * v.1.4
  */
 public class Tools {
+       
+       private static final String PROPERTY_VAR_REGEX = "\\$\\{([A-Za-z0-9_\\.]+)\\}";
+       
     /** @return first glued to second with the separator string, at most one time - useful for appending paths.
      */
     public static String glue(String first, String separator, String second){
@@ -357,7 +360,7 @@ public class Tools {
                // Replace things like ${cspace.password.cow} with values from either the environment
                // or from the JVM system properties.
                //
-               Pattern pattern = Pattern.compile("\\$\\{([A-Za-z0-9_\\.]+)\\}");       // For example, "${cspace.password.mysecret}" or "${password_strong_longpassword}"
+               Pattern pattern = Pattern.compile(PROPERTY_VAR_REGEX);          // For example, "${cspace.password.mysecret}" or "${password_strong_longpassword}"
                Matcher matcher = pattern.matcher(propertyValue);
                String key = null;      
                if (matcher.find()) {
@@ -380,4 +383,23 @@ public class Tools {
                
                return result;
        }
+       
+       /**
+        * Test to see if 'propertyValue' is actually a property variable
+        * @param propertyValue
+        * @return
+        */
+       static public boolean isValuePropretyVar(String propertyValue) {
+               boolean result = false;
+               
+               if (propertyValue != null) {
+                       Pattern pattern = Pattern.compile(PROPERTY_VAR_REGEX);          // For example, "${cspace.password.mysecret}" or "${password_strong_longpassword}"
+                       Matcher matcher = pattern.matcher(propertyValue);
+                       if (matcher.find()) {
+                               result = true;
+                       }
+               }
+               
+               return result;
+       }
 }