1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.property.processor;
17
18 import java.util.Properties;
19
20 import org.kuali.common.util.Assert;
21 import org.kuali.common.util.PropertyUtils;
22 import org.kuali.common.util.log.LoggerUtils;
23 import org.slf4j.Logger;
24 import org.springframework.util.PropertyPlaceholderHelper;
25
26 public class ResolvingProcessor implements PropertyProcessor {
27
28 private static final Logger logger = LoggerUtils.make();
29
30 public static final boolean DEFAULT_IGNORE_UNRESOLVABLE = false;
31 public static final String DEFAULT_RESOLVE_KEY = "properties.resolve";
32
33 public ResolvingProcessor() {
34 this(DEFAULT_IGNORE_UNRESOLVABLE, DEFAULT_RESOLVE_KEY);
35 }
36
37 public ResolvingProcessor(boolean ignoreUnresolvable, String resolveKey) {
38 Assert.noBlanks(resolveKey);
39 this.ignoreUnresolvable = ignoreUnresolvable;
40 this.resolveKey = resolveKey;
41 this.helper = new PropertyPlaceholderHelper("${", "}", ":", ignoreUnresolvable);
42 }
43
44 private final boolean ignoreUnresolvable;
45 private final String resolveKey;
46 private final PropertyPlaceholderHelper helper;
47
48 @Override
49 public void process(Properties properties) {
50 boolean resolve = PropertyUtils.getBoolean(resolveKey, properties, true);
51 if (resolve) {
52 logger.info("Performing placeholder resolution on {} properties", properties.size());
53 PropertyUtils.resolve(properties, helper);
54 } else {
55 logger.info("Skipping placeholder resolution for {} properties", properties.size());
56 }
57 }
58
59 public boolean isIgnoreUnresolvable() {
60 return ignoreUnresolvable;
61 }
62
63 public String getResolveKey() {
64 return resolveKey;
65 }
66
67 public PropertyPlaceholderHelper getHelper() {
68 return helper;
69 }
70
71 }