1 16 package net.sf.dozer.util.mapping.util; 17 18 import java.io.InputStream ; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 import org.xml.sax.EntityResolver ; 23 import org.xml.sax.InputSource ; 24 import org.xml.sax.SAXException ; 25 26 35 public class DozerResolver implements EntityResolver { 36 37 private static final Log log = LogFactory.getLog(DozerResolver.class); 38 39 public InputSource resolveEntity(String publicId, String systemId) throws SAXException { 40 log.debug("Trying to resolve XML entity with public ID [" + publicId + "] and system ID [" + systemId + "]"); 41 if (systemId != null && systemId.indexOf(MapperConstants.DTD_NAME) > systemId.lastIndexOf("/")) { 42 String dtdFile = systemId.substring(systemId.indexOf(MapperConstants.DTD_NAME)); 43 log.debug("Trying to locate [" + dtdFile + "] in classpath"); 44 try { 45 InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(dtdFile); 46 InputSource source = new InputSource (stream); 47 source.setPublicId(publicId); 48 source.setSystemId(systemId); 49 log.debug("Found dozerbeanmapping DTD [" + systemId + "] in classpath"); 50 return source; 51 } catch (Exception ex) { 52 log.error("Could not resolve beans DTD [" + systemId + "]: not found in classpath", ex); 53 } 54 } 55 return null; 57 } 58 } 59 | Popular Tags |