Clover coverage report - DynamicJava Test Coverage (dynamicjava-20130622-r5436)
Coverage timestamp: Sat Jun 22 2013 03:01:29 CDT
file stats: LOC: 100   Methods: 2
NCLOC: 41   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
LocalizedMessageReader.java 64.3% 90.9% 100% 81.6%
coverage coverage
 1    /*
 2    * DynamicJava - Copyright (C) 1999-2001
 3    *
 4    * Permission is hereby granted, free of charge, to any person obtaining a
 5    * copy of this software and associated documentation files
 6    * (the "Software"), to deal in the Software without restriction, including
 7    * without limitation the rights to use, copy, modify, merge, publish,
 8    * distribute, sublicense, and/or sell copies of the Software, and to permit
 9    * persons to whom the Software is furnished to do so, subject to the
 10    * following conditions:
 11    * The above copyright notice and this permission notice shall be included
 12    * in all copies or substantial portions of the Software.
 13    *
 14    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 15    * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 16    * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 17    * IN NO EVENT SHALL DYADE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 18    * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 19    * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 20    * DEALINGS IN THE SOFTWARE.
 21    *
 22    * Except as contained in this notice, the name of Dyade shall not be
 23    * used in advertising or otherwise to promote the sale, use or other
 24    * dealings in this Software without prior written authorization from
 25    * Dyade.
 26    *
 27    */
 28   
 29    package koala.dynamicjava.util;
 30   
 31    import java.util.*;
 32   
 33    /**
 34    * The instances of this class read localized messages in resource files.
 35    * The messages in the file are templates. Context specific strings are
 36    * inserted where '%n' patterns can be found. A '%' character is represented
 37    * with '%%'.
 38    *
 39    * @author Stephane Hillion
 40    * @version 1.0 - 1999/08/04
 41    */
 42   
 43    public class LocalizedMessageReader {
 44    /**
 45    * The escape character
 46    */
 47    private final static char ESCAPE_CHAR = '%';
 48   
 49    /**
 50    * The resource bundle
 51    */
 52    private ResourceBundle bundle;
 53   
 54    /**
 55    * Creates a new message reader
 56    * @param name the name of the resource
 57    */
 58  794 public LocalizedMessageReader(String name) {
 59  794 bundle = ResourceBundle.getBundle(name);
 60    }
 61   
 62    /**
 63    * Gets a message
 64    * @param key the message key
 65    * @param strings the strings to insert in the message
 66    */
 67  141 public String getMessage(String key, String[] strings) {
 68  141 String rawMessage = bundle.getString(key);
 69  141 String result = "";
 70   
 71  141 if (rawMessage != null) {
 72  141 for (int i = 0; i < rawMessage.length(); i++) {
 73  8940 char c = rawMessage.charAt(i);
 74  8940 if (c == ESCAPE_CHAR) {
 75  375 c = rawMessage.charAt(++i);
 76  375 if (c == ESCAPE_CHAR) {
 77  0 result += c;
 78    } else {
 79  375 String numb = "";
 80  375 do {
 81  ? if (!Character.isDigit(c = rawMessage.charAt(i))) {
 82  252 i--;
 83  252 break;
 84    }
 85  375 numb += c;
 86  375 } while (++i < rawMessage.length());
 87  375 int n = Integer.parseInt(numb);
 88  375 if (n >= strings.length) {
 89  0 throw new IllegalArgumentException("Missing argument " + n + " for error code " + key);
 90    }
 91  375 result += strings[n];
 92    }
 93    } else {
 94  8565 result += c;
 95    }
 96    }
 97    }
 98  141 return result;
 99    }
 100    }