/** * Internal method that resolves the value of a variable. * <p> * Most users of this class do not need to call this method. This method is * called automatically by the substitution process. * <p> * Writers of subclasses can override this method if they need to alter * how each substitution occurs. The method is passed the variable's name * and must return the corresponding value. This implementation uses the * {@link #getVariableResolver()} with the variable's name as the key. * * @param variableName the name of the variable, not null * @param buf the buffer where the substitution is occurring, not null * @param startPos the start position of the variable including the prefix, valid * @param endPos the end position of the variable including the suffix, valid * @return the variable's value or <b>null</b> if the variable is unknown */ protected String resolveVariable(String variableName, StrBuilder buf, int startPos, int endPos) { StrLookup resolver = getVariableResolver(); if (resolver == null) { return null; } return resolver.lookup(variableName); }
/** * Creates a new instance and initializes it. Uses defaults for variable * prefix and suffix and the escaping character. * * @param valueMap the map with the variables' values, may be null */ public StrSubstitutor(Map valueMap) { this(StrLookup.mapLookup(valueMap), DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE); }
/** * 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); }
/** * Obtains the lookup object for the specified prefix. This method is called * by the {@code lookup()} method. This implementation will check * whether a lookup object is registered for the given prefix. If not, a * <b>null</b> lookup object will be returned (never <b>null</b>). * * @param prefix the prefix * @return the lookup object to be used for this prefix */ protected StrLookup fetchLookupForPrefix(String prefix) { StrLookup lookup = localLookups.get(prefix); if (lookup == null) { lookup = StrLookup.noneLookup(); } return lookup; }
/** * Obtains the lookup object for the specified prefix. This method is called * by the {@code lookup()} method. This implementation will check * whether a lookup object is registered for the given prefix. If not, a * <b>null</b> lookup object will be returned (never <b>null</b>). * * @param prefix the prefix * @return the lookup object to be used for this prefix */ protected StrLookup fetchLookupForPrefix(String prefix) { StrLookup lookup = localLookups.get(prefix); if (lookup == null) { lookup = StrLookup.noneLookup(); } return lookup; }
/** * Creates a new instance and initializes it. * * @param valueMap the map with the variables' values, 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(Map valueMap, String prefix, String suffix, char escape) { this(StrLookup.mapLookup(valueMap), prefix, suffix, escape); }
@Override public String lookup(String key) { return Pattern.quote(_int.getDefaultLookup().lookup(key)); } });
/** * 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); }
/** * Returns the lookup object to be used for variables without a prefix. This * implementation will check whether a default lookup object was set. If * this is the case, it will be returned. Otherwise a <b>null</b> lookup * object will be returned (never <b>null</b>). * * @return the lookup object to be used for variables without a prefix */ protected StrLookup fetchNoPrefixLookup() { return (getDefaultLookup() != null) ? getDefaultLookup() : StrLookup.noneLookup(); }
/** * Creates a new instance and initializes it. Uses a default escaping character. * * @param valueMap the map with the variables' values, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(Map valueMap, String prefix, String suffix) { this(StrLookup.mapLookup(valueMap), prefix, suffix, DEFAULT_ESCAPE); }
/** * 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); }
/** * Returns the lookup object to be used for variables without a prefix. This * implementation will check whether a default lookup object was set. If * this is the case, it will be returned. Otherwise a <b>null</b> lookup * object will be returned (never <b>null</b>). * * @return the lookup object to be used for variables without a prefix */ protected StrLookup fetchNoPrefixLookup() { return (getDefaultLookup() != null) ? getDefaultLookup() : StrLookup.noneLookup(); }
/** * Creates a new instance and initializes it. Uses a default escaping character. * * @param valueMap the map with the variables' values, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(Map valueMap, String prefix, String suffix) { this(StrLookup.mapLookup(valueMap), prefix, suffix, DEFAULT_ESCAPE); }
@Override public String lookup(String key) { return Pattern.quote(_int.getDefaultLookup().lookup(key)); } });
/** * 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); }
/** * Creates a new instance and initializes it. Uses a default escaping character. * * @param valueMap the map with the variables' values, may be null * @param prefix the prefix for variables, not null * @param suffix the suffix for variables, not null * @throws IllegalArgumentException if the prefix or suffix is null */ public StrSubstitutor(Map valueMap, String prefix, String suffix) { this(StrLookup.mapLookup(valueMap), prefix, suffix, DEFAULT_ESCAPE); }
/** * 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); }
/** * Creates a new instance and initializes it. * * @param valueMap the map with the variables' values, 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(Map valueMap, String prefix, String suffix, char escape) { this(StrLookup.mapLookup(valueMap), prefix, suffix, escape); }