Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SchemaLSResourceResolver |
|
| 3.0;3 |
1 | /* | |
2 | * Copyright 2007-2010 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | package org.kuali.rice.core.xml.schema; | |
17 | ||
18 | import java.io.InputStream; | |
19 | ||
20 | import javax.xml.parsers.DocumentBuilder; | |
21 | import javax.xml.parsers.DocumentBuilderFactory; | |
22 | ||
23 | import org.kuali.rice.core.util.RiceUtilities; | |
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 | * This is an entity resolver for loading schemas. | |
31 | * It finds resources in the impl/src/main/resources/schema directory. | |
32 | * | |
33 | * TODO: Handle schemas that are formally published | |
34 | * | |
35 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
36 | * | |
37 | */ | |
38 | 0 | public class SchemaLSResourceResolver implements LSResourceResolver { |
39 | ||
40 | private static final String SCHEMA_DIR = "classpath:schema/"; | |
41 | /** | |
42 | * This overridden method currently looks for resources in the "classpath:schema/" directory. | |
43 | * | |
44 | * @see org.w3c.dom.ls.LSResourceResolver#resolveResource(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) | |
45 | */ | |
46 | public LSInput resolveResource(String type, String namespaceURI, String publicId, | |
47 | String systemId, String baseURI) { | |
48 | ||
49 | 0 | LSInput input = null; |
50 | try{ | |
51 | 0 | InputStream xsdFile = RiceUtilities.getResourceAsStream(SCHEMA_DIR + systemId); |
52 | 0 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); |
53 | 0 | DocumentBuilder builder = factory.newDocumentBuilder(); |
54 | 0 | DOMImplementation domImpl = builder.getDOMImplementation(); |
55 | 0 | DOMImplementationLS dils = (DOMImplementationLS) domImpl; |
56 | 0 | input = dils.createLSInput(); |
57 | 0 | input.setByteStream(xsdFile); |
58 | 0 | } catch (Exception e) { |
59 | 0 | throw new RuntimeException(e); |
60 | 0 | } |
61 | 0 | return input; |
62 | } | |
63 | ||
64 | } |