1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.comparator.model;
18
19 import java.io.StringWriter;
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.Set;
23 import jakarta.xml.bind.SchemaOutputResolver;
24 import javax.xml.transform.Result;
25 import javax.xml.transform.stream.StreamResult;
26
27
28
29
30
31
32 @SuppressWarnings({"WeakerAccess", "unused"})
33 public class BufferSchemaOutputResolver extends SchemaOutputResolver {
34
35
36
37
38 protected Map<String, StreamResult> buffers = new HashMap<>();
39
40 @Override
41 public Result createOutput(String namespaceUri, String suggestedFileName) {
42 StringWriter out = new StringWriter();
43 StreamResult res = new StreamResult(out);
44 res.setSystemId(suggestedFileName);
45 buffers.put(namespaceUri, res);
46 return res;
47 }
48
49
50
51
52
53
54 public Set<String> getNamespaces() {
55 return buffers.keySet();
56 }
57
58
59
60
61
62
63
64 public String getSchema(String namespaceUri) {
65 return buffers.get(namespaceUri).getWriter().toString();
66 }
67
68
69
70
71
72
73
74 public String getSystemId(String namespaceUri) {
75 return buffers.get(namespaceUri).getSystemId();
76 }
77
78 @Override
79 public String toString() {
80 StringBuilder sb = new StringBuilder();
81 for (String s : buffers.keySet()) {
82 sb.append("***** Begin schema ").append(s).append(", system-id=").append(getSystemId(s))
83 .append(" *****");
84 sb.append(System.getProperty("line.separator"));
85 sb.append(getSchema(s));
86 sb.append("***** End schema ").append(s).append(" *****");
87 sb.append(System.getProperty("line.separator"));
88 sb.append(System.getProperty("line.separator"));
89 }
90 return sb.toString();
91 }
92
93
94
95
96 public void clear() {
97 buffers.clear();
98 }
99
100 }