MimeType.java
- package org.flasby.thymeleaf;
- import java.net.URI;
- import java.util.HashMap;
- import java.util.Map;
- import lombok.extern.log4j.Log4j2;
- @Log4j2
- public class MimeType {
- public static final String TEXT = "text/html";
- public static final String CSS = "text/css";
- public static final String JS = "text/javascript";
- public static final String ICON = "image/x-icon";
- private static Map<String, String> suffixToMime = new HashMap<>();
- static {
- suffixToMime.put(".html", TEXT);
- suffixToMime.put(".css", CSS);
- suffixToMime.put(".js", JS);
- suffixToMime.put(".ico", ICON);
- }
- public static String getMimeTypeFor(String fileSuffix) {
- return suffixToMime.getOrDefault(fileSuffix, TEXT);
- }
- public static String getMimeTypeFor(URI request) {
- if (!request.getPath().contains(".")) {
- return TEXT;
- }
- String suffix = request.getPath().substring(request.getPath().lastIndexOf('.'));
- String mimetype = getMimeTypeFor(suffix);
- LOG.debug("Getting mime type for {} : {}",request.getPath(), mimetype);
- return mimetype;
- }
- }