View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.wss4j.common.crypto;
21  
22  import java.util.Enumeration;
23  import java.util.Locale;
24  import java.util.MissingResourceException;
25  import java.util.ResourceBundle;
26  
27  import org.apache.xml.security.utils.Constants;
28  import org.apache.xml.security.utils.I18n;
29  
30  /**
31   * ResourceBundle for WSS4J
32   */
33  public class WSS4JResourceBundle extends ResourceBundle {
34  
35      private static final org.slf4j.Logger LOG =
36          org.slf4j.LoggerFactory.getLogger(WSS4JResourceBundle.class);
37  
38      private final ResourceBundle wss4jSecResourceBundle;
39      private final ResourceBundle xmlSecResourceBundle;
40  
41      public WSS4JResourceBundle() {
42          wss4jSecResourceBundle = ResourceBundle.getBundle("messages.wss4j_errors");
43  
44          ResourceBundle tmpResourceBundle;
45          try {
46              tmpResourceBundle =
47                  ResourceBundle.getBundle(Constants.exceptionMessagesResourceBundleBase,
48                          Locale.getDefault(),
49                          I18n.class.getClassLoader());
50          } catch (MissingResourceException ex) {
51              // Using a Locale of which there is no properties file.
52              LOG.debug(ex.getMessage());
53              // Default to en/US
54              tmpResourceBundle =
55                  ResourceBundle.getBundle(Constants.exceptionMessagesResourceBundleBase,
56                                           new Locale("en", "US"), I18n.class.getClassLoader());
57          }
58          xmlSecResourceBundle = tmpResourceBundle;
59      }
60  
61      @Override
62      protected Object handleGetObject(String key) {
63          Object value = null;
64          try {
65              value = wss4jSecResourceBundle.getObject(key);
66          } catch (MissingResourceException e) {
67              try {
68                  value = xmlSecResourceBundle.getObject(key);
69              } catch (MissingResourceException ex) { //NOPMD
70                  //ignore
71              }
72          }
73          return value;
74      }
75  
76      @Override
77      public Enumeration<String> getKeys() {
78          throw new UnsupportedOperationException("getKeys not supported");
79      }
80  
81  
82  }