View Javadoc

1   /*
2    * Copyright 2007 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.rice.kns.service.impl;
17  
18  import java.util.Properties;
19  
20  import org.kuali.rice.core.config.ConfigContext;
21  import org.kuali.rice.core.util.ImmutableProperties;
22  import org.kuali.rice.kns.util.KNSConstants;
23  import org.kuali.rice.kns.util.properties.PropertyHolder;
24  import org.kuali.rice.kns.util.spring.Cached;
25  import org.kuali.rice.kns.web.struts.action.KualiPropertyMessageResources;
26  import org.kuali.rice.kns.web.struts.action.KualiPropertyMessageResourcesFactory;
27  
28  @Cached
29  public abstract class AbstractStaticConfigurationServiceImpl {
30      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiConfigurationServiceImpl.class);
31      private PropertyHolder propertyHolder;
32      
33  
34      /**
35       * Harcoding the configFileName, by request.
36       */
37      public AbstractStaticConfigurationServiceImpl() {
38          this.propertyHolder = new PropertyHolder();
39          this.propertyHolder.getHeldProperties().putAll(ConfigContext.getCurrentContextConfig().getProperties());
40          
41          KualiPropertyMessageResourcesFactory propertyMessageFactory = new KualiPropertyMessageResourcesFactory();
42          
43          // create default KualiPropertyMessageResources
44          KualiPropertyMessageResources messageResources = (KualiPropertyMessageResources)propertyMessageFactory.createResources("");;
45                  
46          //Add Kuali Properties to property holder
47          this.propertyHolder.getHeldProperties().putAll(messageResources.getKualiProperties(null));
48      }
49      
50      public boolean isProductionEnvironment() {
51  	return getPropertyString(KNSConstants.PROD_ENVIRONMENT_CODE_KEY).equalsIgnoreCase(
52  		getPropertyString(KNSConstants.ENVIRONMENT_KEY));
53      }
54  
55      /**
56       * @see org.kuali.rice.kns.service.KualiConfigurationService#getPropertyString(java.lang.String)
57       */
58      public String getPropertyString(String key) {
59          LOG.debug("getPropertyString() started");
60  
61          if (key == null) {
62              throw new IllegalArgumentException("invalid (null) key");
63          }
64  
65          return this.propertyHolder.getProperty(key);
66      }
67  
68      /**
69       * @see org.kuali.rice.kns.service.KualiConfigurationService#getPropertyAsBoolean(java.lang.String)
70       */
71      public boolean getPropertyAsBoolean(String key) {
72          LOG.debug("getPropertyAsBoolean() started");
73  
74          if (key == null) {
75              throw new IllegalArgumentException("invalid (null) key");
76          }
77          String property = this.propertyHolder.getProperty(key);
78          if ( property != null ) {
79              property = property.trim();
80              if ((property.equalsIgnoreCase( "true" ) 
81                      || property.equalsIgnoreCase( "yes" )
82                      || property.equalsIgnoreCase( "on" )
83                      || property.equalsIgnoreCase( "1" )) ) {
84                  return true;
85              }
86          }
87          return false;
88      }
89      
90      /**
91       * @see org.kuali.rice.kns.service.KualiConfigurationService#getAllProperties()
92       */
93      public Properties getAllProperties() {
94          LOG.debug("getAllProperties() started");
95  
96          return new ImmutableProperties(propertyHolder.getHeldProperties());      
97      }
98  }