View Javadoc

1   /**
2    * Copyright 2010-2013 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.PropertyUtils;
21  import org.kuali.common.util.property.Constants;
22  import org.kuali.common.util.property.GlobalPropertiesMode;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  import org.springframework.util.PropertyPlaceholderHelper;
26  
27  public class ResolvePlaceholdersProcessor implements PropertyProcessor {
28  
29  	private static final Logger logger = LoggerFactory.getLogger(ResolvePlaceholdersProcessor.class);
30  
31  	PropertyPlaceholderHelper helper = Constants.DEFAULT_PROPERTY_PLACEHOLDER_HELPER;
32  	GlobalPropertiesMode globalPropertiesMode = Constants.DEFAULT_GLOBAL_PROPERTIES_MODE;
33  
34  	public ResolvePlaceholdersProcessor() {
35  		this(Constants.DEFAULT_PROPERTY_PLACEHOLDER_HELPER);
36  	}
37  
38  	public ResolvePlaceholdersProcessor(PropertyPlaceholderHelper helper) {
39  		this(helper, Constants.DEFAULT_GLOBAL_PROPERTIES_MODE);
40  	}
41  
42  	public ResolvePlaceholdersProcessor(PropertyPlaceholderHelper helper, GlobalPropertiesMode globalPropertiesMode) {
43  		super();
44  		this.helper = helper;
45  		this.globalPropertiesMode = globalPropertiesMode;
46  	}
47  
48  	@Override
49  	public void process(Properties properties) {
50  		Properties resolvedProperties = PropertyUtils.getResolvedProperties(properties, helper, globalPropertiesMode);
51  		if (resolvedProperties.size() > 0) {
52  			logger.debug("Resolved {} property values", resolvedProperties.size());
53  			properties.putAll(resolvedProperties);
54  		}
55  	}
56  
57  	public PropertyPlaceholderHelper getHelper() {
58  		return helper;
59  	}
60  
61  	public void setHelper(PropertyPlaceholderHelper helper) {
62  		this.helper = helper;
63  	}
64  
65  	public GlobalPropertiesMode getGlobalPropertiesMode() {
66  		return globalPropertiesMode;
67  	}
68  
69  	public void setGlobalPropertiesMode(GlobalPropertiesMode globalPropertiesMode) {
70  		this.globalPropertiesMode = globalPropertiesMode;
71  	}
72  }