X4O: Fixed recursief debugging xml output

This commit is contained in:
Willem Cazander 2025-11-07 20:13:30 +01:00
parent 889e4b9eb8
commit 2819b36a45
37 changed files with 592 additions and 570 deletions

View file

@ -57,6 +57,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
private final SAX3PropertyConfig propertyConfig;
private final Writer out;
private boolean started = false;
private int indent = 0;
private Map<String,String> prefixMapping = null;
private List<String> printedMappings = null;
@ -130,6 +131,10 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
* @see org.xml.sax.ContentHandler#startDocument()
*/
public void startDocument() throws SAXException {
if (started) {
throw new SAXException("Can start document only once.");
}
started = true;
indent = 0;
write(SAX3XMLConstants.getDocumentDeclaration(getPropertyConfig().getPropertyString(OUTPUT_ENCODING)));
prologWriteLicence();
@ -479,7 +484,7 @@ public class AbstractContentWriterHandler implements ContentHandler, Closeable {
public void endPrefixMapping(String prefix) throws SAXException {
Set<Map.Entry<String,String>> s = prefixMapping.entrySet();
String uri = null;
for (Map.Entry<String,String> e:s) {
for (Map.Entry<String,String> e : s) {
if (e.getValue() == null) {
continue; // way ?
}

View file

@ -23,6 +23,7 @@
package org.x4o.sax3.io;
import java.io.Closeable;
import java.io.IOException;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
@ -38,6 +39,23 @@ import org.xml.sax.ext.LexicalHandler;
*/
public interface ContentWriter extends ContentHandler, LexicalHandler, Closeable {
/**
* Wrap startDocument and endDocument in a body closable code block.
*
* @return An closable resource block reference.
* @throws SAXException When IOException is thrown.
*/
default ContentCloseable startDocumentClosure() throws SAXException {
startDocument();
return () -> {
try {
endDocument();
} catch (SAXException e) {
throw new IOException(e);
}
};
}
/**
* Starts and ends an element in one call.
* @param uri The uri of the element.