Coverage Report - org.apache.commons.i18n.I18nUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
I18nUtils
75%
6/8
100%
4/4
3
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.i18n;
 18  
 
 19  
 import java.util.Locale;
 20  
 import java.util.ResourceBundle;
 21  
 
 22  
 /**
 23  
  * This class holds utility methods useful when working with i18n.
 24  
  * @author Mattias Jiderhamn
 25  
  */
 26  
 public class I18nUtils {
 27  
 
 28  
     static final String INTERNAL_MESSAGE_NOT_FOUND = "Internal I18n error: Message not found";
 29  
     static final String MESSAGE_NOT_FOUND = "messageNotFound";
 30  
     static final String NO_MESSAGE_ENTRIES_FOUND = "noMessageEntriesFound";
 31  
     static final String MESSAGE_ENTRY_NOT_FOUND = "messageEntryNotFound";
 32  
     static final String RESOURCE_BUNDLE_NOT_FOUND = "resourceBundleNotFound";
 33  
     public static final String MESSAGE_PARSING_ERROR = "messageParsingError";
 34  
 
 35  1
     public static final ResourceBundle INTERNAL_MESSAGES = ResourceBundle.getBundle("i18n-messages", Locale.getDefault());
 36  
 
 37  0
     private I18nUtils() {
 38  0
     }
 39  
 
 40  
     public static Locale getParentLocale (Locale locale) {
 41  44
         if(locale.getVariant().length() != 0)
 42  14
           return new Locale(locale.getLanguage(), locale.getCountry());
 43  30
         else if(locale.getCountry().length() != 0)
 44  17
             return new Locale(locale.getLanguage());
 45  
         else // Locale with only language have no parent
 46  13
             return null;
 47  
     }
 48  
 }