Search in sources :

Example 1 with Escaper

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('"', "&quot;").add('\'', "&#39;").add('&', "&amp;").add('<', "&lt;").add('>', "&gt;").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();
}
Also used : EvalContext(io.quarkus.qute.EvalContext) Template(io.quarkus.qute.Template) ReflectionValueResolver(io.quarkus.qute.ReflectionValueResolver) TemplateHtmlBuilder(io.quarkus.runtime.TemplateHtmlBuilder) ValueResolver(io.quarkus.qute.ValueResolver) ReflectionValueResolver(io.quarkus.qute.ReflectionValueResolver) Escaper(io.quarkus.qute.Escaper) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

Escaper (io.quarkus.qute.Escaper)1 EvalContext (io.quarkus.qute.EvalContext)1 ReflectionValueResolver (io.quarkus.qute.ReflectionValueResolver)1 Template (io.quarkus.qute.Template)1 ValueResolver (io.quarkus.qute.ValueResolver)1 TemplateHtmlBuilder (io.quarkus.runtime.TemplateHtmlBuilder)1 CompletionStage (java.util.concurrent.CompletionStage)1