/** * 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(StrLookup variableResolver, String prefix, String suffix, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); }
/** * 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 * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor( StrLookup variableResolver, StrMatcher prefixMatcher, StrMatcher suffixMatcher, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); }
/** * 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(StrLookup variableResolver, String prefix, String suffix, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); }
/** * 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 * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor( StrLookup variableResolver, StrMatcher prefixMatcher, StrMatcher suffixMatcher, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); }
/** * 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(StrLookup variableResolver, String prefix, String suffix, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); }
/** * 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(StrLookup variableResolver, String prefix, String suffix, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); }
/** * 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(StrLookup variableResolver, String prefix, String suffix, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); }
/** * 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(StrLookup variableResolver, String prefix, String suffix, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefix(prefix); this.setVariableSuffix(suffix); this.setEscapeChar(escape); }
/** * 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 * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor( StrLookup variableResolver, StrMatcher prefixMatcher, StrMatcher suffixMatcher, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); }
/** * 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 * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor( StrLookup variableResolver, StrMatcher prefixMatcher, StrMatcher suffixMatcher, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); }
/** * 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 * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor( StrLookup variableResolver, StrMatcher prefixMatcher, StrMatcher suffixMatcher, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); }
/** * 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 * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor( StrLookup variableResolver, StrMatcher prefixMatcher, StrMatcher suffixMatcher, char escape) { this.setVariableResolver(variableResolver); this.setVariablePrefixMatcher(prefixMatcher); this.setVariableSuffixMatcher(suffixMatcher); this.setEscapeChar(escape); }
/** * Replaces the given text by looking up values from the given resource bundle. * @param bundle resource bundle * @param text text to replace * @param variablePrefix variable reference prefix. "${" by default. * @param variableSuffix variable reference suffix. "}" by default. * @param escapeChar escape character which can be put just before a variable reference to ignore the expression. * @param escapeMessageXml whether or not to escape a message value having &,>,<,", and '. * @return replaced string by the values found in the given resource bundle */ public static String replaceMessagesByBundle(ResourceBundle bundle, String text, String variablePrefix, String variableSuffix, Character escapeChar, boolean escapeMessageXml) { if (bundle == null) { throw new IllegalArgumentException("The bundle must not be null."); } StrSubstitutor subst = new StrSubstitutor(new ResourceBundleVariableResolver(bundle, escapeMessageXml), StrSubstitutor.DEFAULT_PREFIX, StrSubstitutor.DEFAULT_SUFFIX, DEFAULT_ESCAPE); if (StringUtils.isNotBlank(variablePrefix)) { subst.setVariablePrefix(variablePrefix); } if (StringUtils.isNotBlank(variableSuffix)) { subst.setVariableSuffix(variableSuffix); } if (escapeChar != null) { subst.setEscapeChar(escapeChar); } return subst.replace(text); }