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