Coverage Report - org.seasar.teeda.core.util.MessageBundle
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageBundle
97%
28/29
83%
5/6
1.353
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
 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,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.util;
 17  
 
 18  
 import java.util.Collection;
 19  
 import java.util.Locale;
 20  
 import java.util.Map;
 21  
 import java.util.ResourceBundle;
 22  
 import java.util.Set;
 23  
 
 24  
 import javax.faces.context.FacesContext;
 25  
 
 26  
 import org.seasar.framework.util.StringUtil;
 27  
 
 28  
 /**
 29  
  * @author manhole
 30  
  */
 31  
 public class MessageBundle implements Map {
 32  
 
 33  
     private final String baseName;
 34  
 
 35  17
     public MessageBundle(String baseName) {
 36  17
         if (baseName == null) {
 37  1
             throw new NullPointerException("baseName");
 38  
         }
 39  16
         if (StringUtil.isBlank(baseName)) {
 40  1
             throw new IllegalArgumentException("baseName [" + baseName + "]");
 41  
         }
 42  15
         this.baseName = baseName;
 43  15
     }
 44  
 
 45  
     ResourceBundle getResourceBundle() {
 46  5
         return ResourceBundle
 47  
                 .getBundle(baseName, getLocale(), getClassLoader());
 48  
     }
 49  
 
 50  
     private Locale getLocale() {
 51  5
         final FacesContext context = FacesContext.getCurrentInstance();
 52  5
         final Locale locale = context.getViewRoot().getLocale();
 53  5
         if (locale != null) {
 54  5
             return locale;
 55  
         }
 56  0
         return context.getApplication().getDefaultLocale();
 57  
     }
 58  
 
 59  
     private ClassLoader getClassLoader() {
 60  5
         return Thread.currentThread().getContextClassLoader();
 61  
     }
 62  
 
 63  
     Map getResourceBundleMap() {
 64  5
         return new ResourceBundleMap(getResourceBundle());
 65  
     }
 66  
 
 67  
     public void clear() {
 68  1
         getResourceBundleMap().clear();
 69  1
     }
 70  
 
 71  
     public boolean containsKey(Object key) {
 72  1
         return getResourceBundleMap().containsKey(key);
 73  
     }
 74  
 
 75  
     public boolean containsValue(Object value) {
 76  1
         return getResourceBundleMap().containsValue(value);
 77  
     }
 78  
 
 79  
     public Set entrySet() {
 80  1
         return getResourceBundleMap().entrySet();
 81  
     }
 82  
 
 83  
     public Object get(Object key) {
 84  6
         return getResourceBundleMap().get(key);
 85  
     }
 86  
 
 87  
     public boolean isEmpty() {
 88  1
         return getResourceBundleMap().isEmpty();
 89  
     }
 90  
 
 91  
     public Set keySet() {
 92  1
         return getResourceBundleMap().keySet();
 93  
     }
 94  
 
 95  
     public Object put(Object key, Object value) {
 96  1
         return getResourceBundleMap().put(key, value);
 97  
     }
 98  
 
 99  
     public void putAll(Map t) {
 100  1
         getResourceBundleMap().putAll(t);
 101  1
     }
 102  
 
 103  
     public Object remove(Object key) {
 104  1
         return getResourceBundleMap().remove(key);
 105  
     }
 106  
 
 107  
     public int size() {
 108  1
         return getResourceBundleMap().size();
 109  
     }
 110  
 
 111  
     public Collection values() {
 112  1
         return getResourceBundleMap().values();
 113  
     }
 114  
 
 115  
 }