| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.ken.util; |
| 17 | |
|
| 18 | |
import java.io.InputStream; |
| 19 | |
|
| 20 | |
import javax.xml.XMLConstants; |
| 21 | |
import javax.xml.parsers.DocumentBuilder; |
| 22 | |
import javax.xml.parsers.DocumentBuilderFactory; |
| 23 | |
|
| 24 | |
import org.w3c.dom.DOMImplementation; |
| 25 | |
import org.w3c.dom.ls.DOMImplementationLS; |
| 26 | |
import org.w3c.dom.ls.LSInput; |
| 27 | |
import org.w3c.dom.ls.LSResourceResolver; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public class ClassLoaderLSResourceResolver extends ClassLoaderResourceResolver implements LSResourceResolver { |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public ClassLoaderLSResourceResolver(String base, String prefix) { |
| 41 | 0 | super(base, prefix); |
| 42 | 0 | } |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { |
| 48 | 0 | if (!type.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) { |
| 49 | 0 | return null; |
| 50 | |
} |
| 51 | 0 | LOG.error(type); |
| 52 | 0 | LOG.error(namespaceURI); |
| 53 | 0 | LOG.error(publicId); |
| 54 | 0 | LOG.error(systemId); |
| 55 | 0 | LOG.error(baseURI); |
| 56 | 0 | String path = resolveSystemId(systemId); |
| 57 | 0 | if (path == null) { |
| 58 | 0 | return null; |
| 59 | |
} |
| 60 | 0 | LOG.debug("Looking up resource '" + path + "' for system id '" + systemId + "'"); |
| 61 | 0 | InputStream is = getClass().getClassLoader().getResourceAsStream(path); |
| 62 | 0 | if (is == null) { |
| 63 | 0 | String message = "Unable to find schema (" + path + ") for: " + systemId; |
| 64 | 0 | LOG.error(message); |
| 65 | 0 | throw new RuntimeException(message); |
| 66 | |
} |
| 67 | |
try { |
| 68 | 0 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| 69 | 0 | DocumentBuilder builder = factory.newDocumentBuilder(); |
| 70 | 0 | DOMImplementation domImpl = builder.getDOMImplementation(); |
| 71 | 0 | DOMImplementationLS dils = (DOMImplementationLS) domImpl; |
| 72 | 0 | LSInput input = dils.createLSInput(); |
| 73 | 0 | input.setByteStream(is); |
| 74 | 0 | return input; |
| 75 | 0 | } catch (Exception e) { |
| 76 | 0 | throw new RuntimeException(e); |
| 77 | |
} |
| 78 | |
} |
| 79 | |
} |