| 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.Reader; |
| 19 | |
import java.io.StringReader; |
| 20 | |
|
| 21 | |
import javax.xml.XMLConstants; |
| 22 | |
import javax.xml.parsers.DocumentBuilder; |
| 23 | |
import javax.xml.parsers.DocumentBuilderFactory; |
| 24 | |
|
| 25 | |
import org.kuali.rice.ken.bo.NotificationContentType; |
| 26 | |
import org.kuali.rice.ken.service.NotificationContentTypeService; |
| 27 | |
import org.w3c.dom.DOMImplementation; |
| 28 | |
import org.w3c.dom.ls.DOMImplementationLS; |
| 29 | |
import org.w3c.dom.ls.LSInput; |
| 30 | |
import org.w3c.dom.ls.LSResourceResolver; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public class ContentTypeLSResourceResolver extends ContentTypeResourceResolver implements LSResourceResolver { |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
public ContentTypeLSResourceResolver(NotificationContentTypeService notificationContentTypeService) { |
| 43 | 0 | super(notificationContentTypeService); |
| 44 | 0 | } |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { |
| 50 | 0 | if (!type.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) { |
| 51 | 0 | return null; |
| 52 | |
} |
| 53 | |
|
| 54 | 0 | if (!systemId.startsWith(CONTENT_TYPE_PREFIX)) { |
| 55 | 0 | LOG.warn("Cannot resolve non-ContentType resources"); |
| 56 | 0 | return null; |
| 57 | |
} |
| 58 | |
|
| 59 | 0 | NotificationContentType notificationContentType = resolveContentType(systemId); |
| 60 | 0 | if (notificationContentType == null) { |
| 61 | 0 | LOG.error("Unable to resolve system id '" + systemId + "' locally...delegating to default resolution strategy."); |
| 62 | 0 | return null; |
| 63 | |
} |
| 64 | |
|
| 65 | 0 | Reader reader = new StringReader(notificationContentType.getXsd()); |
| 66 | |
try { |
| 67 | 0 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
| 68 | 0 | DocumentBuilder builder = factory.newDocumentBuilder(); |
| 69 | 0 | DOMImplementation domImpl = builder.getDOMImplementation(); |
| 70 | 0 | DOMImplementationLS dils = (DOMImplementationLS) domImpl; |
| 71 | 0 | LSInput input = dils.createLSInput(); |
| 72 | 0 | input.setCharacterStream(reader); |
| 73 | 0 | return input; |
| 74 | 0 | } catch (Exception e) { |
| 75 | 0 | throw new RuntimeException(e); |
| 76 | |
} |
| 77 | |
} |
| 78 | |
} |