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.net.URL; |
23 |
|
import java.util.Locale; |
24 |
|
|
25 |
|
import org.qedeq.base.io.IoUtility; |
26 |
|
import org.qedeq.base.io.Parameters; |
27 |
|
import org.qedeq.base.io.TextOutput; |
28 |
|
import org.qedeq.base.io.UrlUtility; |
29 |
|
import org.qedeq.base.trace.Trace; |
30 |
|
import org.qedeq.base.utility.YodaUtility; |
31 |
|
import org.qedeq.kernel.bo.common.KernelServices; |
32 |
|
import org.qedeq.kernel.bo.module.InternalKernelServices; |
33 |
|
import org.qedeq.kernel.bo.module.InternalServiceCall; |
34 |
|
import org.qedeq.kernel.bo.module.InternalServiceProcess; |
35 |
|
import org.qedeq.kernel.bo.module.KernelQedeqBo; |
36 |
|
import org.qedeq.kernel.bo.service.control.ServiceProcessManager; |
37 |
|
import org.qedeq.kernel.se.common.ModuleAddress; |
38 |
|
import org.qedeq.kernel.se.common.Plugin; |
39 |
|
import org.qedeq.kernel.se.common.SourceFileExceptionList; |
40 |
|
import org.qedeq.kernel.se.visitor.InterruptException; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@author |
47 |
|
|
|
|
| 71.9% |
Uncovered Elements: 16 (57) |
Complexity: 13 |
Complexity Density: 0.32 |
|
48 |
|
public final class Xml2Xml implements Plugin { |
49 |
|
|
50 |
|
|
51 |
|
private static final Class CLASS = Xml2Xml.class; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
56 |
143
|
private Xml2Xml() {... |
57 |
|
|
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
@param |
65 |
|
@param |
66 |
|
@param |
67 |
|
@throws |
68 |
|
@throws |
69 |
|
@return |
70 |
|
|
|
|
| 43.8% |
Uncovered Elements: 9 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
71 |
143
|
public static String generate(final KernelServices services, final InternalKernelServices internal,... |
72 |
|
final File from, final File to) throws SourceFileExceptionList, InterruptException { |
73 |
143
|
final String method = "generate(File, File)"; |
74 |
143
|
File destination = null; |
75 |
143
|
try { |
76 |
143
|
if (to != null) { |
77 |
143
|
destination = to.getCanonicalFile(); |
78 |
|
} else { |
79 |
0
|
String xml = from.getName(); |
80 |
0
|
if (xml.toLowerCase(Locale.US).endsWith(".xml")) { |
81 |
0
|
xml = xml.substring(0, xml.length() - 4); |
82 |
|
} |
83 |
0
|
destination = new File(from.getParentFile(), xml + "_.xml").getCanonicalFile(); |
84 |
|
} |
85 |
143
|
return generate(services, internal, UrlUtility.toUrl(from), destination); |
86 |
|
} catch (IOException e) { |
87 |
0
|
Trace.fatal(CLASS, "Writing failed destionation", method, e); |
88 |
0
|
throw internal.createSourceFileExceptionList( |
89 |
|
DaoErrors.WRITING_MODULE_FILE_FAILED_CODE, |
90 |
|
DaoErrors.WRITING_MODULE_FILE_FAILED_TEXT + destination, |
91 |
|
to + "", e); |
92 |
|
} |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
@param |
99 |
|
@param |
100 |
|
@param |
101 |
|
@param |
102 |
|
@throws |
103 |
|
@throws |
104 |
|
@throws |
105 |
|
@return |
106 |
|
|
|
|
| 96.9% |
Uncovered Elements: 1 (32) |
Complexity: 5 |
Complexity Density: 0.19 |
|
107 |
143
|
private static String generate(final KernelServices services, final InternalKernelServices internal,... |
108 |
|
final URL from, final File to) |
109 |
|
throws SourceFileExceptionList, IOException, InterruptException { |
110 |
143
|
final String method = "generate(URL, File)"; |
111 |
143
|
Trace.begin(CLASS, method); |
112 |
143
|
Trace.param(CLASS, method, "from", from); |
113 |
143
|
Trace.param(CLASS, method, "to", to); |
114 |
143
|
TextOutput printer = null; |
115 |
143
|
InternalServiceCall call = null; |
116 |
143
|
try { |
117 |
143
|
final ModuleAddress address = services.getModuleAddress(from); |
118 |
|
|
119 |
143
|
final InternalServiceProcess process = internal.createServiceProcess("generate XML"); |
120 |
143
|
final Plugin plugin = new Xml2Xml(); |
121 |
143
|
final KernelQedeqBo prop = internal.loadKernelModule(process, address); |
122 |
143
|
if (!prop.isLoaded()) { |
123 |
11
|
throw prop.getErrors(); |
124 |
|
} |
125 |
132
|
IoUtility.createNecessaryDirectories(to); |
126 |
132
|
final OutputStream outputStream = new FileOutputStream(to); |
127 |
132
|
printer = new TextOutput(to.getName(), outputStream, "UTF-8"); |
128 |
132
|
call = internal.createServiceCall(plugin, prop, Parameters.EMPTY, |
129 |
|
Parameters.EMPTY, process, null); |
130 |
132
|
Qedeq2Xml.print(call.getInternalServiceProcess(), plugin, prop, printer); |
131 |
132
|
return to.getCanonicalPath(); |
132 |
|
} finally { |
133 |
|
|
134 |
143
|
if (call != null) { |
135 |
132
|
try { |
136 |
132
|
((ServiceProcessManager) YodaUtility.getFieldValue(internal, "processManager")) |
137 |
|
.endServiceCall(call); |
138 |
|
} catch (NoSuchFieldException e) { |
139 |
0
|
throw new RuntimeException(e); |
140 |
|
} |
141 |
|
} |
142 |
143
|
if (printer != null) { |
143 |
132
|
printer.close(); |
144 |
|
} |
145 |
143
|
Trace.end(CLASS, method); |
146 |
|
} |
147 |
|
} |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
0
|
public String getServiceId() {... |
150 |
0
|
return CLASS.getName(); |
151 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
152 |
0
|
public String getServiceAction() {... |
153 |
0
|
return "Xml2Xml"; |
154 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
155 |
0
|
public String getServiceDescription() {... |
156 |
0
|
return "transform XML QEDEQ module in a new XML file"; |
157 |
|
} |
158 |
|
|
159 |
|
} |