|
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.File; |
|
21 |
| import java.io.IOException; |
|
22 |
| |
|
23 |
| import javax.xml.parsers.ParserConfigurationException; |
|
24 |
| |
|
25 |
| import org.qedeq.kernel.base.module.Qedeq; |
|
26 |
| import org.qedeq.kernel.bo.load.DefaultModuleAddress; |
|
27 |
| import org.qedeq.kernel.bo.module.ModuleContext; |
|
28 |
| import org.qedeq.kernel.bo.module.ModuleDataException; |
|
29 |
| import org.qedeq.kernel.common.SourceArea; |
|
30 |
| import org.qedeq.kernel.common.SourceFileException; |
|
31 |
| import org.qedeq.kernel.common.SourceFileExceptionList; |
|
32 |
| import org.qedeq.kernel.context.KernelContext; |
|
33 |
| import org.qedeq.kernel.trace.Trace; |
|
34 |
| import org.qedeq.kernel.xml.parser.DefaultSourceFileExceptionList; |
|
35 |
| import org.qedeq.kernel.xml.tracker.SimpleXPath; |
|
36 |
| import org.qedeq.kernel.xml.tracker.XPathLocationFinder; |
|
37 |
| import org.xml.sax.SAXException; |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| public final class ModuleDataException2XmlFileException { |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
0
| private ModuleDataException2XmlFileException() {
|
|
53 |
| |
|
54 |
| } |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
2370
| public static final SourceFileExceptionList createXmlFileExceptionList(final ModuleDataException
|
|
64 |
| exception, final Qedeq qedeq) { |
|
65 |
2370
| final DefaultSourceFileExceptionList list = new DefaultSourceFileExceptionList();
|
|
66 |
2370
| final SourceFileException e = new SourceFileException(exception, createSourceArea(qedeq,
|
|
67 |
| exception.getContext()), |
|
68 |
| createSourceArea(qedeq, exception.getReferenceContext())); |
|
69 |
2360
| list.add(e);
|
|
70 |
2360
| return list;
|
|
71 |
| } |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
4730
| public static SourceArea createSourceArea(final Qedeq qedeq, final ModuleContext context) {
|
|
81 |
4730
| final String method = "createSourceArea(Qedeq, ModuleContext)";
|
|
82 |
4730
| if (qedeq == null || context == null) {
|
|
83 |
2355
| return null;
|
|
84 |
| } |
|
85 |
2375
| final String xpath;
|
|
86 |
2375
| try {
|
|
87 |
2375
| xpath = Context2SimpleXPath.getXPath(context, qedeq).toString();
|
|
88 |
| } catch (ModuleDataException e) { |
|
89 |
0
| Trace.trace(SourceFileException.class, method, e);
|
|
90 |
0
| return null;
|
|
91 |
| }; |
|
92 |
| |
|
93 |
2369
| SimpleXPath find = null;
|
|
94 |
2369
| try {
|
|
95 |
2369
| find = XPathLocationFinder.getXPathLocation(
|
|
96 |
| new File(KernelContext.getInstance().getLocalFilePath( |
|
97 |
| |
|
98 |
| |
|
99 |
| new DefaultModuleAddress(context.getModuleLocation()))), |
|
100 |
| xpath, |
|
101 |
| context.getModuleLocation()); |
|
102 |
2365
| if (find.getStartLocation() == null) {
|
|
103 |
0
| return null;
|
|
104 |
| } |
|
105 |
2365
| return new SourceArea(context.getModuleLocation(), find.getStartLocation(),
|
|
106 |
| find.getEndLocation()); |
|
107 |
| } catch (ParserConfigurationException e) { |
|
108 |
0
| Trace.trace(SourceFileException.class, method, e);
|
|
109 |
| } catch (SAXException e) { |
|
110 |
0
| Trace.trace(SourceFileException.class, method, e);
|
|
111 |
| } catch (IOException e) { |
|
112 |
0
| Trace.trace(SourceFileException.class, method, e);
|
|
113 |
| } |
|
114 |
0
| return null;
|
|
115 |
| } |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| } |