Java Code Examples for org.springframework.util.PropertyPlaceholderHelper

Following code examples demonstrate how to use org.springframework.util.PropertyPlaceholderHelper from spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.util.PropertyPlaceholderHelper and various code implementation of this class.
Example 1
Project : spring-framework Source File : DefaultDataPlaceholderStrategy.java View Source Code on GitHub

	private String resolveStringValue(String value, final Properties properties) {
		try {
			PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper(DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, false);
			return helper.replacePlaceholders(value, new PlaceholderResolver() {
				@Override
				public String resolvePlaceholder(String placeholderName) {
					return properties.getProperty(placeholderName.toLowerCase());
				}
			});
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return "";
	}
			
Example 2
Project : spring-framework Source File : PropertyPlaceholderHelperCase.java View Source Code on GitHub

	public static void main(String[] args) {
		String tmpl = "this is ${name}";
		
		final Map<String, String> values = new HashMap<>();
		values.put("name", "wangbo");
		
		PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
		String content = helper.replacePlaceholders(tmpl, new PlaceholderResolver() {

			@Override
			public String resolvePlaceholder(String placeholderName) {
				return values.get(placeholderName);
			}
		});
		
		System.out.println(content);
	}
			
Example 3
Project : spring-framework Source File : PlaceholderReplacer.java View Source Code on GitHub

    public static String replacePlaceholders(final Map<String, String> variables, final String value) throws PlaceholderResolutionException {
        PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${","}");
        return helper.replacePlaceholders(value, new PlaceholderResolver() {
            public String resolvePlaceholder(String key) {
                if (key.isEmpty()) {
                    throw new PlaceholderResolutionException("Placeholder in '" + value + "' has to have a length of at least 1");
                }
                
                String result = variables.get(key);
                if (result == null) {
                    throw new PlaceholderResolutionException("Missing value for placeholder: '" + key + "' in '" + value + "'");
                }
                
                return result;
            }
        });
    }
			
Example 4
Project : spring-framework Source File : PlaceHolderHelperTest.java View Source Code on GitHub

    public static void main(String[] args) throws IOException {

        PropertyPlaceholderHelper propertyPlaceholderHelper
                = new PropertyPlaceholderHelper("${", "}");

        Properties properties = new Properties();
        properties.load(PlaceHolderHelperTest.class.getClassLoader().getResourceAsStream("Placeholder.properties"));

        
        String placeholders = propertyPlaceholderHelper.replacePlaceholders("${name}${age}${sex}", properties);
        System.out.println(placeholders);
    }