/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiterMatcher(DEFAULT_VALUE_DELIMITER); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefixMatcher the prefix for variables, not null * @param suffixMatcher the suffix for variables, not null * @param escape the escape character * @param valueDelimiterMatcher the variable default value delimiter matcher, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor( final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, final char escape, final StrMatcher valueDelimiterMatcher) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); this.setValueDelimiterMatcher(valueDelimiterMatcher); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @param valueDelimiter the variable default value delimiter string, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape, final String valueDelimiter) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiter(valueDelimiter); }
public static String replacePlaceholdersWithWhiteSpace(final String templateContent, final Map<String, String> values) { StrSubstitutor sub = new StrSubstitutor(values); sub.setVariableResolver(new StrLookup<Object>() { @Override public String lookup(String key) { if (values == null) { return ""; } Object obj = values.get(key); if (obj == null) { return ""; } return obj.toString(); } }); return sub.replace(templateContent); }
public static String replacePlaceholdersWithWhiteSpace(final String templateContent, final Map<String, String> values) { StrSubstitutor sub = new StrSubstitutor(values); sub.setVariableResolver(new StrLookup<Object>() { @Override public String lookup(String key) { if (values == null) { return ""; } Object obj = values.get(key); if (obj == null) { return ""; } return obj.toString(); } }); return sub.replace(templateContent); }
public static StrSubstitutor createStrSubstitutor(String prefix, String suffix, StrLookup<String> lookup) { StrSubstitutor substitutor = new StrSubstitutor(); substitutor.setEnableSubstitutionInVariables(true); substitutor.setVariablePrefix(prefix); substitutor.setVariableSuffix(suffix); substitutor.setVariableResolver(lookup); return substitutor; }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiterMatcher(DEFAULT_VALUE_DELIMITER); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiterMatcher(DEFAULT_VALUE_DELIMITER); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiterMatcher(DEFAULT_VALUE_DELIMITER); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefixMatcher the prefix for variables, not null * @param suffixMatcher the suffix for variables, not null * @param escape the escape character * @param valueDelimiterMatcher the variable default value delimiter matcher, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor( final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, final char escape, final StrMatcher valueDelimiterMatcher) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); this.setValueDelimiterMatcher(valueDelimiterMatcher); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefixMatcher the prefix for variables, not null * @param suffixMatcher the suffix for variables, not null * @param escape the escape character * @param valueDelimiterMatcher the variable default value delimiter matcher, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor( final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, final char escape, final StrMatcher valueDelimiterMatcher) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); this.setValueDelimiterMatcher(valueDelimiterMatcher); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @param valueDelimiter the variable default value delimiter string, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape, final String valueDelimiter) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiter(valueDelimiter); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @param valueDelimiter the variable default value delimiter string, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape, final String valueDelimiter) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiter(valueDelimiter); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @param escape the escape character * @param valueDelimiter the variable default value delimiter string, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, final char escape, final String valueDelimiter) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); this.setValueDelimiter(valueDelimiter); }
/** * Creates a new instance and initializes it. * * @param variableResolver the variable resolver, may be null * @param prefixMatcher the prefix for variables, not null * @param suffixMatcher the suffix for variables, not null * @param escape the escape character * @param valueDelimiterMatcher the variable default value delimiter matcher, may be null * @throws IllegalArgumentException if the prefix or suffix is null * @since 3.2 */ public StrSubstitutor( final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, final char escape, final StrMatcher valueDelimiterMatcher) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); this.setValueDelimiterMatcher(valueDelimiterMatcher); }