1 5 6 package com.hp.hpl.jena.util; 7 8 import java.nio.charset.Charset ; 9 import java.util.*; 10 19 abstract public class CharEncoding { 20 static Set macEncodings = new HashSet(); 21 static { 22 macEncodings.add("MacArabic"); 23 macEncodings.add("MacCentralEurope"); 24 macEncodings.add("MacCroatian"); 25 macEncodings.add("MacCyrillic"); 26 macEncodings.add("MacDingbat"); 27 macEncodings.add("MacGreek"); 28 macEncodings.add("MacHebrew"); 29 macEncodings.add("MacIceland"); 30 macEncodings.add("MacRoman"); 31 macEncodings.add("MacRomania"); 32 macEncodings.add("MacSymbol"); 33 macEncodings.add("MacThai"); 34 macEncodings.add("MacTurkish"); 35 macEncodings.add("MacUkraine"); 36 } 37 private String name; 38 private CharEncoding(){} 39 private CharEncoding(String name) { 40 this.name = name; 41 } 42 53 public String name() { 54 return name; 55 } 56 67 68 abstract public boolean isIANA(); 69 77 abstract public boolean isInNIO(); 78 79 86 abstract public String warningMessage(); 87 static private class IANAnioEncoding extends CharEncoding { 88 IANAnioEncoding(String name) { 89 super(name); 90 } 91 public boolean isIANA() { 92 return true; 93 } 94 public boolean isInNIO() { 95 return true; 96 } 97 public String warningMessage() { 98 return null; 99 } 100 } 101 static private class NonIANAnioEncoding extends CharEncoding { 102 NonIANAnioEncoding(String name) { 103 super(name); 104 } 105 public boolean isIANA() { 106 return false; 107 } 108 public boolean isInNIO() { 109 return true; 110 } 111 public String warningMessage() { 112 return "The encoding \"" + name() + "\" is not registered with IANA, and hence not suitable for Web content."; 113 } 114 } 115 static private class NotNioEncoding extends CharEncoding { 116 NotNioEncoding(String name) { 117 super(name); 118 } 119 public boolean isIANA() { 120 return false; 121 } 122 public boolean isInNIO() { 123 return false; 124 } 125 public String warningMessage() { 126 return "The encoding \"" + name() + "\" is not fully supported; maybe try using Java 1.5 or higher (if you are not already)."; 127 } 128 } 129 130 137 static public CharEncoding create(String enc){ 138 if (Charset.isSupported(enc)) { 139 String nm = Charset.forName(enc).name(); 140 if (nm.charAt(1)=='-' 141 && (nm.charAt(0)=='x' || nm.charAt(0)=='X') ) 142 return new NonIANAnioEncoding(nm); 143 else if (nm.startsWith("Mac") && 144 macEncodings.contains(nm) ) 145 return new NonIANAnioEncoding(nm); 146 else 147 return new IANAnioEncoding(nm); 148 } else { 149 return new NotNioEncoding(enc); 150 } 151 } 152 } 153 154 179 180 | Popular Tags |