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 |
5
| public static final XmlFileExceptionList createXmlFileExceptionList(final ModuleDataException
|
54 |
| exception, final Qedeq qedeq) { |
55 |
5
| final DefaultXmlFileExceptionList list = new DefaultXmlFileExceptionList();
|
56 |
5
| final XmlFileException e = new XmlFileException(exception, createSourceArea(qedeq,
|
57 |
| exception.getContext()), |
58 |
| createSourceArea(qedeq, exception.getReferenceContext())); |
59 |
5
| list.add(e);
|
60 |
5
| return list;
|
61 |
| } |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
10
| public static SourceArea createSourceArea(final Qedeq qedeq, final ModuleContext context) {
|
71 |
10
| final String method = "createSourceArea(Qedeq, ModuleContext)";
|
72 |
10
| if (qedeq == null || context == null) {
|
73 |
3
| return null;
|
74 |
| } |
75 |
7
| final String xpath;
|
76 |
7
| try {
|
77 |
7
| 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 |
7
| SimpleXPath find = null;
|
84 |
7
| try {
|
85 |
7
| find = XPathLocationFinder.getXPathLocation(
|
86 |
| context.getModuleLocation(), xpath); |
87 |
7
| if (find.getStartLocation() == null) {
|
88 |
0
| return null;
|
89 |
| } |
90 |
7
| 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 |
| } |