/** * 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); }
/** * 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 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 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; }
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 ) ); }
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 ); } }
/** * 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); }
@Override public String toString() { if (this.label != null && this.params != null && !this.params.isEmpty()) { StrSubstitutor strSub = new StrSubstitutor(this.params); this.label = strSub.replace(this.label); } return this.label; }
/** * 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); }
/** * 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); }
/** * 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 String apply( final Map<String, String> model ) { final StrSubstitutor substitutor = new StrSubstitutor( model, "{{", "}}", '\\' ); return substitutor.replace( this.template ); }
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); }
/** * 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); }
/** * 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); }
@Test public void testStr() { Map<String, String> valuesMap = new HashMap<String, String>(); valuesMap.put("str1", "aaaaa"); valuesMap.put("str2", "bbbbb"); String templateString = "> str1: ${str1}\n" + "> str2: ${str2}\n" ; StrSubstitutor sub = new StrSubstitutor(valuesMap); String resolvedString = sub.replace(templateString); System.err.println(resolvedString); }