public static string replaceTokens(string s, uddiClientNodeProperty[] properties) { if (properties == null || s == null) return s; s = s.Replace("\\n", " ").Replace("\\r", "").Replace(" ", ""); s = s.Trim(); /* pattern that is multi-line (?m), and looks for a pattern of * ${token}, in a 'reluctant' manner, by using the ? to * make sure we find ALL the tokens. */ //Pattern pattern = Pattern.compile("(?m)\\$\\{.*?\\}"); //Matcher matcher = pattern.matcher(s); Match matcher = System.Text.RegularExpressions.Regex.Match(s, "(?m)\\$\\{.*?\\}"); // Match temp = matcher.NextMatch(); while (matcher.Success) { String token = matcher.Value; token = token.Substring(2, token.Length - 3); String replacement = getValue(token, properties); if (replacement != null) { log.debug("Found token " + token + " and replacement value " + replacement); s = s.Replace("${" + token + "}", replacement); } else { log.error("Found token " + token + " but could not obtain its value. Data: " + s); } // matcher = System.Text.RegularExpressions.Regex.Match(s, "(?m)\\$\\{.*?\\}"); matcher = matcher.NextMatch(); } log.debug("Data after token replacement: " + s); return s; }
static string getValue(String key, uddiClientNodeProperty[] items) { if (key == null || items == null) return null; for (int i = 0; i < items.Length; i++) { if (items[i].name.Equals(key, StringComparison.CurrentCultureIgnoreCase)) return items[i].value; } return null; }
public void setProperties(uddiClientNodeProperty[] uddiClientNodeProperty) { if (uddiClientNodeProperty == null) return; Properties p = new Properties(); for (int i = 0; i < uddiClientNodeProperty.Length; i++) { p.setProperty(uddiClientNodeProperty[i].name, uddiClientNodeProperty[i].value); } this.properties = p; }