|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.xml.mapper; |
|
19 |
| |
|
20 |
| import java.io.IOException; |
|
21 |
| |
|
22 |
| import javax.xml.parsers.ParserConfigurationException; |
|
23 |
| |
|
24 |
| import org.qedeq.kernel.base.module.Qedeq; |
|
25 |
| import org.qedeq.kernel.bo.module.ModuleContext; |
|
26 |
| import org.qedeq.kernel.bo.module.ModuleDataException; |
|
27 |
| import org.qedeq.kernel.common.SourceArea; |
|
28 |
| import org.qedeq.kernel.common.XmlFileException; |
|
29 |
| import org.qedeq.kernel.common.XmlFileExceptionList; |
|
30 |
| import org.qedeq.kernel.trace.Trace; |
|
31 |
| import org.qedeq.kernel.xml.parser.DefaultXmlFileExceptionList; |
|
32 |
| import org.qedeq.kernel.xml.tracker.SimpleXPath; |
|
33 |
| import org.qedeq.kernel.xml.tracker.XPathLocationFinder; |
|
34 |
| import org.xml.sax.SAXException; |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| public final class ModuleDataException2XmlFileException { |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
0
| private ModuleDataException2XmlFileException() {
|
|
50 |
| |
|
51 |
| } |
|
52 |
| |
|
53 |
14
| public static final XmlFileExceptionList createXmlFileExceptionList(final ModuleDataException
|
|
54 |
| exception, final Qedeq qedeq) { |
|
55 |
14
| final DefaultXmlFileExceptionList list = new DefaultXmlFileExceptionList();
|
|
56 |
14
| final XmlFileException e = new XmlFileException(exception, createSourceArea(qedeq,
|
|
57 |
| exception.getContext()), |
|
58 |
| createSourceArea(qedeq, exception.getReferenceContext())); |
|
59 |
14
| list.add(e);
|
|
60 |
14
| return list;
|
|
61 |
| } |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
28
| public static SourceArea createSourceArea(final Qedeq qedeq, final ModuleContext context) {
|
|
71 |
28
| final String method = "createSourceArea(Qedeq, ModuleContext)";
|
|
72 |
28
| if (qedeq == null || context == null) {
|
|
73 |
10
| return null;
|
|
74 |
| } |
|
75 |
18
| final String xpath;
|
|
76 |
18
| try {
|
|
77 |
18
| xpath = Context2SimpleXPath.getXPath(context, qedeq).toString();
|
|
78 |
| } catch (ModuleDataException e) { |
|
79 |
0
| Trace.trace(XmlFileException.class, method, e);
|
|
80 |
0
| return null;
|
|
81 |
| }; |
|
82 |
| |
|
83 |
18
| SimpleXPath find = null;
|
|
84 |
18
| try {
|
|
85 |
18
| find = XPathLocationFinder.getXPathLocation(
|
|
86 |
| context.getModuleLocation(), xpath); |
|
87 |
18
| if (find.getStartLocation() == null) {
|
|
88 |
0
| return null;
|
|
89 |
| } |
|
90 |
18
| return new SourceArea(find.getStartLocation().getAddress(),
|
|
91 |
| find.getStartLocation().getLocalAddress(), find.getStartLocation(), |
|
92 |
| find.getEndLocation()); |
|
93 |
| } catch (ParserConfigurationException e) { |
|
94 |
0
| Trace.trace(XmlFileException.class, method, e);
|
|
95 |
| } catch (SAXException e) { |
|
96 |
0
| Trace.trace(XmlFileException.class, method, e);
|
|
97 |
| } catch (IOException e) { |
|
98 |
0
| Trace.trace(XmlFileException.class, method, e);
|
|
99 |
| } |
|
100 |
0
| return null;
|
|
101 |
| } |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| } |