1 17 18 package org.sape.carbon.core.config.format.jdom; 19 20 import java.io.InputStream ; 21 22 import org.xml.sax.InputSource ; 23 import org.xml.sax.SAXException ; 24 import org.xml.sax.helpers.DefaultHandler ; 25 26 39 public class ConfigEntityResolver extends DefaultHandler { 40 41 private static final String CLASSPATH_PREFIX = "classpath://"; 42 43 44 protected String name; 45 46 51 public ConfigEntityResolver(String name) { 52 super(); 53 this.name = name; 54 } 55 56 74 public InputSource resolveEntity(String publicId, String systemId) 75 throws SAXException { 76 77 InputSource inputSource = null; 78 79 if (systemId.startsWith(CLASSPATH_PREFIX)) { 80 String classpathLocation = 81 systemId.substring(CLASSPATH_PREFIX.length()); 82 83 InputStream inputStream = 84 getClass().getClassLoader().getResourceAsStream(classpathLocation); 85 86 if (inputStream != null) { 87 inputSource = new InputSource (inputStream); 88 } 89 } 90 91 if (inputSource != null) { 92 return inputSource; 93 } else { 94 return super.resolveEntity(publicId, systemId); 95 } 96 } 97 } 98 | Popular Tags |