Wed, 10 Jul 2024 21:57:53 +0200
hotfix for multiple subsequent line continuations
issue #392
25
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2014 Mike Becker. All rights reserved. |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | * |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | */ |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | package de.uapcore.sigred.doc.base; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | import de.uapcore.sigred.doc.Resources; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | import de.uapcore.sigrapi.impl.Digraph; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | import de.uapcore.sigrapi.impl.Graph; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | import de.uapcore.sigrapi.IGraph; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | import java.io.IOException; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | import java.io.InputStream; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | import java.io.OutputStream; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
39 | import java.util.concurrent.atomic.AtomicBoolean; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
40 | import java.util.concurrent.atomic.AtomicReference; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
41 | import org.apache.xerces.impl.Constants; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | import org.dom4j.Document; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | import org.dom4j.DocumentException; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | import org.dom4j.DocumentHelper; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | import org.dom4j.Element; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | import org.dom4j.Namespace; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | import org.dom4j.QName; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | import org.dom4j.io.OutputFormat; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | import org.dom4j.io.SAXReader; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | import org.dom4j.io.XMLWriter; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | import org.xml.sax.ErrorHandler; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | import org.xml.sax.SAXException; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | import org.xml.sax.SAXParseException; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | public abstract class AbstractGraphDocument<T extends IGraph> |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | extends FileBackedDocument { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | protected static final Namespace NAMESPACE = Namespace.get("sigred", |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | "http://develop.uap-core.de/sigred/"); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
61 | private static final |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | QName TAG_GRAPHDOC = QName.get("graph-document", NAMESPACE); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | private static final |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | QName TAG_GRAPH = QName.get("graph", NAMESPACE); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
65 | private static final |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | QName TAG_DIGRAPH = QName.get("digraph", NAMESPACE); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | private static final |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | QName TAG_METADATA = QName.get("metadata", NAMESPACE); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | protected final T graph; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | private final GraphDocumentMetadata metadata; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
74 | public AbstractGraphDocument(Class<T> graphType) { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
75 | T g; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | try { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | g = graphType.newInstance(); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | } catch (ReflectiveOperationException e) { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | assert false; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | g = null; // for the compiler |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | graph = g; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | metadata = new GraphDocumentMetadata(); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | public T getGraph() { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | return graph; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | public GraphDocumentMetadata getMetadata() { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | return metadata; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
93 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
94 | protected abstract void writeGraph(Element rootNode) throws IOException; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
95 | protected abstract void readGraph(Element rootNode) throws IOException; |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
96 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | @Override |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | public void writeTo(OutputStream out) throws IOException { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | Document doc = DocumentHelper.createDocument(); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | Element rootNode = doc.addElement(TAG_GRAPHDOC); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | Element metadataNode = rootNode.addElement(TAG_METADATA); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
105 | metadata.write(metadataNode); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | if (graph instanceof Graph) { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | writeGraph(rootNode.addElement(TAG_GRAPH)); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | } else if (graph instanceof Digraph) { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | writeGraph(rootNode.addElement(TAG_DIGRAPH)); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | } else { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | throw new IOException("unsupported graph type"); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
113 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint()); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | writer.write(doc); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | writer.flush(); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
118 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
119 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | @Override |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | public void readFrom(InputStream in) throws IOException { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | try { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
123 | SAXReader reader = new SAXReader(true); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | reader.setStripWhitespaceText(true); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
125 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
126 | reader.setFeature(Constants.XERCES_FEATURE_PREFIX+ |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | Constants.SCHEMA_VALIDATION_FEATURE, true); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | reader.setProperty(Constants.XERCES_PROPERTY_PREFIX + |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
129 | Constants.SCHEMA_LOCATION, String.format("%s %s", |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
130 | NAMESPACE.getURI(), Resources.class.getResource( |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | "graph-document.xsd").toExternalForm())); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
132 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
133 | final AtomicBoolean passed = new AtomicBoolean(true); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | final AtomicReference<SAXParseException> xmlerror = new AtomicReference<>(); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | // TODO: we should do more detailed error handling here |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | reader.setErrorHandler(new ErrorHandler() { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
137 | @Override |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
138 | public void warning(SAXParseException exception) throws SAXException { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
139 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | @Override |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | public void error(SAXParseException exception) throws SAXException { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
143 | xmlerror.set(exception); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | passed.set(false); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
147 | @Override |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
148 | public void fatalError(SAXParseException exception) throws SAXException { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | xmlerror.set(exception); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | passed.set(false); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | }); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | Document doc = reader.read(in); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
155 | if (!passed.get()) { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | // TODO: provide details (maybe via separate error object?) |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | throw xmlerror.get(); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
160 | doc.normalize(); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
161 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
162 | Element root = doc.getRootElement(); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
163 | metadata.read(root.element(TAG_METADATA)); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
164 | |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | if (graph instanceof Graph) { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
166 | readGraph(root.element(TAG_GRAPH)); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | } else if (graph instanceof Digraph) { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
168 | readGraph(root.element(TAG_DIGRAPH)); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | } else { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
170 | throw new IOException("unsupported graph type"); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
171 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
172 | } catch (DocumentException | SAXException ex) { |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
173 | throw new IOException(ex); |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
174 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
175 | } |
f82aa7afe872
more and better test cases + fixed memory leak introduced by changeset e43dee5892f4
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
176 | } |