001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.util;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.apache.commons.lang.text.StrLookup;
020 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
021 import org.kuali.rice.core.api.config.property.ConfigContext;
022 import org.kuali.rice.coreservice.api.parameter.ParameterKey;
023 import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
024 import org.kuali.rice.kew.api.KewApiConstants;
025 import org.kuali.rice.krad.util.KRADConstants;
026
027 /**
028 * Looks up Strings from the Config and System Parameters.
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032 public class ConfigStringLookup extends StrLookup {
033
034 private final String applicationId;
035
036 public ConfigStringLookup() {
037 this(null);
038 }
039
040 public ConfigStringLookup(String applicationId) {
041 this.applicationId = applicationId;
042 }
043
044 @Override
045 public String lookup(String propertyName) {
046 if (StringUtils.isBlank(propertyName)) {
047 return null;
048 }
049
050 String paramValue = null;
051 // check system parameters first
052 if (StringUtils.isBlank(applicationId)) {
053 paramValue = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(
054 KewApiConstants.KEW_NAMESPACE, KRADConstants.DetailTypes.ALL_DETAIL_TYPE, propertyName);
055 } else {
056 ParameterKey parameterKey = ParameterKey.create(applicationId, KewApiConstants.KEW_NAMESPACE,
057 KRADConstants.DetailTypes.ALL_DETAIL_TYPE, propertyName);
058 paramValue = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameterValueAsString(parameterKey);
059 }
060
061 if (paramValue == null) {
062 paramValue = ConfigContext.getCurrentContextConfig().getProperty(propertyName);
063 }
064 return paramValue;
065 }
066
067 }