1 16 package com.ibatis.sqlmap.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 import java.util.Collections ; 28 29 32 public class SqlMapClasspathEntityResolver implements EntityResolver { 33 34 private static final String SQL_MAP_CONFIG_DTD = "com/ibatis/sqlmap/engine/builder/xml/sql-map-config-2.dtd"; 35 private static final String SQL_MAP_DTD = "com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd"; 36 37 private static final Map doctypeMap = new HashMap (); 38 39 static { 40 doctypeMap.put("http://www.ibatis.com/dtd/sql-map-config-2.dtd", SQL_MAP_CONFIG_DTD); 41 doctypeMap.put("http://ibatis.apache.org/dtd/sql-map-config-2.dtd", SQL_MAP_CONFIG_DTD); 42 doctypeMap.put("-//iBATIS.com//DTD SQL Map Config 2.0//EN", SQL_MAP_CONFIG_DTD); 43 44 doctypeMap.put("http://www.ibatis.com/dtd/sql-map-2.dtd", SQL_MAP_DTD); 45 doctypeMap.put("http://ibatis.apache.org/dtd/sql-map-2.dtd", SQL_MAP_DTD); 46 doctypeMap.put("-//iBATIS.com//DTD SQL Map 2.0//EN", SQL_MAP_DTD); 47 } 48 49 50 58 public InputSource resolveEntity(String publicId, String systemId) 59 throws SAXException { 60 InputSource source = null; 61 try { 62 String path = (String ) doctypeMap.get(publicId); 63 path = (String ) doctypeMap.get(systemId); 64 if (path != null) { 65 InputStream in = null; 66 try { 67 in = Resources.getResourceAsStream(path); 68 source = new InputSource (in); 69 } catch (IOException e) { 70 } 72 } 73 } catch (Exception e) { 74 throw new SAXException (e.toString()); 75 } 76 return source; 77 } 78 79 } 80 | Popular Tags |