Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 76   Methods: 2
NCLOC: 53   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
Languages.java 57,1% 82,1% 0% 70,5%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.base;
 11   
 
 12   
 import java.io.BufferedReader;
 13   
 import java.io.InputStreamReader;
 14   
 import java.util.Enumeration;
 15   
 import java.util.HashMap;
 16   
 import java.util.Map;
 17   
 import java.util.StringTokenizer;
 18   
 
 19   
 /**
 20   
  * Contains language codes according to ISO 639.
 21   
  * The codes are set up by reading the two files "languages-2.txt"
 22   
  * and "languages-3.txt" that contain all 2 letter codes from ISO 639
 23   
  * and all 3 letter codes from ISO 639-2, resprectively.
 24   
  */
 25   
 public class Languages {
 26   
 
 27   
   public static Map ourLanguages = new HashMap();
 28   
 
 29  0
   public static boolean contains(String aLanguageCode) {
 30  0
     return null != ourLanguages.get(aLanguageCode);
 31   
   }
 32   
 
 33   
   static {
 34  3
     ourLanguages.put("i", "internal");
 35  3
     ourLanguages.put("x", "extension");
 36  3
     try {
 37  3
       String line;
 38  3
       BufferedReader r = new BufferedReader(new InputStreamReader(Languages.class.getResourceAsStream("languages-2.txt")));
 39  ?
       while (null != (line = r.readLine())) {
 40  417
         if (line.startsWith("#")) {
 41  0
           continue;
 42   
         }
 43  417
         Enumeration e = new StringTokenizer(line);
 44  417
         String name = (String)e.nextElement();
 45  417
         String key = null;
 46  417
         do {
 47  426
           key = (String)e.nextElement();
 48  426
         } while (key.length() != 2);
 49  417
         ourLanguages.put(key.trim().toLowerCase(), name);
 50   
       }
 51  3
       r = new BufferedReader(new InputStreamReader(Languages.class.getResourceAsStream("languages-3.txt")));
 52  ?
       while (null != (line = r.readLine())) {
 53  1485
         if (line.startsWith("#")) {
 54  0
           continue;
 55   
         }
 56  1485
         int idx = line.lastIndexOf(';');
 57  1485
         if (idx >= 0) {
 58  1407
           String codes = line.substring(idx + 1);
 59  1407
           String name = line.substring(0, idx);
 60  1407
           for (Enumeration e = new StringTokenizer(codes, "/");
 61  2880
                   e.hasMoreElements(); ) {
 62  1473
             String s = (String)e.nextElement();
 63  1473
             ourLanguages.put(s.trim().toLowerCase(), name);
 64   
           }
 65   
         }
 66   
       }
 67   
     } catch (Exception e) {
 68  0
       e.printStackTrace();
 69  0
       System.err.println("Language codes are not set up properly");
 70   
     }
 71   
   }
 72   
 
 73  0
   private Languages() {}
 74   
 
 75   
 }
 76