Coverage report

  %line %branch
org.apache.jetspeed.util.JetspeedLocale
0% 
0% 

 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  
 
 18  
 package org.apache.jetspeed.util;
 19  
 
 20  
 import java.util.Locale;
 21  
 import java.util.StringTokenizer;
 22  
 
 23  
 /**
 24  
  * Class to set and get Locale settings for Jetspeed.
 25  
  *          
 26  
  * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
 27  
  * @author <a href="mailto:shinsuke@yahoo.co.jp">Shinsuke Sugaya</a>
 28  
  * @version $Id: JetspeedLocale.java 516448 2007-03-09 16:25:47Z ate $
 29  
  */
 30  0
 public class JetspeedLocale
 31  
 {
 32  
     private static final String DELIM = ",";
 33  
     
 34  
     /**
 35  
      * According to PLT.21.8.1, the default locale should be English.
 36  
      */
 37  
     public static Locale getDefaultLocale()
 38  
     {
 39  0
         return Locale.ENGLISH;
 40  
     }
 41  
 
 42  
 
 43  
     /**
 44  
      * Converts Locale to String.
 45  
      * 
 46  
      * @param locale
 47  
      * @return
 48  
      */
 49  
     public static String convertLocaleToString(Locale locale)
 50  
     {
 51  0
         if (locale == null)
 52  
         {
 53  0
             return null;
 54  
         }
 55  0
         String country = locale.getCountry();
 56  0
         String language = locale.getLanguage();
 57  0
         String variant = locale.getVariant();
 58  0
         StringBuffer buffer = new StringBuffer(40);
 59  0
         if (language != null)
 60  
         {
 61  0
             buffer.append(language);
 62  
         }
 63  0
         buffer.append(DELIM);
 64  
 
 65  0
         if (country != null)
 66  
         {
 67  0
             buffer.append(country);
 68  
         }
 69  0
         buffer.append(DELIM);
 70  
 
 71  0
         if (variant != null)
 72  
         {
 73  0
             buffer.append(variant);
 74  
         }
 75  
 
 76  0
         return buffer.toString().trim();
 77  
     }
 78  
 
 79  
     /**
 80  
      * Converts String to Locale.
 81  
      * 
 82  
      * @param localeString
 83  
      * @return
 84  
      */
 85  
     public static Locale convertStringToLocale(String localeString)
 86  
     {
 87  0
         if (localeString == null)
 88  
         {
 89  0
             return null;
 90  
         }
 91  0
         StringTokenizer tokenizer = new StringTokenizer(localeString, DELIM);
 92  
 
 93  0
         String language = tokenizer.nextToken().trim();
 94  0
         String country = null;
 95  0
         String variant = null;
 96  0
         if (tokenizer.hasMoreTokens())
 97  
         {
 98  0
             country = tokenizer.nextToken().trim();
 99  
         }
 100  
 
 101  0
         if (tokenizer.hasMoreTokens())
 102  
         {
 103  0
             variant = tokenizer.nextToken().trim();
 104  
         }
 105  
 
 106  0
         if (country != null && language != class="keyword">null && variant != class="keyword">null)
 107  
         {
 108  0
             return new Locale(language, country, variant);
 109  
         }
 110  0
         else if (country != null && language != class="keyword">null)
 111  
         {
 112  0
             return new Locale(language, country);
 113  
         }
 114  0
         else if (language != null)
 115  
         {
 116  0
             return new Locale(language, ""); // JDK 1.3 compatibility
 117  
         }
 118  
         else
 119  
         {
 120  0
             return null;
 121  
         }
 122  
 
 123  
     }
 124  
 
 125  
 
 126  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.