1 23 package org.objectweb.clif.scenario.util.isac.util.xml; 24 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 28 import org.xml.sax.EntityResolver ; 29 import org.xml.sax.InputSource ; 30 import org.xml.sax.SAXException ; 31 32 38 public class IsacEntityResolver implements EntityResolver { 39 private final ClassLoader loader; 41 42 private static final String CLASSPATH = "classpath://"; 43 44 private static final String FILE = "file:///"; 45 46 52 public IsacEntityResolver(ClassLoader loader) { 53 super(); 54 this.loader = loader; 55 } 56 57 61 public InputSource resolveEntity(String publicId, String systemId) 62 throws SAXException , IOException { 63 if (systemId != null) { 64 if (systemId.startsWith(CLASSPATH)) { 65 ClassLoader classLoader = this.getClass().getClassLoader(); 67 InputStream dtdStream = classLoader 68 .getResourceAsStream(systemId.substring(CLASSPATH.length())); 69 if (dtdStream == null) { 70 System.out.println(systemId + " not found in classpath"); 71 return null; 72 } else { 73 InputSource source = new InputSource (dtdStream); 74 source.setPublicId(publicId); 75 source.setSystemId(systemId); 76 return source; 77 } 78 } else if (systemId.startsWith(FILE)) { 79 InputStream childStream = loader.getResourceAsStream(systemId 80 .substring(FILE.length())); 81 if (childStream == null) 82 return null; 83 else { 84 InputSource source = new InputSource (childStream); 85 source.setPublicId(publicId); 86 source.setSystemId(systemId); 87 return source; 88 } 89 } else 90 return null; 91 } else { 92 return null; 94 } 95 } 96 } | Popular Tags |