View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }