1 5 6 package org.w3c.tidy; 7 8 33 34 import java.util.Hashtable ; 35 import java.util.Enumeration ; 36 37 public class EntityTable { 38 39 public EntityTable() 40 { 41 } 42 43 public Entity lookup( String name ) 44 { 45 return (Entity)entityHashtable.get( name ); 46 } 47 48 public Entity install( String name, short code ) 49 { 50 Entity ent = lookup( name ); 51 if ( ent == null ) { 52 ent = new Entity( name, code ); 53 entityHashtable.put( name, ent ); 54 } else { 55 ent.code = code; 56 } 57 return ent; 58 } 59 60 public Entity install( Entity ent ) 61 { 62 return (Entity)entityHashtable.put( ent.name, ent ); 63 } 64 65 66 public short entityCode( String name ) 67 { 68 int c; 69 70 if (name.length() <= 1) 71 return 0; 72 73 74 if ( name.charAt(1) == '#' ) { 75 c = 0; 76 77 78 try { 79 if (name.length() >= 4 && name.charAt(2) == 'x') { 80 c = Integer.parseInt( name.substring(3), 16 ); 81 } else if (name.length() >= 3) { 82 c = Integer.parseInt( name.substring(2) ); 83 } 84 } 85 catch ( NumberFormatException e ) {} 86 87 return (short)c; 88 } 89 90 91 Entity ent = lookup( name.substring(1) ); 92 if ( ent != null ) { 93 return ent.code; 94 } 95 96 return 0; 97 } 98 99 public String entityName( short code ) 100 { 101 String name = null; 102 Entity ent; 103 Enumeration en = entityHashtable.elements(); 104 while ( en.hasMoreElements() ) { 105 ent = (Entity)en.nextElement(); 106 if ( ent.code == code ) { 107 name = ent.name; 108 break; 109 } 110 } 111 return name; 112 } 113 114 private Hashtable entityHashtable = new Hashtable (); 115 116 private static EntityTable defaultEntityTable = null; 117 118 private static Entity[] entities = { 119 120 new Entity( "nbsp", 160 ), 121 new Entity( "iexcl", 161 ), 122 new Entity( "cent", 162 ), 123 new Entity( "pound", 163 ), 124 new Entity( "curren", 164 ), 125 new Entity( "yen", 165 ), 126 new Entity( "brvbar", 166 ), 127 new Entity( "sect", 167 ), 128 new Entity( "uml", 168 ), 129 new Entity( "copy", 169 ), 130 new Entity( "ordf", 170 ), 131 new Entity( "laquo", 171 ), 132 new Entity( "not", 172 ), 133 new Entity( "shy", 173 ), 134 new Entity( "reg", 174 ), 135 new Entity( "macr", 175 ), 136 new Entity( "deg", 176 ), 137 new Entity( "plusmn", 177 ), 138 new Entity( "sup2", 178 ), 139 new Entity( "sup3", 179 ), 140 new Entity( "acute", 180 ), 141 new Entity( "micro", 181 ), 142 new Entity( "para", 182 ), 143 new Entity( "middot", 183 ), 144 new Entity( "cedil", 184 ), 145 new Entity( "sup1", 185 ), 146 new Entity( "ordm", 186 ), 147 new Entity( "raquo", 187 ), 148 new Entity( "frac14", 188 ), 149 new Entity( "frac12", 189 ), 150 new Entity( "frac34", 190 ), 151 new Entity( "iquest", 191 ), 152 new Entity( "Agrave", 192 ), 153 new Entity( "Aacute", 193 ), 154 new Entity( "Acirc", 194 ), 155 new Entity( "Atilde", 195 ), 156 new Entity( "Auml", 196 ), 157 new Entity( "Aring", 197 ), 158 new Entity( "AElig", 198 ), 159 new Entity( "Ccedil", 199 ), 160 new Entity( "Egrave", 200 ), 161 new Entity( "Eacute", 201 ), 162 new Entity( "Ecirc", 202 ), 163 new Entity( "Euml", 203 ), 164 new Entity( "Igrave", 204 ), 165 new Entity( "Iacute", 205 ), 166 new Entity( "Icirc", 206 ), 167 new Entity( "Iuml", 207 ), 168 new Entity( "ETH", 208 ), 169 new Entity( "Ntilde", 209 ), 170 new Entity( "Ograve", 210 ), 171 new Entity( "Oacute", 211 ), 172 new Entity( "Ocirc", 212 ), 173 new Entity( "Otilde", 213 ), 174 new Entity( "Ouml", 214 ), 175 new Entity( "times", 215 ), 176 new Entity( "Oslash", 216 ), 177 new Entity( "Ugrave", 217 ), 178 new Entity( "Uacute", 218 ), 179 new Entity( "Ucirc", 219 ), 180 new Entity( "Uuml", 220 ), 181 new Entity( "Yacute", 221 ), 182 new Entity( "THORN", 222 ), 183 new Entity( "szlig", 223 ), 184 new Entity( "agrave", 224 ), 185 new Entity( "aacute", 225 ), 186 new Entity( "acirc", 226 ), 187 new Entity( "atilde", 227 ), 188 new Entity( "auml", 228 ), 189 new Entity( "aring", 229 ), 190 new Entity( "aelig", 230 ), 191 new Entity( "ccedil", 231 ), 192 new Entity( "egrave", 232 ), 193 new Entity( "eacute", 233 ), 194 new Entity( "ecirc", 234 ), 195 new Entity( "euml", 235 ), 196 new Entity( "igrave", 236 ), 197 new Entity( "iacute", 237 ), 198 new Entity( "icirc", 238 ), 199 new Entity( "iuml", 239 ), 200 new Entity( "eth", 240 ), 201 new Entity( "ntilde", 241 ), 202 new Entity( "ograve", 242 ), 203 new Entity( "oacute", 243 ), 204 new Entity( "ocirc", 244 ), 205 new Entity( "otilde", 245 ), 206 new Entity( "ouml", 246 ), 207 new Entity( "divide", 247 ), 208 new Entity( "oslash", 248 ), 209 new Entity( "ugrave", 249 ), 210 new Entity( "uacute", 250 ), 211 new Entity( "ucirc", 251 ), 212 new Entity( "uuml", 252 ), 213 new Entity( "yacute", 253 ), 214 new Entity( "thorn", 254 ), 215 new Entity( "yuml", 255 ), 216 new Entity( "fnof", 402 ), 217 new Entity( "Alpha", 913 ), 218 new Entity( "Beta", 914 ), 219 new Entity( "Gamma", 915 ), 220 new Entity( "Delta", 916 ), 221 new Entity( "Epsilon", 917 ), 222 new Entity( "Zeta", 918 ), 223 new Entity( "Eta", 919 ), 224 new Entity( "Theta", 920 ), 225 new Entity( "Iota", 921 ), 226 new Entity( "Kappa", 922 ), 227 new Entity( "Lambda", 923 ), 228 new Entity( "Mu", 924 ), 229 new Entity( "Nu", 925 ), 230 new Entity( "Xi", 926 ), 231 new Entity( "Omicron", 927 ), 232 new Entity( "Pi", 928 ), 233 new Entity( "Rho", 929 ), 234 new Entity( "Sigma", 931 ), 235 new Entity( "Tau", 932 ), 236 new Entity( "Upsilon", 933 ), 237 new Entity( "Phi", 934 ), 238 new Entity( "Chi", 935 ), 239 new Entity( "Psi", 936 ), 240 new Entity( "Omega", 937 ), 241 new Entity( "alpha", 945 ), 242 new Entity( "beta", 946 ), 243 new Entity( "gamma", 947 ), 244 new Entity( "delta", 948 ), 245 new Entity( "epsilon", 949 ), 246 new Entity( "zeta", 950 ), 247 new Entity( "eta", 951 ), 248 new Entity( "theta", 952 ), 249 new Entity( "iota", 953 ), 250 new Entity( "kappa", 954 ), 251 new Entity( "lambda", 955 ), 252 new Entity( "mu", 956 ), 253 new Entity( "nu", 957 ), 254 new Entity( "xi", 958 ), 255 new Entity( "omicron", 959 ), 256 new Entity( "pi", 960 ), 257 new Entity( "rho", 961 ), 258 new Entity( "sigmaf", 962 ), 259 new Entity( "sigma", 963 ), 260 new Entity( "tau", 964 ), 261 new Entity( "upsilon", 965 ), 262 new Entity( "phi", 966 ), 263 new Entity( "chi", 967 ), 264 new Entity( "psi", 968 ), 265 new Entity( "omega", 969 ), 266 new Entity( "thetasym", 977 ), 267 new Entity( "upsih", 978 ), 268 new Entity( "piv", 982 ), 269 new Entity( "bull", 8226 ), 270 new Entity( "hellip", 8230 ), 271 new Entity( "prime", 8242 ), 272 new Entity( "Prime", 8243 ), 273 new Entity( "oline", 8254 ), 274 new Entity( "frasl", 8260 ), 275 new Entity( "weierp", 8472 ), 276 new Entity( "image", 8465 ), 277 new Entity( "real", 8476 ), 278 new Entity( "trade", 8482 ), 279 new Entity( "alefsym", 8501 ), 280 new Entity( "larr", 8592 ), 281 new Entity( "uarr", 8593 ), 282 new Entity( "rarr", 8594 ), 283 new Entity( "darr", 8595 ), 284 new Entity( "harr", 8596 ), 285 new Entity( "crarr", 8629 ), 286 new Entity( "lArr", 8656 ), 287 new Entity( "uArr", 8657 ), 288 new Entity( "rArr", 8658 ), 289 new Entity( "dArr", 8659 ), 290 new Entity( "hArr", 8660 ), 291 new Entity( "forall", 8704 ), 292 new Entity( "part", 8706 ), 293 new Entity( "exist", 8707 ), 294 new Entity( "empty", 8709 ), 295 new Entity( "nabla", 8711 ), 296 new Entity( "isin", 8712 ), 297 new Entity( "notin", 8713 ), 298 new Entity( "ni", 8715 ), 299 new Entity( "prod", 8719 ), 300 new Entity( "sum", 8721 ), 301 new Entity( "minus", 8722 ), 302 new Entity( "lowast", 8727 ), 303 new Entity( "radic", 8730 ), 304 new Entity( "prop", 8733 ), 305 new Entity( "infin", 8734 ), 306 new Entity( "ang", 8736 ), 307 new Entity( "and", 8743 ), 308 new Entity( "or", 8744 ), 309 new Entity( "cap", 8745 ), 310 new Entity( "cup", 8746 ), 311 new Entity( "int", 8747 ), 312 new Entity( "there4", 8756 ), 313 new Entity( "sim", 8764 ), 314 new Entity( "cong", 8773 ), 315 new Entity( "asymp", 8776 ), 316 new Entity( "ne", 8800 ), 317 new Entity( "equiv", 8801 ), 318 new Entity( "le", 8804 ), 319 new Entity( "ge", 8805 ), 320 new Entity( "sub", 8834 ), 321 new Entity( "sup", 8835 ), 322 new Entity( "nsub", 8836 ), 323 new Entity( "sube", 8838 ), 324 new Entity( "supe", 8839 ), 325 new Entity( "oplus", 8853 ), 326 new Entity( "otimes", 8855 ), 327 new Entity( "perp", 8869 ), 328 new Entity( "sdot", 8901 ), 329 new Entity( "lceil", 8968 ), 330 new Entity( "rceil", 8969 ), 331 new Entity( "lfloor", 8970 ), 332 new Entity( "rfloor", 8971 ), 333 new Entity( "lang", 9001 ), 334 new Entity( "rang", 9002 ), 335 new Entity( "loz", 9674 ), 336 new Entity( "spades", 9824 ), 337 new Entity( "clubs", 9827 ), 338 new Entity( "hearts", 9829 ), 339 new Entity( "diams", 9830 ), 340 new Entity( "quot", 34 ), 341 new Entity( "amp", 38 ), 342 new Entity( "lt", 60 ), 343 new Entity( "gt", 62 ), 344 new Entity( "OElig", 338 ), 345 new Entity( "oelig", 339 ), 346 new Entity( "Scaron", 352 ), 347 new Entity( "scaron", 353 ), 348 new Entity( "Yuml", 376 ), 349 new Entity( "circ", 710 ), 350 new Entity( "tilde", 732 ), 351 new Entity( "ensp", 8194 ), 352 new Entity( "emsp", 8195 ), 353 new Entity( "thinsp", 8201 ), 354 new Entity( "zwnj", 8204 ), 355 new Entity( "zwj", 8205 ), 356 new Entity( "lrm", 8206 ), 357 new Entity( "rlm", 8207 ), 358 new Entity( "ndash", 8211 ), 359 new Entity( "mdash", 8212 ), 360 new Entity( "lsquo", 8216 ), 361 new Entity( "rsquo", 8217 ), 362 new Entity( "sbquo", 8218 ), 363 new Entity( "ldquo", 8220 ), 364 new Entity( "rdquo", 8221 ), 365 new Entity( "bdquo", 8222 ), 366 new Entity( "dagger", 8224 ), 367 new Entity( "Dagger", 8225 ), 368 new Entity( "permil", 8240 ), 369 new Entity( "lsaquo", 8249 ), 370 new Entity( "rsaquo", 8250 ), 371 new Entity( "euro", 8364 ) 372 373 }; 374 375 public static EntityTable getDefaultEntityTable() 376 { 377 if ( defaultEntityTable == null ) { 378 defaultEntityTable = new EntityTable(); 379 for ( int i = 0; i < entities.length; i++ ) { 380 defaultEntityTable.install( entities[i] ); 381 } 382 } 383 return defaultEntityTable; 384 } 385 386 } 387 | Popular Tags |