Skip to content

Commit d669122

Browse files
committed
Using jte.
Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
1 parent 2fbd1d3 commit d669122

File tree

4 files changed

+54
-20
lines changed

4 files changed

+54
-20
lines changed

frameworks/Java/helidon/nima/pom.xml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<rocker.version>1.3.0</rocker.version>
3939
<vertx-pg-client.version>4.5.3</vertx-pg-client.version>
4040
<jsoniter.version>0.9.23</jsoniter.version>
41+
<jte.version>3.1.15</jte.version>
4142
</properties>
4243

4344
<dependencies>
@@ -78,9 +79,9 @@
7879
<version>42.6.1</version>
7980
</dependency>
8081
<dependency>
81-
<groupId>com.fizzed</groupId>
82-
<artifactId>rocker-runtime</artifactId>
83-
<version>${rocker.version}</version>
82+
<groupId>gg.jte</groupId>
83+
<artifactId>jte</artifactId>
84+
<version>${jte.version}</version>
8485
</dependency>
8586
<dependency>
8687
<groupId>io.helidon.common.testing</groupId>
@@ -98,7 +99,6 @@
9899
<scope>test</scope>
99100
</dependency>
100101
</dependencies>
101-
102102
<build>
103103
<plugins>
104104
<plugin>
@@ -125,20 +125,21 @@
125125
</execution>
126126
</executions>
127127
</plugin>
128+
128129
<plugin>
129-
<groupId>com.fizzed</groupId>
130-
<artifactId>rocker-maven-plugin</artifactId>
131-
<version>${rocker.version}</version>
130+
<groupId>gg.jte</groupId>
131+
<artifactId>jte-maven-plugin</artifactId>
132+
<version>${jte.version}</version>
133+
<configuration>
134+
<sourceDirectory>${project.basedir}/src/main/resources/views</sourceDirectory>
135+
<contentType>Html</contentType>
136+
</configuration>
132137
<executions>
133138
<execution>
134-
<id>generate-rocker-templates</id>
135139
<phase>generate-sources</phase>
136140
<goals>
137141
<goal>generate</goal>
138142
</goals>
139-
<configuration>
140-
<templateDirectory>src/main/resources</templateDirectory>
141-
</configuration>
142143
</execution>
143144
</executions>
144145
</plugin>

frameworks/Java/helidon/nima/src/main/java/io/helidon/benchmark/nima/services/FortuneHandler.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11

22
package io.helidon.benchmark.nima.services;
33

4+
import java.io.IOException;
5+
import java.io.OutputStream;
6+
import java.nio.charset.StandardCharsets;
47
import java.util.Comparator;
58
import java.util.List;
69

7-
import com.fizzed.rocker.runtime.ArrayOfByteArraysOutput;
10+
import gg.jte.TemplateOutput;
811
import io.helidon.benchmark.nima.models.DbRepository;
912
import io.helidon.benchmark.nima.models.Fortune;
1013
import io.helidon.webserver.http.Handler;
1114
import io.helidon.webserver.http.ServerRequest;
1215
import io.helidon.webserver.http.ServerResponse;
13-
import views.fortunes;
16+
17+
import gg.jte.html.OwaspHtmlTemplateOutput;
18+
import gg.jte.generated.precompiled.JtefortunesGenerated;
1419

1520
import static io.helidon.benchmark.nima.Main.CONTENT_TYPE_HTML;
1621
import static io.helidon.benchmark.nima.Main.SERVER;
@@ -33,8 +38,38 @@ public void handle(ServerRequest req, ServerResponse res) {
3338
List<Fortune> fortuneList = repository.getFortunes();
3439
fortuneList.add(ADDITIONAL_FORTUNE);
3540
fortuneList.sort(Comparator.comparing(Fortune::getMessage));
36-
res.send(fortunes.template(fortuneList)
37-
.render(ArrayOfByteArraysOutput.FACTORY)
38-
.toByteArray());
41+
try (OutputStream os = res.outputStream()) {
42+
JtefortunesGenerated.render(new OwaspHtmlTemplateOutput(new HelidonTemplateOutput(os)),
43+
null, fortuneList);
44+
} catch (IOException e) {
45+
throw new RuntimeException(e);
46+
}
3947
}
48+
49+
static class HelidonTemplateOutput implements TemplateOutput{
50+
private final OutputStream os;
51+
52+
HelidonTemplateOutput(OutputStream os) {
53+
this.os = os;
54+
}
55+
56+
@Override
57+
public void writeContent(String value) {
58+
writeBinaryContent(value.getBytes(StandardCharsets.UTF_8));
59+
}
60+
61+
@Override
62+
public void writeContent(String value, int beginIndex, int endIndex) {
63+
writeBinaryContent(value.substring(beginIndex, endIndex).getBytes(StandardCharsets.UTF_8));
64+
}
65+
66+
@Override
67+
public void writeBinaryContent(byte[] value) {
68+
try {
69+
os.write(value);
70+
} catch (IOException e) {
71+
throw new RuntimeException(e);
72+
}
73+
}
74+
};
4075
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@param java.util.List<io.helidon.benchmark.nima.models.Fortune> fortunes
2+
<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>@for(io.helidon.benchmark.nima.models.Fortune fortune : fortunes)<tr><td>${fortune.getId()}</td><td>${fortune.getMessage()}</td></tr>@endfor</table></body></html>

frameworks/Java/helidon/nima/src/main/resources/views/fortunes.rocker.html

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)