001 /** 002 * Copyright 2005-2011 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.kns.web.struts.action; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.apache.struts.util.MessageResourcesFactory; 020 import org.apache.struts.util.PropertyMessageResources; 021 022 import java.util.HashMap; 023 import java.util.Map; 024 import 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 */ 032 public class KualiPropertyMessageResources extends PropertyMessageResources { 033 private static final long serialVersionUID = -7712311580595112293L; 034 private HashMap kualiMessages; 035 036 public KualiPropertyMessageResources(MessageResourcesFactory factory, String config) { 037 super(factory, config); 038 } 039 040 public KualiPropertyMessageResources(MessageResourcesFactory factory, String config, boolean returnNull) { 041 super(factory, config, returnNull); 042 } 043 044 protected void loadLocale(String localeKey) { 045 String initialConfig = config; 046 String[] propertyFiles = config.split(","); 047 for (String propertyFile : propertyFiles) { 048 config = propertyFile; 049 locales.remove(localeKey); 050 super.loadLocale(localeKey); 051 } 052 config = initialConfig; 053 } 054 055 public Map getKualiProperties(String localeKey) { 056 if (this.kualiMessages != null && !this.kualiMessages.isEmpty()) { 057 return this.kualiMessages; 058 } 059 localeKey = (localeKey == null) ? "" : localeKey; 060 String localePrefix = localeKey + "."; 061 062 this.loadLocale((localeKey == null) ? "" : localeKey); 063 this.kualiMessages = new HashMap(this.messages.size()); 064 Set<String> keys = this.messages.keySet(); 065 for (String key : keys) { 066 this.kualiMessages.put(StringUtils.substringAfter(key, localePrefix), this.messages.get(key)); 067 } 068 return this.kualiMessages; 069 } 070 071 }