Skip to content

Commit

Permalink
Added XMLTag
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Aug 31, 2023
1 parent 103a1e5 commit 5076942
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/dev/latvian/apps/webutils/html/RootTag.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package dev.latvian.apps.webutils.html;

import dev.latvian.apps.webutils.net.FileResponse;
import dev.latvian.apps.webutils.net.Response;
import io.javalin.http.HttpStatus;

import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.List;

public class RootTag extends PairedTag {
Expand Down Expand Up @@ -83,4 +88,9 @@ public void write(Writer writer) throws Throwable {
writer.write("<!DOCTYPE html>");
super.write(writer);
}

@Override
public Response asResponse(HttpStatus status) {
return FileResponse.of(status, "text/html; charset=utf-8", toString().getBytes(StandardCharsets.UTF_8));
}
}
3 changes: 1 addition & 2 deletions src/main/java/dev/latvian/apps/webutils/html/Tag.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.latvian.apps.webutils.html;

import dev.latvian.apps.webutils.ansi.Ansi;
import dev.latvian.apps.webutils.net.FileResponse;
import dev.latvian.apps.webutils.net.Response;
import io.javalin.http.Context;
import io.javalin.http.HttpStatus;
Expand Down Expand Up @@ -130,7 +129,7 @@ public Response asResponse() {
}

public Response asResponse(HttpStatus status) {
return FileResponse.of(status, "text/html; charset=utf-8", getRoot().toString().getBytes(StandardCharsets.UTF_8));
return getRoot().asResponse(status);
}

public Tag string(Object string) {
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/dev/latvian/apps/webutils/html/XMLTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.latvian.apps.webutils.html;

import dev.latvian.apps.webutils.net.FileResponse;
import dev.latvian.apps.webutils.net.Response;
import io.javalin.http.HttpStatus;

import java.io.Writer;
import java.nio.charset.StandardCharsets;

public class XMLTag extends PairedTag {
public XMLTag(String tag) {
super(tag);
}

@Override
public Tag getRoot() {
return this;
}

@Override
public void write(Writer writer) throws Throwable {
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
super.write(writer);
}

@Override
public Response asResponse(HttpStatus status) {
return FileResponse.of(status, "text/xml; charset=utf-8", toString().getBytes(StandardCharsets.UTF_8));
}
}

0 comments on commit 5076942

Please sign in to comment.