From c4e941cfa517724ffbd9b12d0f505467fd9cd159 Mon Sep 17 00:00:00 2001 From: remillet Date: Thu, 14 Jul 2016 16:46:31 -0700 Subject: [PATCH] CSPACE-6973: Adding enhancement for property variable support. --- .../services/common/api/Tools.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java index 52b5ebaeb..9981244a6 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/Tools.java @@ -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; + } } -- 2.47.3