1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.qedeq.kernel.xml.dao; |
19 |
|
|
20 |
|
import java.io.File; |
21 |
|
import java.io.FileOutputStream; |
22 |
|
import java.io.IOException; |
23 |
|
import java.io.OutputStream; |
24 |
|
import java.net.URL; |
25 |
|
|
26 |
|
import org.qedeq.base.io.IoUtility; |
27 |
|
import org.qedeq.base.io.TextOutput; |
28 |
|
import org.qedeq.base.trace.Trace; |
29 |
|
import org.qedeq.kernel.bo.context.KernelContext; |
30 |
|
import org.qedeq.kernel.bo.module.KernelQedeqBo; |
31 |
|
import org.qedeq.kernel.common.DefaultSourceFileExceptionList; |
32 |
|
import org.qedeq.kernel.common.ModuleAddress; |
33 |
|
import org.qedeq.kernel.common.SourceFileExceptionList; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@author |
41 |
|
|
|
|
| 62,2% |
Uncovered Elements: 17 (45) |
Complexity: 10 |
Complexity Density: 0,29 |
|
42 |
|
public final class Xml2Xml { |
43 |
|
|
44 |
|
|
45 |
|
private static final Class CLASS = Xml2Xml.class; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
50 |
0
|
private Xml2Xml() {... |
51 |
|
|
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@param |
58 |
|
@param |
59 |
|
@throws |
60 |
|
@return |
61 |
|
|
|
|
| 43,8% |
Uncovered Elements: 9 (16) |
Complexity: 4 |
Complexity Density: 0,33 |
|
62 |
3
|
public static String generate(final File from, final File to)... |
63 |
|
throws SourceFileExceptionList { |
64 |
3
|
final String method = "generate(File, File)"; |
65 |
3
|
File destination; |
66 |
3
|
try { |
67 |
3
|
if (to != null) { |
68 |
3
|
destination = to.getCanonicalFile(); |
69 |
|
} else { |
70 |
0
|
String xml = from.getName(); |
71 |
0
|
if (xml.toLowerCase().endsWith(".xml")) { |
72 |
0
|
xml = xml.substring(0, xml.length() - 4); |
73 |
|
} |
74 |
0
|
destination = new File(from.getParentFile(), xml + "_.xml").getCanonicalFile(); |
75 |
|
} |
76 |
|
} catch (IOException e) { |
77 |
0
|
Trace.trace(CLASS, method, e); |
78 |
0
|
throw new DefaultSourceFileExceptionList(e); |
79 |
|
} |
80 |
3
|
return generate(IoUtility.toUrl(from), destination); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
@param |
87 |
|
@param |
88 |
|
@throws |
89 |
|
@return |
90 |
|
|
|
|
| 73,1% |
Uncovered Elements: 7 (26) |
Complexity: 5 |
Complexity Density: 0,23 |
|
91 |
3
|
public static String generate(final URL from, final File to)... |
92 |
|
throws SourceFileExceptionList { |
93 |
3
|
final String method = "generate(URL, File)"; |
94 |
3
|
Trace.begin(CLASS, method); |
95 |
3
|
Trace.param(CLASS, method, "from", from); |
96 |
3
|
Trace.param(CLASS, method, "to", to); |
97 |
3
|
TextOutput printer = null; |
98 |
3
|
try { |
99 |
3
|
final ModuleAddress address = KernelContext.getInstance().getModuleAddress(from); |
100 |
|
|
101 |
3
|
final KernelQedeqBo prop = (KernelQedeqBo) KernelContext.getInstance() |
102 |
|
.loadModule(address); |
103 |
3
|
if (prop.getLoadingState().isFailure()) { |
104 |
0
|
throw prop.getException(); |
105 |
|
} |
106 |
3
|
IoUtility.createNecessaryDirectories(to); |
107 |
3
|
final OutputStream outputStream = new FileOutputStream(to); |
108 |
3
|
printer = new TextOutput(to.getName(), outputStream); |
109 |
3
|
Qedeq2Xml.print(prop, printer); |
110 |
3
|
return to.getCanonicalPath(); |
111 |
|
} catch (IOException e) { |
112 |
0
|
Trace.trace(CLASS, method, e); |
113 |
0
|
throw new DefaultSourceFileExceptionList(e); |
114 |
|
} catch (RuntimeException e) { |
115 |
0
|
Trace.trace(CLASS, method, e); |
116 |
0
|
throw new DefaultSourceFileExceptionList(e); |
117 |
|
} finally { |
118 |
3
|
if (printer != null) { |
119 |
3
|
printer.close(); |
120 |
|
} |
121 |
3
|
Trace.end(CLASS, method); |
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
|
} |