View Javadoc
1   /**
2    * Copyright 2005-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.rice.kew.util;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.config.property.ConfigStrLookup;
20  import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
21  import org.kuali.rice.coreservice.api.parameter.ParameterKey;
22  import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
23  import org.kuali.rice.kew.api.KewApiConstants;
24  import org.kuali.rice.krad.util.KRADConstants;
25  
26  /**
27   * Uses the KEW runtime parameters to locate a string for replacement, falling back to the deploy time configuration
28   * variables if necessary.
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class ParameterStrLookup extends ConfigStrLookup {
33  	
34  	private final String applicationId;
35  
36      /**
37       * Creates a string locator to search for KEW runtime parameters for any {@code applicationId}.
38       */
39  	public ParameterStrLookup() {
40          this(null);
41  	}
42  
43      /**
44       * Creates a string locator to search for KEW runtime parameters for a specific {@code applicationId}.
45       *
46       * @param applicationId the application to search for the KEW runtime parameter in.
47       */
48  	public ParameterStrLookup(String applicationId) {
49  		this.applicationId = applicationId;
50  	}
51  
52      /**
53       * {@inheritDoc}
54       */
55      @Override
56      public String lookup(String propertyName) {
57          if (StringUtils.isBlank(propertyName)) {
58              return null;
59          }
60  
61          String paramValue;
62  
63          // check runtime parameters first
64          if (StringUtils.isBlank(applicationId)) {
65              paramValue = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(
66                      KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.ALL_DETAIL_TYPE, propertyName);
67          } else {
68              ParameterKey parameterKey = ParameterKey.create(applicationId, KewApiConstants.KEW_NAMESPACE,
69                      KRADConstants.DetailTypes.ALL_DETAIL_TYPE, propertyName);
70              paramValue = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameterValueAsString(parameterKey);
71          }
72  
73          // fall back to deploy time configurations if empty
74          if (paramValue == null) {
75              paramValue = super.lookup(propertyName);
76          }
77  
78          return paramValue;
79      }
80  
81  }