Commit 50f22d0e authored by Jos van den Oever's avatar Jos van den Oever

Make sure the document has started before writing comments.

parent dc25eb62
......@@ -2,6 +2,7 @@ package odf;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Stack;
import java.util.TreeMap;
......@@ -15,6 +16,8 @@ import org.eclipse.jdt.annotation.Nullable;
class PrettyPrinter implements XMLStreamWriter {
final private XMLStreamWriter out;
final private HashSet<QName> elementsWithNoText;
final private LinkedList<String> initialComments = new LinkedList<String>();
private boolean started = false;
PrettyPrinter(XMLStreamWriter out, HashSet<QName> elementsWithNoText) {
this.out = out;
......@@ -107,6 +110,10 @@ class PrettyPrinter implements XMLStreamWriter {
@Override
public void writeComment(@Nullable String data) throws XMLStreamException {
if (!started) {
initialComments.add(data);
return;
}
startElement();
if (stack.size() == 0 || stack.peek()) {
indent();
......@@ -184,21 +191,31 @@ class PrettyPrinter implements XMLStreamWriter {
out.writeProcessingInstruction(target, data);
}
private void writeInitialComments() throws XMLStreamException {
started = true;
for (String comment : initialComments) {
writeComment(comment);
}
}
@Override
public void writeStartDocument() throws XMLStreamException {
out.writeStartDocument();
writeInitialComments();
}
@Override
public void writeStartDocument(@Nullable String version)
throws XMLStreamException {
out.writeStartDocument("UTF-8", version);
writeInitialComments();
}
@Override
public void writeStartDocument(@Nullable String encoding,
@Nullable String version) throws XMLStreamException {
out.writeStartDocument(encoding, version);
writeInitialComments();
}
static QName parseQName(@Nullable String qname, NamespaceContext nc) {
......
......@@ -20,7 +20,7 @@ public class RngNormalizer {
final Element def = defs.get(name);
def.removeAttribute("combine");
// move non-element nodes in that precede this <define/> and the
// move non-element nodes that precede this <define/> and the
// <define/> to the end of the <grammar/> element
Node before = def.getPreviousSibling();
while (before != null && before.getNodeType() != Node.ELEMENT_NODE) {
......
......@@ -71,7 +71,6 @@ public class XML {
try {
XMLReader reader = parser.getXMLReader();
DOMResult domResult = new DOMResult();
if (info != null) {
WhitespaceHandler whitespace = new WhitespaceHandler(
info.getRngInfo(this));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment