1 21 22 package nu.xom; 23 24 import java.io.UnsupportedEncodingException ; 25 import java.io.Writer ; 26 import java.util.Locale ; 27 28 32 class TextWriterFactory { 33 34 public static TextWriter getTextWriter( 35 Writer out, String encoding) { 36 37 String encodingUpperCase = encoding.toUpperCase(Locale.ENGLISH); 40 if (encodingUpperCase.startsWith("UTF") 41 || encodingUpperCase.startsWith("UNICODE") 42 ) { 43 return new UnicodeWriter(out, encoding); 44 } 45 else if (encodingUpperCase.startsWith("ISO-10646-UCS") 46 || encodingUpperCase.startsWith("UCS") 47 || encodingUpperCase.equals("GB18030")) { 48 return new UCSWriter(out, encoding); 53 } 54 else if (encodingUpperCase.equals("ISO-8859-1")) { 55 return new Latin1Writer(out, encoding); 56 } 57 else if (encodingUpperCase.equals("ISO-8859-2")) { 58 return new Latin2Writer(out, encodingUpperCase); 59 } 60 else if (encodingUpperCase.equals("ISO-8859-3")) { 61 return new Latin3Writer(out, encodingUpperCase); 62 } 63 else if (encodingUpperCase.equals("ISO-8859-4")) { 64 return new Latin4Writer(out, encodingUpperCase); 65 } 66 else if (encodingUpperCase.equals("ISO-8859-5")) { 67 return new ISOCyrillicWriter(out, encodingUpperCase); 68 } 69 else if (encodingUpperCase.equals("ISO-8859-6")) { 70 return new ISOArabicWriter(out, encodingUpperCase); 71 } 72 else if (encodingUpperCase.equals("ISO-8859-7")) { 73 return new ISOGreekWriter(out, encodingUpperCase); 74 } 75 else if (encodingUpperCase.equals("ISO-8859-8")) { 76 return new ISOHebrewWriter(out, encodingUpperCase); 77 } 78 else if (encodingUpperCase.equals("ISO-8859-9") 79 || encodingUpperCase.equals("EBCDIC-CP-TR") 80 || encodingUpperCase.equals("CP1037")) { 81 return new Latin5Writer(out, encodingUpperCase); 82 } 83 else if (encoding.equals("ISO-8859-10")) { 84 return new Latin6Writer(out, encoding); 85 } 86 else if (encodingUpperCase.equals("ISO-8859-11") 87 || encodingUpperCase.equals("TIS-620") 88 || encodingUpperCase.equals("TIS620")) { 89 return new ISOThaiWriter(out, encodingUpperCase); 90 } 91 else if (encodingUpperCase.equals("ISO-8859-13")) { 94 return new Latin7Writer(out, encodingUpperCase); 95 } 96 else if (encoding.equals("ISO-8859-14")) { 97 return new Latin8Writer(out, encoding); 98 } 99 else if (encodingUpperCase.equals("ISO-8859-15")) { 100 return new Latin9Writer(out, encodingUpperCase); 101 } 102 else if (encoding.equals("ISO-8859-16")) { 103 return new Latin10Writer(out, encoding); 104 } 105 else if (encodingUpperCase.endsWith("ASCII")) { 106 return new ASCIIWriter(out, encodingUpperCase); 107 } 108 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 return new Latin1Writer(out, encodingUpperCase); 118 } 119 else { 120 try { 121 return new GenericWriter(out, encoding); 122 } 123 catch (UnsupportedEncodingException ex) { 124 return new ASCIIWriter(out, encoding); 125 } 126 } 127 128 } 129 130 } 131 | Popular Tags |