1 57 58 package org.enhydra.apache.xerces.readers; 59 60 import java.io.IOException ; 61 import java.util.Enumeration ; 62 import java.util.Hashtable ; 63 64 import org.xml.sax.EntityResolver ; 65 import org.xml.sax.InputSource ; 66 import org.xml.sax.SAXException ; 67 68 93 public abstract class XMLCatalogHandler implements EntityResolver { 94 95 104 public abstract void loadCatalog(InputSource source) throws Exception ; 105 106 107 111 112 private Hashtable publicMap = new Hashtable (); 113 114 115 private Hashtable systemMap = new Hashtable (); 116 117 121 127 public void addPublicMapping(String publicId, String systemId) { 128 publicMap.put(publicId, systemId); 129 } 130 131 136 public void removePublicMapping(System publicId) { 137 publicMap.remove(publicId); 138 } 139 140 141 public Enumeration getPublicMappingKeys() { 142 return publicMap.keys(); 143 } 144 145 153 public String getPublicMapping(String publicId) { 154 return (String )publicMap.get(publicId); 155 } 156 157 163 public void addSystemMapping(String systemId1, String systemId2) { 164 systemMap.put(systemId1, systemId2); 165 } 166 167 172 public void removeSystemMapping(String systemId) { 173 systemMap.remove(systemId); 174 } 175 176 177 public Enumeration getSystemMappingKeys() { 178 return systemMap.keys(); 179 } 180 181 189 public String getSystemMapping(String systemId) { 190 return (String )systemMap.get(systemId); 191 } 192 193 208 public InputSource resolveEntity(String publicId, String systemId) throws SAXException , IOException 209 { 210 211 if (publicId != null) { 213 String value = getPublicMapping(publicId); 214 if (value != null) { 215 return new InputSource (value); 216 } 217 } 218 219 if (systemId != null) { 221 String value = getSystemMapping(systemId); 222 if (value == null) { 223 value = systemId; 224 } 225 226 return new InputSource (value); 227 } 228 229 return null; 230 231 } 232 } 233 | Popular Tags |