|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.xml.parser; |
|
19 |
| |
|
20 |
| import java.io.FileNotFoundException; |
|
21 |
| import java.io.InputStream; |
|
22 |
| |
|
23 |
| import org.qedeq.kernel.context.KernelContext; |
|
24 |
| import org.qedeq.kernel.trace.Trace; |
|
25 |
| import org.xml.sax.EntityResolver; |
|
26 |
| import org.xml.sax.InputSource; |
|
27 |
| import org.xml.sax.SAXException; |
|
28 |
| import org.xml.sax.SAXParseException; |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| public class SaxEntityResolver implements EntityResolver { |
|
38 |
| |
|
39 |
| |
|
40 |
| private final SaxDefaultHandler handler; |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
132
| public SaxEntityResolver(final SaxDefaultHandler handler) {
|
|
48 |
132
| this.handler = handler;
|
|
49 |
| } |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
254
| public InputSource resolveEntity(final String publicId, final String systemId)
|
|
55 |
| throws FileNotFoundException, SAXException { |
|
56 |
254
| final String method = "resolveEntity";
|
|
57 |
254
| Trace.param(this, method, "systemId", systemId);
|
|
58 |
254
| Trace.param(this, method, "publicId", publicId);
|
|
59 |
254
| if ((systemId == null)) {
|
|
60 |
0
| return null;
|
|
61 |
| } |
|
62 |
254
| if (systemId.equals("http://www.qedeq.org/" + KernelContext.getInstance()
|
|
63 |
| .getKernelVersionDirectory() + "/xml/qedeq.xsd")) { |
|
64 |
91
| InputStream in = SaxEntityResolver.class.getResourceAsStream(
|
|
65 |
| "/org/qedeq/kernel/xml/schema/qedeq.xsd"); |
|
66 |
91
| if (in == null) {
|
|
67 |
0
| throw new FileNotFoundException("/org/qedeq/kernel/xml/schema/qedeq.xsd");
|
|
68 |
| } |
|
69 |
91
| InputSource inputSource = new InputSource(in);
|
|
70 |
91
| inputSource.setPublicId(publicId);
|
|
71 |
91
| inputSource.setSystemId(systemId);
|
|
72 |
91
| return inputSource;
|
|
73 |
163
| } else if (systemId.equals("http://www.qedeq.org/"
|
|
74 |
| + KernelContext.getInstance().getKernelVersionDirectory() |
|
75 |
| + "/xml/parser.xsd")) { |
|
76 |
162
| InputStream in = SaxEntityResolver.class.getResourceAsStream(
|
|
77 |
| "/org/qedeq/kernel/xml/schema/parser.xsd"); |
|
78 |
162
| if (in == null) {
|
|
79 |
0
| throw new FileNotFoundException("/org/qedeq/kernel/xml/schema/parser.xsd");
|
|
80 |
| } |
|
81 |
162
| InputSource inputSource = new InputSource(in);
|
|
82 |
162
| inputSource.setPublicId(publicId);
|
|
83 |
162
| inputSource.setSystemId(systemId);
|
|
84 |
162
| return inputSource;
|
|
85 |
| } |
|
86 |
1
| Trace.trace(this, method, "unknown entity");
|
|
87 |
1
| SAXParseException sax = handler.createSAXParseException(
|
|
88 |
| "this kernel supports only the following XSDs:\n" |
|
89 |
| + "http://www.qedeq.org/" + KernelContext.getInstance() |
|
90 |
| .getKernelVersionDirectory() + "/xml/qedeq.xsd" + "\n" |
|
91 |
| + "http://www.qedeq.org/" |
|
92 |
| + KernelContext.getInstance().getKernelVersionDirectory() |
|
93 |
| + "/xml/parser.xsd"); |
|
94 |
1
| throw sax;
|
|
95 |
| |
|
96 |
| |
|
97 |
| } |
|
98 |
| } |