1 7 8 package org.cyberneko.html; 9 10 import java.io.IOException ; 11 import java.util.Enumeration ; 12 import java.util.Properties ; 13 14 21 public class HTMLEntities { 22 23 27 28 protected static final Properties ENTITIES = new Properties (); 29 30 31 protected static final IntProperties SEITITNE = new IntProperties(); 32 33 37 static { 38 load0("res/HTMLlat1.properties"); 40 load0("res/HTMLspecial.properties"); 41 load0("res/HTMLsymbol.properties"); 42 load0("res/XMLbuiltin.properties"); 43 44 Enumeration keys = ENTITIES.propertyNames(); 46 while (keys.hasMoreElements()) { 47 String key = (String )keys.nextElement(); 48 String value = ENTITIES.getProperty(key); 49 if (value.length() == 1) { 50 int ivalue = value.charAt(0); 51 SEITITNE.put(ivalue, key); 52 } 53 } 54 } 55 56 60 64 public static int get(String name) { 65 String value = (String )ENTITIES.get(name); 66 return value != null ? value.charAt(0) : -1; 67 } 69 73 public static String get(int c) { 74 return SEITITNE.get(c); 75 } 77 81 82 private static void load0(String filename) { 83 try { 84 ENTITIES.load(HTMLEntities.class.getResourceAsStream(filename)); 85 } 86 catch (IOException e) { 87 System.err.println("error: unable to load resource \""+filename+"\""); 88 } 89 } 91 95 static class IntProperties { 96 private int top = 0; 97 private Entry[] entries = new Entry[101]; 98 public void put(int key, String value) { 99 int hash = key % entries.length; 100 Entry entry = new Entry(key, value, entries[hash]); 101 entries[hash] = entry; 102 } 103 public String get(int key) { 104 int hash = key % entries.length; 105 Entry entry = entries[hash]; 106 while (entry != null) { 107 if (entry.key == key) { 108 return entry.value; 109 } 110 entry = entry.next; 111 } 112 return null; 113 } 114 static class Entry { 115 public int key; 116 public String value; 117 public Entry next; 118 public Entry(int key, String value, Entry next) { 119 this.key = key; 120 this.value = value; 121 this.next = next; 122 } 123 } 124 } 125 126 } | Popular Tags |