001/**
002 * Copyright 2005-2016 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 */
016package org.kuali.rice.kns.web.struts.action;
017
018import org.apache.commons.lang.StringUtils;
019import org.apache.struts.util.MessageResourcesFactory;
020import org.apache.struts.util.PropertyMessageResources;
021
022import java.util.HashMap;
023import java.util.Map;
024import java.util.Set;
025
026/**
027 * This is a description of what this class does - jjhanso don't forget to fill this in. 
028 * 
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 *
031 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
032 */
033@Deprecated
034public class KualiPropertyMessageResources extends PropertyMessageResources {
035    private static final long serialVersionUID = -7712311580595112293L;
036    private HashMap kualiMessages;
037
038    public KualiPropertyMessageResources(MessageResourcesFactory factory, String config) {
039        super(factory, config);
040    }
041
042    public KualiPropertyMessageResources(MessageResourcesFactory factory, String config, boolean returnNull) {
043        super(factory, config, returnNull);
044    }
045
046    protected void loadLocale(String localeKey) {
047        String initialConfig = config;
048        String[] propertyFiles = config.split(",");
049        for (String propertyFile : propertyFiles) {
050            config = propertyFile;
051            locales.remove(localeKey);
052            super.loadLocale(localeKey);
053        }
054        config = initialConfig;
055    }
056    
057    public Map getKualiProperties(String localeKey) {
058        if (this.kualiMessages != null && !this.kualiMessages.isEmpty()) {
059            return this.kualiMessages;
060        } 
061        localeKey = (localeKey == null) ? "" : localeKey;
062        String localePrefix = localeKey + ".";
063        
064        this.loadLocale((localeKey == null) ? "" : localeKey);
065        this.kualiMessages = new HashMap(this.messages.size());
066        Set<String> keys = this.messages.keySet();
067        for (String key : keys) {
068            this.kualiMessages.put(StringUtils.substringAfter(key, localePrefix), this.messages.get(key));
069        }
070        return this.kualiMessages;
071    }
072
073}