1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.xml.dao; |
17 |
|
|
18 |
|
import java.io.File; |
19 |
|
import java.io.FileOutputStream; |
20 |
|
import java.io.IOException; |
21 |
|
import java.io.OutputStream; |
22 |
|
import java.io.Reader; |
23 |
|
import java.util.Locale; |
24 |
|
|
25 |
|
import javax.xml.parsers.ParserConfigurationException; |
26 |
|
|
27 |
|
import org.qedeq.base.io.SourceArea; |
28 |
|
import org.qedeq.base.io.TextOutput; |
29 |
|
import org.qedeq.base.trace.Trace; |
30 |
|
import org.qedeq.kernel.bo.common.QedeqBo; |
31 |
|
import org.qedeq.kernel.bo.module.InternalKernelServices; |
32 |
|
import org.qedeq.kernel.bo.module.InternalServiceJob; |
33 |
|
import org.qedeq.kernel.bo.module.KernelQedeqBo; |
34 |
|
import org.qedeq.kernel.bo.module.QedeqFileDao; |
35 |
|
import org.qedeq.kernel.se.base.module.Qedeq; |
36 |
|
import org.qedeq.kernel.se.common.ModuleContext; |
37 |
|
import org.qedeq.kernel.se.common.ModuleDataException; |
38 |
|
import org.qedeq.kernel.se.common.ModuleService; |
39 |
|
import org.qedeq.kernel.se.common.SourceFileExceptionList; |
40 |
|
import org.qedeq.kernel.xml.handler.common.SaxDefaultHandler; |
41 |
|
import org.qedeq.kernel.xml.handler.module.QedeqHandler; |
42 |
|
import org.qedeq.kernel.xml.mapper.Context2SimpleXPath; |
43 |
|
import org.qedeq.kernel.xml.parser.SaxParser; |
44 |
|
import org.qedeq.kernel.xml.tracker.SimpleXPath; |
45 |
|
import org.qedeq.kernel.xml.tracker.XPathLocationParser; |
46 |
|
import org.xml.sax.SAXException; |
47 |
|
|
48 |
|
import com.sun.syndication.io.XmlReader; |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@author |
55 |
|
|
|
|
| 54.4% |
Uncovered Elements: 26 (57) |
Complexity: 17 |
Complexity Density: 0.41 |
|
56 |
|
public class XmlQedeqFileDao implements QedeqFileDao, ModuleService { |
57 |
|
|
58 |
|
|
59 |
|
private static final Class CLASS = XmlQedeqFileDao.class; |
60 |
|
|
61 |
|
|
62 |
|
private InternalKernelServices services; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
67 |
12
|
public XmlQedeqFileDao() {... |
68 |
|
|
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
12
|
public void setServices(final InternalKernelServices services) {... |
72 |
12
|
this.services = services; |
73 |
|
} |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0
|
public InternalKernelServices getServices() {... |
76 |
0
|
return this.services; |
77 |
|
} |
78 |
|
|
|
|
| 76.5% |
Uncovered Elements: 4 (17) |
Complexity: 4 |
Complexity Density: 0.24 |
|
79 |
145
|
public Qedeq loadQedeq(final InternalServiceJob process, final QedeqBo prop,... |
80 |
|
final File file) throws SourceFileExceptionList { |
81 |
145
|
final String method = "loadModule"; |
82 |
|
|
83 |
145
|
SaxDefaultHandler handler = new SaxDefaultHandler(this); |
84 |
145
|
QedeqHandler simple = new QedeqHandler(handler); |
85 |
145
|
handler.setBasisDocumentHandler(simple); |
86 |
145
|
SaxParser parser = null; |
87 |
145
|
Locale.setDefault(Locale.US); |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
145
|
try { |
139 |
145
|
parser = new SaxParser(this, handler); |
140 |
|
} catch (SAXException e) { |
141 |
0
|
Trace.fatal(CLASS, this, method, "XML Parser: Severe configuration problem.", e); |
142 |
0
|
throw services.createSourceFileExceptionList( |
143 |
|
DaoErrors.PARSER_CONFIGURATION_ERROR_CODE, |
144 |
|
DaoErrors.PARSER_CONFIGURATION_ERROR_TEXT, |
145 |
|
file + "", e); |
146 |
|
} catch (ParserConfigurationException e) { |
147 |
0
|
Trace.fatal(CLASS, this, method, "XML Parser: Option not recognized or supported.", e); |
148 |
0
|
throw services.createSourceFileExceptionList( |
149 |
|
DaoErrors.PARSER_CONFIGURATION_OPTION_ERROR_CODE, |
150 |
|
DaoErrors.PARSER_CONFIGURATION_OPTION_ERROR_TEXT, |
151 |
|
file + "", e); |
152 |
|
} |
153 |
145
|
try { |
154 |
145
|
parser.parse(file, prop.getUrl()); |
155 |
|
} catch (SourceFileExceptionList e) { |
156 |
10
|
Trace.trace(CLASS, this, method, e); |
157 |
10
|
throw e; |
158 |
|
} |
159 |
135
|
return simple.getQedeq(); |
160 |
|
} |
161 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
162 |
0
|
public void saveQedeq(final InternalServiceJob process, final KernelQedeqBo prop,... |
163 |
|
final File localFile) throws SourceFileExceptionList, IOException { |
164 |
0
|
final OutputStream outputStream = new FileOutputStream(localFile); |
165 |
0
|
final TextOutput printer = new TextOutput(localFile.getName(), outputStream, "UTF-8"); |
166 |
0
|
Qedeq2Xml.print(process, this, prop, printer); |
167 |
|
} |
168 |
|
|
|
|
| 52.4% |
Uncovered Elements: 10 (21) |
Complexity: 5 |
Complexity Density: 0.33 |
|
169 |
6
|
public SourceArea createSourceArea(final Qedeq qedeq, final ModuleContext context) {... |
170 |
|
|
171 |
6
|
final String method = "createSourceArea(Qedeq, ModuleContext)"; |
172 |
6
|
if (context == null) { |
173 |
0
|
return null; |
174 |
|
} |
175 |
6
|
if (qedeq == null) { |
176 |
0
|
return new SourceArea(context.getModuleLocation().getUrl()); |
177 |
|
} |
178 |
6
|
ModuleContext ctext = new ModuleContext(context); |
179 |
6
|
final SimpleXPath xpath; |
180 |
6
|
try { |
181 |
6
|
xpath = Context2SimpleXPath.getXPath(ctext, qedeq); |
182 |
|
} catch (ModuleDataException e) { |
183 |
0
|
Trace.fatal(CLASS, method, "not found: \"" + ctext + "\"", e); |
184 |
0
|
if (Boolean.TRUE.toString().equalsIgnoreCase( |
185 |
|
System.getProperty("qedeq.test.xmlLocationFailures"))) { |
186 |
0
|
throw new RuntimeException(e); |
187 |
|
} |
188 |
0
|
return new SourceArea(ctext.getModuleLocation().getUrl()); |
189 |
|
} |
190 |
|
|
191 |
6
|
final File local = services.getLocalFilePath(ctext.getModuleLocation()); |
192 |
6
|
return XPathLocationParser.findSourceArea(ctext.getModuleLocation().getUrl(), xpath, |
193 |
|
ctext.getStartDelta(), ctext.getEndDelta(), local); |
194 |
|
} |
195 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
196 |
2
|
public Reader getModuleReader(final KernelQedeqBo bo)... |
197 |
|
throws IOException { |
198 |
2
|
return new XmlReader(services.getLocalFilePath(bo.getModuleAddress())); |
199 |
|
} |
200 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
201 |
0
|
public String getServiceId() {... |
202 |
0
|
return CLASS.getName(); |
203 |
|
} |
204 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
0
|
public String getServiceAction() {... |
206 |
0
|
return "XML Worker"; |
207 |
|
} |
208 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
209 |
0
|
public String getServiceDescription() {... |
210 |
0
|
return "can read and write XML QEDEQ modules"; |
211 |
|
} |
212 |
|
|
213 |
|
} |