private TokenReplacer buildModuleTokenReplacer(AppConfig appConfig) { DefaultTokenReplacer r = new DefaultTokenReplacer(); final Map<String, String> customTokens = appConfig.getCustomTokens(); if (customTokens != null && !customTokens.isEmpty()) { r.addPropertiesSource(() -> { Properties p = new Properties(); p.putAll(customTokens); return p; }); } return r; }
@Override public String replaceTokens(String text) { if (properties == null) { initializeProperties(); } if (helper == null) { initializeHelper(); } for (Object key : properties.keySet()) { String skey = propertyPrefix != null ? propertyPrefix + key : key.toString(); if (logger.isTraceEnabled()) { logger.trace("Checking for key in text: " + skey); } if (text.contains(skey)) { String value = properties.getProperty(key.toString()); value = helper.replacePlaceholders(value, properties); if (logger.isDebugEnabled()) { logger.debug(format("Replacing %s with %s", skey, value)); } text = text.replace(skey, value); } } return text; }
protected TokenReplacer buildModuleTokenReplacer(AppConfig appConfig) { DefaultTokenReplacer r = appConfig.isUseRoxyTokenPrefix() ? new RoxyTokenReplacer() : new DefaultTokenReplacer(); final Map<String, String> customTokens = appConfig.getCustomTokens(); if (customTokens != null) { r.addPropertiesSource(new MapPropertiesSource(customTokens)); } if (appConfig.getModuleTokensPropertiesSources() != null) { for (PropertiesSource ps : appConfig.getModuleTokensPropertiesSources()) { r.addPropertiesSource(ps); } } return r; } }