Clover coverage report - Clover results for XOM 1.2d1
Coverage timestamp: Wed Feb 8 2006 08:31:33 EST
file stats: LOC: 130   Methods: 1
NCLOC: 89   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TextWriterFactory.java 92.1% 90.5% 100% 91.4%
coverage coverage
 1    /* Copyright 2002-2004 Elliotte Rusty Harold
 2   
 3    This library is free software; you can redistribute it and/or modify
 4    it under the terms of version 2.1 of the GNU Lesser General Public
 5    License as published by the Free Software Foundation.
 6   
 7    This library is distributed in the hope that it will be useful,
 8    but WITHOUT ANY WARRANTY; without even the implied warranty of
 9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 10    GNU Lesser General Public License for more details.
 11   
 12    You should have received a copy of the GNU Lesser General Public
 13    License along with this library; if not, write to the
 14    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 15    Boston, MA 02111-1307 USA
 16   
 17    You can contact Elliotte Rusty Harold by sending e-mail to
 18    elharo@metalab.unc.edu. Please include the word "XOM" in the
 19    subject line. The XOM home page is located at http://www.xom.nu/
 20    */
 21   
 22    package nu.xom;
 23   
 24    import java.io.UnsupportedEncodingException;
 25    import java.io.Writer;
 26    import java.util.Locale;
 27   
 28    /**
 29    * @author Elliotte Rusty Harold
 30    * @version 1.0
 31    */
 32    class TextWriterFactory {
 33   
 34  19228 public static TextWriter getTextWriter(
 35    Writer out, String encoding) {
 36   
 37    // Not all encoding names are case-insensitive in Java, even
 38    // though they should be. For instance, MacRoman isn't.
 39  19228 String encodingUpperCase = encoding.toUpperCase(Locale.ENGLISH);
 40  19228 if (encodingUpperCase.startsWith("UTF")
 41    || encodingUpperCase.startsWith("UNICODE")
 42    ) {
 43  19160 return new UnicodeWriter(out, encoding);
 44    }
 45  68 else if (encodingUpperCase.startsWith("ISO-10646-UCS")
 46    || encodingUpperCase.startsWith("UCS")
 47    || encodingUpperCase.equals("GB18030")) {
 48    // GB18030 has a 1-1 mapping to Unicode. However, the Sun
 49    // GB18030 VM is buggy with non-BMP characters. The IBM VM
 50    // gets this right, but for safety we'll escape all non-BMP
 51    // characters.
 52  2 return new UCSWriter(out, encoding);
 53    }
 54  66 else if (encodingUpperCase.equals("ISO-8859-1")) {
 55  33 return new Latin1Writer(out, encoding);
 56    }
 57  33 else if (encodingUpperCase.equals("ISO-8859-2")) {
 58  1 return new Latin2Writer(out, encodingUpperCase);
 59    }
 60  32 else if (encodingUpperCase.equals("ISO-8859-3")) {
 61  1 return new Latin3Writer(out, encodingUpperCase);
 62    }
 63  31 else if (encodingUpperCase.equals("ISO-8859-4")) {
 64  1 return new Latin4Writer(out, encodingUpperCase);
 65    }
 66  30 else if (encodingUpperCase.equals("ISO-8859-5")) {
 67  4 return new ISOCyrillicWriter(out, encodingUpperCase);
 68    }
 69  26 else if (encodingUpperCase.equals("ISO-8859-6")) {
 70  1 return new ISOArabicWriter(out, encodingUpperCase);
 71    }
 72  25 else if (encodingUpperCase.equals("ISO-8859-7")) {
 73  1 return new ISOGreekWriter(out, encodingUpperCase);
 74    }
 75  24 else if (encodingUpperCase.equals("ISO-8859-8")) {
 76  1 return new ISOHebrewWriter(out, encodingUpperCase);
 77    }
 78  23 else if (encodingUpperCase.equals("ISO-8859-9")
 79    || encodingUpperCase.equals("EBCDIC-CP-TR")
 80    || encodingUpperCase.equals("CP1037")) {
 81  1 return new Latin5Writer(out, encodingUpperCase);
 82    }
 83  22 else if (encoding.equals("ISO-8859-10")) {
 84  0 return new Latin6Writer(out, encoding);
 85    }
 86  22 else if (encodingUpperCase.equals("ISO-8859-11")
 87    || encodingUpperCase.equals("TIS-620")
 88    || encodingUpperCase.equals("TIS620")) {
 89  1 return new ISOThaiWriter(out, encodingUpperCase);
 90    }
 91    // There's no such thing as ISO-8859-12
 92    // nor is there likely to be one in the future.
 93  21 else if (encodingUpperCase.equals("ISO-8859-13")) {
 94  1 return new Latin7Writer(out, encodingUpperCase);
 95    }
 96  20 else if (encoding.equals("ISO-8859-14")) {
 97  0 return new Latin8Writer(out, encoding);
 98    }
 99  20 else if (encodingUpperCase.equals("ISO-8859-15")) {
 100  1 return new Latin9Writer(out, encodingUpperCase);
 101    }
 102  19 else if (encoding.equals("ISO-8859-16")) {
 103  0 return new Latin10Writer(out, encoding);
 104    }
 105  19 else if (encodingUpperCase.endsWith("ASCII")) {
 106  11 return new ASCIIWriter(out, encodingUpperCase);
 107    }
 108  8 else if (encodingUpperCase.equals("IBM037")
 109    || encodingUpperCase.equals("CP037")
 110    || encodingUpperCase.equals("EBCDIC-CP-US")
 111    || encodingUpperCase.equals("EBCDIC-CP-CA")
 112    || encodingUpperCase.equals("EBCDIC-CP-WA")
 113    || encodingUpperCase.equals("EBCDIC-CP-NL")
 114    || encodingUpperCase.equals("CSIBM037")) {
 115    // EBCDIC-37 has same character set as ISO-8859-1;
 116    // just at different code points.
 117  1 return new Latin1Writer(out, encodingUpperCase);
 118    }
 119    else {
 120  7 try {
 121  7 return new GenericWriter(out, encoding);
 122    }
 123    catch (UnsupportedEncodingException ex) {
 124  0 return new ASCIIWriter(out, encoding);
 125    }
 126    }
 127   
 128    }
 129   
 130    }