From 467dac37234fbc228adcc4381a6cf1fa5c582dbb Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Tue, 13 Feb 2024 18:39:15 +0100 Subject: [PATCH] Created the ContentType.java http entity --- .../de/gnmyt/mcdash/http/ContentType.java | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/main/java/de/gnmyt/mcdash/http/ContentType.java diff --git a/src/main/java/de/gnmyt/mcdash/http/ContentType.java b/src/main/java/de/gnmyt/mcdash/http/ContentType.java new file mode 100644 index 0000000..96e2bcb --- /dev/null +++ b/src/main/java/de/gnmyt/mcdash/http/ContentType.java @@ -0,0 +1,93 @@ +package de.gnmyt.mcdash.http; + +/** + * All content types needed by this plugin + */ +public enum ContentType { + + /** + * The default text content type + */ + TEXT("text/html", "html"), + + /** + * The json content type + */ + JSON("application/json", "json"), + + /** + * The multipart content type + */ + MULTIPART("multipart/form-data", null), + + /** + * The css content type + */ + CSS("text/css", "css"), + + /** + * The javascript content type + */ + JAVASCRIPT("application/javascript", "js"), + + /** + * The png content type + */ + PNG("image/png", "png"), + + /** + * The jpeg content type + */ + JPEG("image/jpeg", "jpeg"), + + /** + * The svg content type + */ + SVG("image/svg+xml", "svg"), + + /** + * The ico content type + */ + ICO("image/x-icon", "ico"), + + /** + * The woff2 content type + */ + WOFF2("font/woff2", "woff2"); + + private final String type; + private final String fileEnding; + + /** + * The basic constructor of the {@link ContentType} + * @param type The content type (header value) + */ + ContentType(String type, String fileEnding) { + this.type = type; + this.fileEnding = fileEnding; + } + + public static ContentType getContentType(String fileEnding) { + for (ContentType contentType : values()) { + if (contentType.getFileEnding() != null && fileEnding.endsWith(contentType.getFileEnding())) + return contentType; + } + return TEXT; + } + + /** + * Gets the content type + * @return the content type + */ + public String getType() { + return type; + } + + /** + * Gets the file ending of the content type + * @return the file ending of the content type + */ + public String getFileEnding() { + return fileEnding; + } +}