1 16 package com.ibatis.dao.engine.builder.xml; 17 18 import com.ibatis.common.resources.Resources; 19 import org.xml.sax.EntityResolver ; 20 import org.xml.sax.InputSource ; 21 import org.xml.sax.SAXException ; 22 23 import java.io.InputStream ; 24 import java.io.IOException ; 25 import java.util.Map ; 26 import java.util.HashMap ; 27 28 public class DaoClasspathEntityResolver implements EntityResolver { 29 30 private static final String DTD_PATH_DAO = "com/ibatis/dao/engine/builder/xml/dao-2.dtd"; 31 32 private static final Map doctypeMap = new HashMap (); 33 34 static { 35 doctypeMap.put("http://www.ibatis.com/dtd/dao-2.dtd", DTD_PATH_DAO); 36 doctypeMap.put("http://ibatis.apache.org/dtd/dao-2.dtd", DTD_PATH_DAO); 37 doctypeMap.put("-//iBATIS.com//DTD DAO Configuration 2.0", DTD_PATH_DAO); 38 doctypeMap.put("-//iBATIS.com//DTD DAO Config 2.0", DTD_PATH_DAO); 39 } 40 41 42 50 public InputSource resolveEntity(String publicId, String systemId) 51 throws SAXException { 52 InputSource source = null; 53 54 try { 55 String path = (String ) doctypeMap.get(publicId); 56 path = (String ) doctypeMap.get(systemId); 57 if (path != null) { 58 InputStream in = null; 59 try { 60 in = Resources.getResourceAsStream(path); 61 source = new InputSource (in); 62 } catch (IOException e) { 63 } 65 } 66 } catch (Exception e) { 67 throw new SAXException (e.toString()); 68 } 69 70 return source; 71 } 72 73 } 74 | Popular Tags |