/** * Replaces all the occurrences of variables in the given source object with * their matching values from the map. * * @param source the source text containing the variables to substitute, null returns null * @param valueMap the map with the values, may be null * @return the result of the replace operation */ public static String replace(Object source, Map valueMap) { return new StrSubstitutor(valueMap).replace(source); }
public static Properties interpolateVariables(Properties properties, Map<String, String> variables) { Properties result = new Properties(); Enumeration keys = properties.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = (String) properties.get(key); String interpolatedValue = StrSubstitutor.replace(value, variables, "${env:", "}"); result.setProperty(key, interpolatedValue); } return result; }
/** * Replaces all the occurrences of variables in the given source object with * their matching values from the map. This method allows to specifiy a * custom variable prefix and suffix * * @param source the source text containing the variables to substitute, null returns null * @param valueMap the map with the values, may be null * @param prefix the prefix of variables, not null * @param suffix the suffix of variables, not null * @return the result of the replace operation * @throws IllegalArgumentException if the prefix or suffix is null */ public static String replace(Object source, Map valueMap, String prefix, String suffix) { return new StrSubstitutor(valueMap, prefix, suffix).replace(source); }
/** * Replaces all the occurrences of variables in the given source object with their matching * values from the properties. * * @param source the source text containing the variables to substitute, null returns null * @param valueProperties the properties with values, may be null * @return the result of the replace operation * @since 2.6 */ public static String replace(Object source, Properties valueProperties) { if (valueProperties == null) { return source.toString(); } Map valueMap = new HashMap(); Enumeration propNames = valueProperties.propertyNames(); while (propNames.hasMoreElements()) { String propName = (String)propNames.nextElement(); String propValue = valueProperties.getProperty(propName); valueMap.put(propName, propValue); } return StrSubstitutor.replace(source, valueMap); }
public String generateError(String error) { Map<String, String> values = ImmutableMap.of( PARAMETER_TOTAL_WIDTH, valueOf(MARGIN + computeWidth(error) + MARGIN), PARAMETER_LABEL, error); StrSubstitutor strSubstitutor = new StrSubstitutor(values); return strSubstitutor.replace(errorTemplate); }
/** * * @param propertyKeys the collection of the properties; if null will return all properties * @return */ protected Properties getProperties(Collection<String> propertyKeys) { Map<String, String> envMap = System.getenv(); StrSubstitutor sub = new StrSubstitutor(envMap); Properties properties = new Properties(); for (Entry<Object, Object> entry : this.properties.entrySet()) { if (propertyKeys == null || propertyKeys.contains(entry.getKey())) { properties.put(entry.getKey(), sub.replace((String) entry.getValue())); } } return properties; }
/** * Replaces all the occurrences of variables in the given source object with * their matching values from the system properties. * * @param source the source text containing the variables to substitute, null returns null * @return the result of the replace operation */ public static String replaceSystemProperties(Object source) { return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); }
public String generateBadge(String label, String value, Color backgroundValueColor) { int labelWidth = computeWidth(label); int valueWidth = computeWidth(value); Map<String, String> values = ImmutableMap.<String, String>builder() .put(PARAMETER_TOTAL_WIDTH, valueOf(MARGIN * 4 + ICON_WIDTH + labelWidth + valueWidth)) .put(PARAMETER_LABEL_WIDTH, valueOf(labelWidth)) .put(PARAMETER_VALUE_WIDTH, valueOf(valueWidth)) .put(PARAMETER_LEFT_WIDTH, valueOf(MARGIN * 2 + ICON_WIDTH + labelWidth)) .put(PARAMETER_LEFT_WIDTH_PLUS_MARGIN, valueOf(MARGIN * 3 + ICON_WIDTH + labelWidth)) .put(PARAMETER_RIGHT_WIDTH, valueOf(MARGIN * 2 + valueWidth)) .put(PARAMETER_ICON_WIDTH_PLUS_MARGIN, valueOf(MARGIN + ICON_WIDTH)) .put(PARAMETER_COLOR, backgroundValueColor.getValue()) .put(PARAMETER_LABEL, label) .put(PARAMETER_VALUE, value) .build(); StrSubstitutor strSubstitutor = new StrSubstitutor(values); return strSubstitutor.replace(badgeTemplate); }
public String emailMsg( Map<String, String> values, String propertyName ) { return new StrSubstitutor( values ).replace( properties.getProperty( propertyName ) ); }
settings.addProperties(props); for (Map.Entry<String, String> entry : settings.getProperties().entrySet()) { String interpolatedValue = StrSubstitutor.replace(entry.getValue(), System.getenv(), "${", "}"); settings.setProperty(entry.getKey(), interpolatedValue);
private void testProperty( String propertyName, boolean containsSubstitution ) { String propertyValue = setup.get( propertyName ); assertTrue( propertyName + " was not found", isNotBlank( propertyValue ) ); logger.info( propertyName + "=" + propertyValue ); if ( containsSubstitution ) { Map<String, String> valuesMap = new HashMap<String, String>(); valuesMap.put( "reset_url", "test-url" ); valuesMap.put( "organization_name", "test-org" ); valuesMap.put( "activation_url", "test-url" ); valuesMap.put( "confirmation_url", "test-url" ); valuesMap.put( "user_email", "test-email" ); valuesMap.put( "pin", "test-pin" ); StrSubstitutor sub = new StrSubstitutor( valuesMap ); String resolvedString = sub.replace( propertyValue ); assertNotSame( propertyValue, resolvedString ); } }
@Theory public void checkSQL_results( @FromDataPoints("database") DatabaseAndResult database, @FromDataPoints("columnDef") ColumnDef columnDef) { String oldColumnName = "old_" + randomAlphabetic(6).toLowerCase(); String tableName = "table_" + randomAlphabetic(6).toLowerCase(); List<String> result = new RenameColumnsBuilder(database.getDialect(), tableName) .renameColumn(oldColumnName, columnDef) .build(); Map<String, String> parameters = new HashMap<>(); parameters.put("table_name", tableName); parameters.put("old_column_name", oldColumnName); parameters.put("new_column_name", NEW_COLUMN_NAME); parameters.put("column_def", columnDef.generateSqlType(database.getDialect())); String expectedResult = StrSubstitutor.replace(database.getTemplateSql(), parameters); assertThat(result).containsExactlyInAnyOrder(expectedResult); }
private void copyWithVarSubstitution(String resourceName, File destination, StrSubstitutor... moreSubstitutors) throws IOException { String resource = marytts.util.io.FileUtils.getStreamAsString( getClass().getResourceAsStream("templates/" + resourceName), "UTF-8"); String resourceWithReplacements = substitutor.replace(resource); for (StrSubstitutor more : moreSubstitutors) { resourceWithReplacements = more.replace(resourceWithReplacements); } PrintWriter out = new PrintWriter(destination, "UTF-8"); out.print(resourceWithReplacements); out.close(); }
public String apply( final Map<String, String> model ) { final StrSubstitutor substitutor = new StrSubstitutor( model, "{{", "}}", '\\' ); return substitutor.replace( this.template ); }
private String makePath() { String pathPattern = trailing ? path.substring(0, path.length() - 1) : path; return getSubstitutor().replace(pathPattern); }
@RequestMapping(value = "/agent/", method = GET) public String agent(HttpServletRequest request) { return StrSubstitutor.replace(startString, of("secret", nodeSecret == null ? "" : "-e \"dm_agent_notifier_secret=" + nodeSecret + "\"", "server", getServerAddress(request)), "{", "}"); }
/** * Replaces all the occurrences of variables in the given source object with * their matching values from the system properties. * * @param source the source text containing the variables to substitute, null returns null * @return the result of the replace operation */ public static String replaceSystemProperties(Object source) { return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); }
/** * Replaces all the occurrences of variables in the given source object with * their matching values from the system properties. * * @param source the source text containing the variables to substitute, null returns null * @return the result of the replace operation */ public static String replaceSystemProperties(Object source) { return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); }