Added fail-safe

This commit is contained in:
M66B 2023-11-28 11:43:30 +01:00
parent 2fb0edb782
commit 1db2a69265
1 changed files with 20 additions and 13 deletions

View File

@ -41,20 +41,27 @@ public class StructuredEmail {
} }
public String getHtml(Context context) throws JSONException { public String getHtml(Context context) throws JSONException {
StringBuilder sb = new StringBuilder(); try {
getHtml(jroot, 0, sb); StringBuilder sb = new StringBuilder();
getHtml(jroot, 0, sb);
Document d = Document.createShell(""); Document d = Document.createShell("");
d.appendElement("hr"); d.body().appendElement("hr");
d.appendElement("div") d.body().appendElement("div")
.attr("style", "font-size: larger !important;") .attr("style", "font-size: larger !important;")
.text("Linked Data"); .text("Linked Data");
d.appendElement("br"); d.body().appendElement("br");
d.appendElement("div") d.body().appendElement("div")
.attr("style", "font-size: smaller !important;") .attr("style", "font-size: smaller !important;")
.html(HtmlHelper.formatPlainText(sb.toString())); .html(HtmlHelper.formatPlainText(sb.toString()));
d.appendElement("hr"); d.body().appendElement("hr");
return d.html(); return d.body().html();
} catch (Throwable ex) {
Log.e(ex);
Document d = Document.createShell("");
d.body().append("pre").text(Log.formatThrowable(ex, false));
return d.body().html();
}
} }
private void getHtml(Object obj, int indent, StringBuilder sb) throws JSONException { private void getHtml(Object obj, int indent, StringBuilder sb) throws JSONException {