[#7801] Record.formatXML() should format nested records recursively
This commit is contained in:
parent
ae41800faa
commit
f0acb5693b
@ -49,7 +49,6 @@ import static org.jooq.tools.StringUtils.abbreviate;
|
||||
import static org.jooq.tools.StringUtils.leftPad;
|
||||
import static org.jooq.tools.StringUtils.rightPad;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
@ -100,7 +99,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
abstract class AbstractCursor<R extends Record> extends AbstractFormattable implements Iterable<R>, Serializable {
|
||||
abstract class AbstractCursor<R extends Record> extends AbstractFormattable implements Iterable<R> {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
@ -420,6 +419,9 @@ abstract class AbstractCursor<R extends Record> extends AbstractFormattable impl
|
||||
|
||||
@Override
|
||||
public final void formatJSON(Writer writer, JSONFormat format) {
|
||||
if (format == null)
|
||||
format = JSONFormat.DEFAULT_FOR_RESULTS;
|
||||
|
||||
try {
|
||||
String separator;
|
||||
int recordLevel = format.header() ? 2 : 1;
|
||||
@ -646,6 +648,9 @@ abstract class AbstractCursor<R extends Record> extends AbstractFormattable impl
|
||||
|
||||
@Override
|
||||
public final void formatXML(Writer writer, XMLFormat format) {
|
||||
if (format == null)
|
||||
format = XMLFormat.DEFAULT_FOR_RESULTS;
|
||||
|
||||
String newline = format.newline();
|
||||
int recordLevel = format.header() ? 2 : 1;
|
||||
|
||||
@ -742,7 +747,12 @@ abstract class AbstractCursor<R extends Record> extends AbstractFormattable impl
|
||||
}
|
||||
else {
|
||||
writer.append(">");
|
||||
writer.append(escapeXML(format0(value, false, false)));
|
||||
|
||||
if (value instanceof Formattable)
|
||||
((Formattable) value).formatXML(writer, format);
|
||||
else
|
||||
writer.append(escapeXML(format0(value, false, false)));
|
||||
|
||||
writer.append("</" + tag + ">");
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,12 +245,12 @@ abstract class AbstractFormattable implements Formattable, Serializable {
|
||||
|
||||
@Override
|
||||
public final void formatJSON(Writer writer) {
|
||||
formatJSON(writer, JSONFormat.DEFAULT_FOR_RESULTS);
|
||||
formatJSON(writer, (JSONFormat) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String formatXML() {
|
||||
return formatXML(XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
return formatXML((XMLFormat) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -262,7 +262,7 @@ abstract class AbstractFormattable implements Formattable, Serializable {
|
||||
|
||||
@Override
|
||||
public final void formatXML(OutputStream stream) {
|
||||
formatXML(stream, XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
formatXML(stream, (XMLFormat) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -272,7 +272,7 @@ abstract class AbstractFormattable implements Formattable, Serializable {
|
||||
|
||||
@Override
|
||||
public final void formatXML(Writer writer) {
|
||||
formatXML(writer, XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
formatXML(writer, (XMLFormat) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -342,11 +342,11 @@ abstract class AbstractFormattable implements Formattable, Serializable {
|
||||
|
||||
@Override
|
||||
public final Document intoXML() {
|
||||
return intoXML(XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
return intoXML((XMLFormat) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <H extends ContentHandler> H intoXML(H handler) throws SAXException {
|
||||
return intoXML(handler, XMLFormat.DEFAULT_FOR_RESULTS);
|
||||
return intoXML(handler, (XMLFormat) null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -930,6 +930,9 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
|
||||
@Override
|
||||
public final void formatJSON(Writer writer, JSONFormat format) {
|
||||
if (format == null)
|
||||
format = JSONFormat.DEFAULT_FOR_RECORDS;
|
||||
|
||||
if (format.header())
|
||||
log.debug("JSONFormat.header currently not supported for Record.formatJSON()");
|
||||
|
||||
@ -952,6 +955,9 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
|
||||
@Override
|
||||
public final void formatXML(Writer writer, XMLFormat format) {
|
||||
if (format == null)
|
||||
format = XMLFormat.DEFAULT_FOR_RECORDS;
|
||||
|
||||
if (format.header())
|
||||
log.debug("XMLFormat.header currently not supported for Record.formatXML()");
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user