[jOOQ/jOOQ#10387] XMLGenerator should quote source code from views, check constraints, and default expressions in generated output

This commit is contained in:
Lukas Eder 2020-07-14 14:16:30 +02:00
parent 00f38ce5b1
commit aa6957e4cc

View File

@ -156,37 +156,42 @@ public final class XMLBuilder {
public XMLBuilder append(String elementName, String s) {
if (s != null) {
openTag(elementName);
builder.append(s);
builder.append(escape(s));
closeTag(elementName).newLine();
}
return this;
}
public XMLBuilder append(String elementName, Pattern p) {
if (p != null) {
openTag(elementName);
builder.append(p.pattern());
closeTag(elementName).newLine();
}
if (p != null)
append(elementName, p.pattern());
return this;
}
public XMLBuilder append(String elementName, Object o) {
if (o != null) {
openTag(elementName);
builder.append(o);
closeTag(elementName).newLine();
}
if (o != null)
append(elementName, "" + o);
return this;
}
@Override
public String toString() {
return builder.toString();
private static final Pattern P_XML_SPECIAL_CHARACTERS = Pattern.compile("[<>&]");
private static final String escape(String string) {
return P_XML_SPECIAL_CHARACTERS.matcher(string).find()
? string.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
: string;
}
public void appendTo(Appendable a) throws IOException {
a.append(builder);
}
@Override
public String toString() {
return builder.toString();
}
}