Coverage Report - org.apache.commons.feedparser.tools.RFC3066LocaleParser
 
Classes in this File Line Coverage Branch Coverage Complexity
RFC3066LocaleParser
0%
0/150
0%
0/4
2
 
 1  
 /*
 2  
  * Copyright 1999,2004 The Apache Software Foundation.
 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, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.feedparser.tools;
 18  
 
 19  
 import java.util.HashMap;
 20  
 import java.util.Locale;
 21  
 import java.util.StringTokenizer;
 22  
 
 23  0
 public class RFC3066LocaleParser {
 24  
 
 25  0
     static HashMap locales = new HashMap();
 26  
     
 27  
     public static Locale parse( String input ) {
 28  
 
 29  0
         StringTokenizer tok = new StringTokenizer( input, "-" );
 30  
 
 31  0
         while ( tok.hasMoreElements() ) {
 32  0
             String current = (String)tok.nextElement();
 33  
 
 34  0
             current = current.toLowerCase();
 35  
 
 36  0
             if ( current.length() == 2 ) {
 37  0
                 return getLocale( current );
 38  
             }
 39  
             
 40  0
         }
 41  
 
 42  0
         return null;
 43  
 
 44  
     }
 45  
 
 46  
     public static Locale getLocale( String language ) {
 47  0
         return (Locale)locales.get( language );
 48  
     }
 49  
     
 50  
     private static void initLocale( String name ) {
 51  0
         locales.put( name, new Locale( name ) );
 52  0
     }
 53  
     
 54  
     static {
 55  
 
 56  
         // Taken from: http://www.w3.org/WAI/ER/IG/ert/iso639.htm
 57  
         
 58  0
         initLocale( "aa" ); //afar"
 59  0
         initLocale( "ab" ); //abkhazian"
 60  0
         initLocale( "af" ); //afrikaans"
 61  0
         initLocale( "am" ); //amharic"
 62  0
         initLocale( "ar" ); //arabic"
 63  0
         initLocale( "as" ); //assamese"
 64  0
         initLocale( "ay" ); //aymara"
 65  0
         initLocale( "az" ); //azerbaijani"
 66  0
         initLocale( "ba" ); //bashkir"
 67  0
         initLocale( "be" ); //byelorussian"
 68  0
         initLocale( "bg" ); //bulgarian"
 69  0
         initLocale( "bh" ); //bihari"
 70  0
         initLocale( "bi" ); //bislama"
 71  0
         initLocale( "bn" ); //bengali"" ); //bangla"
 72  0
         initLocale( "bo" ); //tibetan"
 73  0
         initLocale( "br" ); //breton"
 74  0
         initLocale( "ca" ); //catalan"
 75  0
         initLocale( "co" ); //corsican"
 76  0
         initLocale( "cs" ); //czech"
 77  0
         initLocale( "cy" ); //welsh"
 78  0
         initLocale( "da" ); //danish"
 79  0
         initLocale( "de" ); //german"
 80  0
         initLocale( "dz" ); //bhutani"
 81  0
         initLocale( "el" ); //greek"
 82  0
         initLocale( "en" ); //english"" ); //american"
 83  0
         initLocale( "eo" ); //esperanto"
 84  0
         initLocale( "es" ); //spanish"
 85  0
         initLocale( "et" ); //estonian"
 86  0
         initLocale( "eu" ); //basque"
 87  0
         initLocale( "fa" ); //persian"
 88  0
         initLocale( "fi" ); //finnish"
 89  0
         initLocale( "fj" ); //fiji"
 90  0
         initLocale( "fo" ); //faeroese"
 91  0
         initLocale( "fr" ); //french"
 92  0
         initLocale( "fy" ); //frisian"
 93  0
         initLocale( "ga" ); //irish"
 94  0
         initLocale( "gd" ); //gaelic"" ); //scots gaelic"
 95  0
         initLocale( "gl" ); //galician"
 96  0
         initLocale( "gn" ); //guarani"
 97  0
         initLocale( "gu" ); //gujarati"
 98  0
         initLocale( "ha" ); //hausa"
 99  0
         initLocale( "hi" ); //hindi"
 100  0
         initLocale( "hr" ); //croatian"
 101  0
         initLocale( "hu" ); //hungarian"
 102  0
         initLocale( "hy" ); //armenian"
 103  0
         initLocale( "ia" ); //interlingua"
 104  0
         initLocale( "ie" ); //interlingue"
 105  0
         initLocale( "ik" ); //inupiak"
 106  0
         initLocale( "in" ); //indonesian"
 107  0
         initLocale( "is" ); //icelandic"
 108  0
         initLocale( "it" ); //italian"
 109  0
         initLocale( "iw" ); //hebrew"
 110  0
         initLocale( "ja" ); //japanese"
 111  0
         initLocale( "ji" ); //yiddish"
 112  0
         initLocale( "jw" ); //javanese"
 113  0
         initLocale( "ka" ); //georgian"
 114  0
         initLocale( "kk" ); //kazakh"
 115  0
         initLocale( "kl" ); //greenlandic"
 116  0
         initLocale( "km" ); //cambodian"
 117  0
         initLocale( "kn" ); //kannada"
 118  0
         initLocale( "ko" ); //korean"
 119  0
         initLocale( "ks" ); //kashmiri"
 120  0
         initLocale( "ku" ); //kurdish"
 121  0
         initLocale( "ky" ); //kirghiz"
 122  0
         initLocale( "la" ); //latin"
 123  0
         initLocale( "ln" ); //lingala"
 124  0
         initLocale( "lo" ); //laothian"
 125  0
         initLocale( "lt" ); //lithuanian"
 126  0
         initLocale( "lv" ); //latvian"" ); //lettish"
 127  0
         initLocale( "mg" ); //malagasy"
 128  0
         initLocale( "mi" ); //maori"
 129  0
         initLocale( "mk" ); //macedonian"
 130  0
         initLocale( "ml" ); //malayalam"
 131  0
         initLocale( "mn" ); //mongolian"
 132  0
         initLocale( "mo" ); //moldavian"
 133  0
         initLocale( "mr" ); //marathi"
 134  0
         initLocale( "ms" ); //malay"
 135  0
         initLocale( "mt" ); //maltese"
 136  0
         initLocale( "my" ); //burmese"
 137  0
         initLocale( "na" ); //nauru"
 138  0
         initLocale( "ne" ); //nepali"
 139  0
         initLocale( "nl" ); //dutch"
 140  0
         initLocale( "no" ); //norwegian"
 141  0
         initLocale( "oc" ); //occitan"
 142  0
         initLocale( "om" ); //oromo"" ); //afan"
 143  0
         initLocale( "or" ); //oriya"
 144  0
         initLocale( "pa" ); //punjabi"
 145  0
         initLocale( "pl" ); //polish"
 146  0
         initLocale( "ps" ); //pashto"" ); //pushto"
 147  0
         initLocale( "pt" ); //portuguese"
 148  0
         initLocale( "qu" ); //quechua"
 149  0
         initLocale( "rm" ); //rhaeto-romance"
 150  0
         initLocale( "rn" ); //kirundi"
 151  0
         initLocale( "ro" ); //romanian"
 152  0
         initLocale( "ru" ); //russian"
 153  0
         initLocale( "rw" ); //kinyarwanda"
 154  0
         initLocale( "sa" ); //sanskrit"
 155  0
         initLocale( "sd" ); //sindhi"
 156  0
         initLocale( "sg" ); //sangro"
 157  0
         initLocale( "sh" ); //serbo-croatian"
 158  0
         initLocale( "si" ); //singhalese"
 159  0
         initLocale( "sk" ); //slovak"
 160  0
         initLocale( "sl" ); //slovenian"
 161  0
         initLocale( "sm" ); //samoan"
 162  0
         initLocale( "sn" ); //shona"
 163  0
         initLocale( "so" ); //somali"
 164  0
         initLocale( "sq" ); //albanian"
 165  0
         initLocale( "sr" ); //serbian"
 166  0
         initLocale( "ss" ); //siswati"
 167  0
         initLocale( "st" ); //sesotho"
 168  0
         initLocale( "su" ); //sudanese"
 169  0
         initLocale( "sv" ); //swedish"
 170  0
         initLocale( "sw" ); //swahili"
 171  0
         initLocale( "ta" ); //tamil"
 172  0
         initLocale( "te" ); //tegulu"
 173  0
         initLocale( "tg" ); //tajik"
 174  0
         initLocale( "th" ); //thai"
 175  0
         initLocale( "ti" ); //tigrinya"
 176  0
         initLocale( "tk" ); //turkmen"
 177  0
         initLocale( "tl" ); //tagalog"
 178  0
         initLocale( "tn" ); //setswana"
 179  0
         initLocale( "to" ); //tonga"
 180  0
         initLocale( "tr" ); //turkish"
 181  0
         initLocale( "ts" ); //tsonga"
 182  0
         initLocale( "tt" ); //tatar"
 183  0
         initLocale( "tw" ); //twi"
 184  0
         initLocale( "uk" ); //ukrainian"
 185  0
         initLocale( "ur" ); //urdu"
 186  0
         initLocale( "uz" ); //uzbek"
 187  0
         initLocale( "vi" ); //vietnamese"
 188  0
         initLocale( "vo" ); //volapuk"
 189  0
         initLocale( "wo" ); //wolof"
 190  0
         initLocale( "xh" ); //xhosa"
 191  0
         initLocale( "yo" ); //yoruba"
 192  0
         initLocale( "zh" ); //chinese"
 193  0
         initLocale( "zu" ); //Zulu"
 194  
     
 195  0
     }
 196  
     
 197  
 }