From: remillet Date: Thu, 14 Jul 2016 23:46:31 +0000 (-0700) Subject: CSPACE-6973: Adding enhancement for property variable support. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=c4e941cfa517724ffbd9b12d0f505467fd9cd159;p=tmp%2Fjakarta-migration.git CSPACE-6973: Adding enhancement for property variable support. --- 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; + } }