1 package com.icl.saxon.charcode; 2 import com.icl.saxon.Loader; 3 import javax.xml.transform.OutputKeys ; 4 import java.util.Properties ; 5 6 9 10 11 public class CharacterSetFactory { 12 13 14 17 18 public static CharacterSet getCharacterSet(Properties details) { 19 String encoding = details.getProperty(OutputKeys.ENCODING); 20 if (encoding==null) encoding = "UTF8"; 21 if (encoding.equalsIgnoreCase("utf-8")) encoding = "UTF8"; 23 CharacterSet charSet = makeCharacterSet(encoding); 24 if (charSet==null) { 25 charSet = new ASCIICharacterSet(); 26 } 27 return charSet; 28 } 29 30 public static CharacterSet makeCharacterSet(String encoding) { 31 32 if (encoding.equalsIgnoreCase("ASCII")) { 33 return new ASCIICharacterSet(); 34 } else if (encoding.equalsIgnoreCase("US-ASCII")) { 35 return new ASCIICharacterSet(); 36 } else if (encoding.equalsIgnoreCase("iso-8859-1")) { 37 return new Latin1CharacterSet(); 38 } else if (encoding.equalsIgnoreCase("ISO8859_1")) { 39 return new Latin1CharacterSet(); 40 } else if (encoding.equalsIgnoreCase("iso-8859-2")) { 41 return new Latin2CharacterSet(); 42 } else if (encoding.equalsIgnoreCase("ISO8859_2")) { 43 return new Latin2CharacterSet(); 44 } else if (encoding.equalsIgnoreCase("utf-8")) { 45 return new UnicodeCharacterSet(); 46 } else if (encoding.equalsIgnoreCase("UTF8")) { 47 return new UnicodeCharacterSet(); 48 } else if (encoding.equalsIgnoreCase("utf-16")) { 49 return new UnicodeCharacterSet(); 50 } else if (encoding.equalsIgnoreCase("utf16")) { 51 return new UnicodeCharacterSet(); 52 } else if (encoding.equalsIgnoreCase("KOI8-R")) { 53 return new KOI8RCharacterSet(); 54 } else if (encoding.equalsIgnoreCase("cp1251")) { 55 return new CP1251CharacterSet(); 56 } else if (encoding.equalsIgnoreCase("windows-1251")) { 57 return new CP1251CharacterSet(); 58 } else if (encoding.equalsIgnoreCase("cp1250")) { 59 return new CP1250CharacterSet(); 60 } else if (encoding.equalsIgnoreCase("windows-1250")) { 61 return new CP1250CharacterSet(); 62 } else if (encoding.equalsIgnoreCase("cp852")) { 63 return new CP852CharacterSet(); 64 65 } else { 66 String csname = null; 67 try { 68 csname = System.getProperty(OutputKeys.ENCODING + "." + encoding); 70 if (csname == null) { 71 csname = encoding; 72 } 73 Object obj = Loader.getInstance(csname); 74 if (obj instanceof PluggableCharacterSet) { 75 return (PluggableCharacterSet)obj; 76 } 77 } catch (Exception err) { 78 System.err.println("Failed to load " + csname); 79 } 80 } 81 82 return null; 83 84 } 85 } 86 87 | Popular Tags |