1 3 package org.jgroups.conf; 4 5 11 12 import org.xml.sax.EntityResolver ; 13 import org.xml.sax.InputSource ; 14 import org.xml.sax.SAXException ; 15 16 import java.io.InputStream ; 17 import java.io.IOException ; 18 import java.net.URL ; 19 20 public class ClassPathEntityResolver implements EntityResolver { 21 public String mDefaultJGroupsDTD="jgroups-protocol.dtd"; 22 23 public ClassPathEntityResolver() { 24 } 25 26 public ClassPathEntityResolver(String dtdName) { 27 mDefaultJGroupsDTD=dtdName; 28 } 29 30 public InputSource resolveEntity(String publicId, String systemId) throws SAXException , IOException { 31 InputSource source=new InputSource (getInputStream(systemId)); 32 return source; 33 } 34 35 protected InputStream getInputStream(String dtdurl) 36 throws java.io.IOException { 37 String url=dtdurl; 38 if(url == null) url=mDefaultJGroupsDTD; 39 try { 41 URL inurl=new URL (url); 42 return inurl.openStream(); 43 } 44 catch(Exception ignore) { 45 } 46 48 InputStream stream=Thread.currentThread().getContextClassLoader().getResourceAsStream(url); 49 if(stream == null) { 50 throw new IOException ("Could not locate the DTD with name:[" + url + "] in the classpath."); 51 } 52 else 53 return stream; 54 } 55 } 56 | Popular Tags |