View Javadoc

1   /**
2    * Copyright 2005-2013 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.web.struts.action;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.struts.util.MessageResourcesFactory;
20  import org.apache.struts.util.PropertyMessageResources;
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  import java.util.Set;
25  
26  /**
27   * This is a description of what this class does - jjhanso don't forget to fill this in. 
28   * 
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   *
31   */
32  public class KualiPropertyMessageResources extends PropertyMessageResources {
33      private static final long serialVersionUID = -7712311580595112293L;
34      private HashMap kualiMessages;
35  
36      public KualiPropertyMessageResources(MessageResourcesFactory factory, String config) {
37          super(factory, config);
38      }
39  
40      public KualiPropertyMessageResources(MessageResourcesFactory factory, String config, boolean returnNull) {
41          super(factory, config, returnNull);
42      }
43  
44      protected void loadLocale(String localeKey) {
45          String initialConfig = config;
46          String[] propertyFiles = config.split(",");
47          for (String propertyFile : propertyFiles) {
48              config = propertyFile;
49              locales.remove(localeKey);
50              super.loadLocale(localeKey);
51          }
52          config = initialConfig;
53      }
54      
55      public Map getKualiProperties(String localeKey) {
56          if (this.kualiMessages != null && !this.kualiMessages.isEmpty()) {
57              return this.kualiMessages;
58          } 
59          localeKey = (localeKey == null) ? "" : localeKey;
60          String localePrefix = localeKey + ".";
61          
62          this.loadLocale((localeKey == null) ? "" : localeKey);
63          this.kualiMessages = new HashMap(this.messages.size());
64          Set<String> keys = this.messages.keySet();
65          for (String key : keys) {
66              this.kualiMessages.put(StringUtils.substringAfter(key, localePrefix), this.messages.get(key));
67          }
68          return this.kualiMessages;
69      }
70  
71  }