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.myfaces.tobago.context;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import javax.faces.context.FacesContext;
26 import java.util.Collections;
27 import java.util.Enumeration;
28 import java.util.ResourceBundle;
29
30 /**
31 * This class works like the Java resource bundle mechanism for a named resource bundle
32 * and adds the functionality of the tobago themes and also supports XML properties files.
33 * This class might be used in the faces-config.xml as an alternative to the tc:loadBundle tag.
34 *
35 * @since 1.5.0
36 */
37 public class TobagoBundle extends ResourceBundle {
38
39 private static final Logger LOG = LoggerFactory.getLogger(TobagoBundle.class);
40
41 private String bundleName;
42
43 public TobagoBundle(String bundleName) {
44 this.bundleName = bundleName;
45 }
46
47 protected Object handleGetObject(String key) {
48 if (LOG.isDebugEnabled()) {
49 LOG.debug("Searching for '{}' in bundle '{}'", key, bundleName);
50 }
51 FacesContext facesContext = FacesContext.getCurrentInstance();
52 return ResourceManagerUtils.getProperty(facesContext, bundleName, key);
53 }
54
55 public Enumeration<String> getKeys() {
56 return Collections.enumeration(Collections.<String>emptyList());
57 }
58
59 public String getBundleName() {
60 return bundleName;
61 }
62 }