01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.core.service.impl;
17:
18: import java.util.Iterator;
19: import java.util.Properties;
20:
21: import org.apache.commons.lang.StringUtils;
22: import org.kuali.RiceConstants;
23: import org.kuali.core.util.properties.KualiPropertiesFactory;
24: import org.kuali.core.util.properties.PropertyHolder;
25: import org.kuali.core.util.spring.Cached;
26: import org.kuali.rice.core.Core;
27:
28: @Cached
29: public abstract class AbstractStaticConfigurationServiceImpl {
30: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
31: .getLogger(KualiConfigurationServiceImpl.class);
32: private PropertyHolder propertyHolder;
33:
34: /**
35: * Harcoding the configFileName, by request.
36: */
37: public AbstractStaticConfigurationServiceImpl() {
38: KualiPropertiesFactory propertiesFactory = new KualiPropertiesFactory(
39: RiceConstants.CONFIGURATION_SERVICE_DATA_FILE_NAME);
40: this .propertyHolder = propertiesFactory.getProperties(null);
41: this .propertyHolder.getHeldProperties().putAll(
42: Core.getCurrentContextConfig().getProperties());
43: }
44:
45: public boolean isProductionEnvironment() {
46: return getPropertyString(
47: RiceConstants.PROD_ENVIRONMENT_CODE_KEY).equals(
48: getPropertyString(RiceConstants.ENVIRONMENT_KEY));
49: }
50:
51: /**
52: * @see org.kuali.core.service.KualiConfigurationService#getPropertyString(java.lang.String)
53: */
54: public String getPropertyString(String key) {
55: LOG.debug("getPropertyString() started");
56:
57: if (key == null) {
58: throw new IllegalArgumentException("invalid (null) key");
59: }
60:
61: return this .propertyHolder.getProperty(key);
62: }
63:
64: /**
65: * @see org.kuali.core.service.KualiConfigurationService#getPropertyAsBoolean(java.lang.String)
66: */
67: public boolean getPropertyAsBoolean(String key) {
68: LOG.debug("getPropertyAsBoolean() started");
69:
70: if (key == null) {
71: throw new IllegalArgumentException("invalid (null) key");
72: }
73: String property = this .propertyHolder.getProperty(key);
74: if (property != null
75: && (property.equalsIgnoreCase("true")
76: || property.equalsIgnoreCase("yes")
77: || property.equalsIgnoreCase("on") || property
78: .equalsIgnoreCase("1"))) {
79: return true;
80: }
81: return false;
82: }
83:
84: /**
85: * @see org.kuali.core.service.KualiConfigurationService#getAllProperties()
86: */
87: public Properties getAllProperties() {
88: LOG.debug("getAllProperties() started");
89:
90: Properties p = new Properties();
91:
92: for (Iterator i = propertyHolder.getKeys(); i.hasNext();) {
93: String key = (String) i.next();
94: p.setProperty(key, propertyHolder.getProperty(key));
95: }
96:
97: return p;
98: }
99: }
|