use of io.quarkus.qute.ReflectionValueResolver 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();
}
use of io.quarkus.qute.ReflectionValueResolver in project quarkus-ls by redhat-developer.
the class TestLiteralQute method main.
public static void main(String[] args) {
List<Item> items = new ArrayList<>();
for (int i = 0; i < 5; i++) {
Item item = new Item(i);
items.add(item);
for (int j = 0; j < 7; j++) {
item.addReview(new Review(j));
}
}
Map<String, Object> data = new HashMap<>();
data.put("items", items);
Engine engine = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()).build();
Template template = engine.parse(convertStreamToString(TestLiteralQute.class.getResourceAsStream("literal.qute")));
String s = template.data(data).render();
System.err.println(s);
}
use of io.quarkus.qute.ReflectionValueResolver in project quarkus-ls by redhat-developer.
the class TestOrQute method main.
public static void main(String[] args) {
Map<String, Object> data = new HashMap<>();
data.put("item", new Item(0));
Engine engine = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()).build();
Template template = engine.parse(convertStreamToString(TestOrQute.class.getResourceAsStream("or.qute")));
String s = template.data(data).render();
System.err.println(s);
}
use of io.quarkus.qute.ReflectionValueResolver in project quarkus-ls by redhat-developer.
the class TestTemplateExtensionQute method main.
public static void main(String[] args) {
Map<String, Object> data = new HashMap<>();
data.put("item", new Item(0));
Engine engine = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()).build();
Template template = engine.parse(convertStreamToString(TestTemplateExtensionQute.class.getResourceAsStream("template-extensions.qute.html")));
String s = template.data(data).render();
System.err.println(s);
}
use of io.quarkus.qute.ReflectionValueResolver in project camel-quarkus by apache.
the class QuteEndpoint method getQuteEngine.
private synchronized Engine getQuteEngine() {
if (quteEngine == null) {
EngineBuilder builder = Engine.builder().addDefaults();
builder.addValueResolver(ReflectionValueResolver::new);
builder.addLocator(this::locate);
quteEngine = builder.build();
}
return quteEngine;
}
Aggregations