1 4 package org.jfox.ioc.util; 5 6 import java.io.IOException ; 7 import java.io.InputStream ; 8 import java.util.Properties ; 9 10 import org.xml.sax.EntityResolver ; 11 import org.xml.sax.InputSource ; 12 import org.xml.sax.SAXException ; 13 14 17 18 public class DTDEntityResolver implements EntityResolver { 19 private static Properties pubToLocal = new Properties (); 21 private final static String DTD_PROPERTIES = "dtd.properties"; 22 private final static ClassLoader cl = Thread.currentThread().getContextClassLoader(); 23 24 static { 25 InputStream fin = null; 26 try { 27 fin = cl.getResourceAsStream(DTD_PROPERTIES); pubToLocal.load(fin); 29 } 30 catch(Exception e) { 31 e.printStackTrace(); 32 } 33 finally { 34 if(fin != null) { 35 try { 36 fin.close(); 37 } 38 catch(Exception e) { 39 e.printStackTrace(); 40 } 41 } 42 } 43 } 44 45 46 public InputSource resolveEntity(String publicId, String systemId) throws SAXException , IOException { 47 if(publicId == null) return null; 48 if(!pubToLocal.containsKey(publicId)) return null; 50 51 String dtd = pubToLocal.getProperty(publicId); 52 try { 53 InputSource inputSource = new InputSource (cl.getResourceAsStream(dtd)); 55 return inputSource; 56 } 57 catch(Exception e) { 58 e.printStackTrace(); 59 return null; 60 } 61 } 62 63 public static void main(String [] args) { 64 65 } 66 } 67 68 69 70 | Popular Tags |