import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile;
import com.fasterxml.jackson.annotation.JsonProperty;
-import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.hc.core5.http.NameValuePair;
import org.apache.hc.core5.net.WWWFormCodec;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
+import static kotlinx.html.Gen_consumer_tagsKt.html;
+import static kotlinx.html.Gen_tag_groupsKt.table;
+import static kotlinx.html.Gen_tag_unionsKt.a;
+import static kotlinx.html.Gen_tags_hKt.body;
+import static kotlinx.html.Gen_tags_tKt.caption;
+import static kotlinx.html.Gen_tags_tKt.tbody;
+import static kotlinx.html.Gen_tags_tKt.td;
+import static kotlinx.html.Gen_tags_tKt.th;
+import static kotlinx.html.Gen_tags_tKt.thead;
+import static kotlinx.html.Gen_tags_tKt.tr;
+import static kotlinx.html.stream.StreamKt.createHTML;
+import static net.pterodactylus.util.dom.KotlinXHtml.wrapper;
/**
* {@link State} that contains information about an arbitrary number of torrent
@Override
protected String htmlText() {
- StringBuilder htmlBuilder = new StringBuilder();
- htmlBuilder.append("<html><body>\n");
- htmlBuilder.append("<table>\n<caption>All Known Torrents</caption>\n");
- htmlBuilder.append("<thead>\n");
- htmlBuilder.append("<tr>");
- htmlBuilder.append("<th>Filename</th>");
- htmlBuilder.append("<th>Size</th>");
- htmlBuilder.append("<th>File(s)</th>");
- htmlBuilder.append("<th>Seeds</th>");
- htmlBuilder.append("<th>Leechers</th>");
- htmlBuilder.append("<th>Magnet</th>");
- htmlBuilder.append("<th>Download</th>");
- htmlBuilder.append("</tr>\n");
- htmlBuilder.append("</thead>\n");
- htmlBuilder.append("<tbody>\n");
- for (TorrentFile torrentFile : files.stream().sorted(sortNewFirst()).toList()) {
- if (newTorrentFiles.contains(torrentFile)) {
- htmlBuilder.append("<tr style=\"color: #008000; font-weight: bold;\">");
- } else {
- htmlBuilder.append("<tr>");
- }
- htmlBuilder.append("<td>").append(StringEscapeUtils.escapeHtml4(torrentFile.name())).append("</td>");
- htmlBuilder.append("<td>").append(StringEscapeUtils.escapeHtml4(torrentFile.size())).append("</td>");
- htmlBuilder.append("<td>").append(torrentFile.fileCount()).append("</td>");
- htmlBuilder.append("<td>").append(torrentFile.seedCount()).append("</td>");
- htmlBuilder.append("<td>").append(torrentFile.leechCount()).append("</td>");
- htmlBuilder.append("<td><a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.magnetUri())).append("\">Link</a></td>");
- htmlBuilder.append("<td><a href=\"").append(StringEscapeUtils.escapeHtml4(torrentFile.downloadUri())).append("\">Link</a></td>");
- htmlBuilder.append("</tr>\n");
- }
- htmlBuilder.append("</tbody>\n");
- htmlBuilder.append("</table>\n");
- htmlBuilder.append("</body></html>\n");
- return htmlBuilder.toString();
+ var tagConsumer = createHTML(true, true);
+ return html(tagConsumer, null, wrapper(html -> {
+ body(html, null, wrapper(body -> {
+ table(body, null, wrapper(table -> {
+ caption(table, null, wrapper(caption -> caption.text("All Known Torrents")));
+ thead(table, null, wrapper(thead -> {
+ tr(thead, null, wrapper(tr -> {
+ th(tr, null, null, wrapper(th -> th.text("Filename")));
+ th(tr, null, null, wrapper(th -> th.text("Size")));
+ th(tr, null, null, wrapper(th -> th.text("File(s)")));
+ th(tr, null, null, wrapper(th -> th.text("Seeds")));
+ th(tr, null, null, wrapper(th -> th.text("Leechers")));
+ th(tr, null, null, wrapper(th -> th.text("Magnets")));
+ th(tr, null, null, wrapper(th -> th.text("Download")));
+ }));
+ }));
+ tbody(table, null, wrapper(tbody -> {
+ for (TorrentFile torrentFile : files.stream().sorted(sortNewFirst()).toList()) {
+ tr(tbody, null, wrapper(tr -> {
+ if (newTorrentFiles.contains(torrentFile)) {
+ tr.getAttributes().put("style", "color: #008000; font-weight: bold;");
+ }
+ td(tr, null, wrapper(td -> td.text(torrentFile.name())));
+ td(tr, null, wrapper(td -> td.text(torrentFile.size())));
+ td(tr, null, wrapper(td -> td.text(torrentFile.fileCount())));
+ td(tr, null, wrapper(td -> td.text(torrentFile.seedCount())));
+ td(tr, null, wrapper(td -> td.text(torrentFile.leechCount())));
+ td(tr, null, wrapper(td -> a(td, torrentFile.magnetUri(), null, null, wrapper(a -> a.text("Link")))));
+ td(tr, null, wrapper(td -> a(td, torrentFile.downloadUri(), null, null, wrapper(a -> a.text("Link")))));
+ }));
+ }
+ }));
+ }));
+ }));
+ }));
}
/**