use of io.quarkus.qute.Escaper in project quarkus by quarkusio.
the class QuteErrorPageSetup method generatePage.
String generatePage(Throwable exception) {
Escaper escaper = Escaper.builder().add('"', """).add('\'', "'").add('&', "&").add('<', "<").add('>', ">").build();
Template problemTemplate = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()).addValueResolver(new ValueResolver() {
public boolean appliesTo(EvalContext context) {
return context.getName().equals("pad");
}
@Override
public CompletionStage<Object> resolve(EvalContext context) {
return CompletableFuture.completedFuture(htmlPadRight(context.getBase().toString(), 5));
}
}).build().parse(PROBLEM_TEMPLATE);
TemplateHtmlBuilder builder;
List<Throwable> problems;
Throwable[] suppressed = exception.getSuppressed();
if (suppressed.length == 0) {
problems = Collections.singletonList(exception);
} else {
problems = Arrays.asList(suppressed);
}
String problemsFound = "Found " + problems.size() + " Qute problems";
builder = new TemplateHtmlBuilder("Error restarting Quarkus", problemsFound, problemsFound);
// Attempt to sort problems by line
problems.sort(new Comparator<Throwable>() {
@Override
public int compare(Throwable t1, Throwable t2) {
Object o1 = getOrigin(t1);
Object o2 = getOrigin(t2);
if (o1 == o2) {
return 0;
} else if (o1 == null && o2 != null) {
return -1;
} else if (o1 != null && o2 == null) {
return 1;
}
return Integer.compare(getLine(o1), getLine(o2));
}
});
for (ListIterator<Throwable> it = problems.listIterator(); it.hasNext(); ) {
Throwable problem = it.next();
builder.append(getProblemInfo(it.previousIndex() + 1, problem, problemTemplate, escaper));
}
return builder.toString();
}
Aggregations