Package org.rapidcontext.core.web
Class Mime
java.lang.Object
org.rapidcontext.core.web.Mime
A MIME type helper class.
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String[]
The MIME types commonly used for binary data.static javax.servlet.ServletContext
The helper servlet context.static final String[]
The MIME types commonly used for CSS.static final String[]
The MIME types commonly used for GIF images.static final String[]
The MIME types commonly used for HTML.static final String[]
The MIME types commonly used for ICO images.static final String[]
The MIME types commonly used for JPEG images.static final String[]
The MIME types commonly used for JavaScript.static final String[]
The MIME types commonly used for JSON.static final String[]
The MIME types commonly used for Markdown.static final String[]
The MIME types commonly used for PNG images.static final String[]
The MIME types commonly used for Java Properties.static final String[]
The MIME types commonly used for SVG images.static final String[]
The MIME types commonly used for plain text.static final String[]
The MIME types commonly used for web form data.static final String[]
The MIME types commonly used for XML.static final String[]
The MIME types commonly used for YAML. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isInputMatch
(Request request, String[] mimes) Checks if the request input matches one of the specified MIME types.static boolean
Checks if a specified content type matches one of the specified MIME types.static boolean
isOutputMatch
(Request request, String[] mimes) Checks if the accepted request output matches one of the specified MIME types.static boolean
Checks if a specified content type is a known MIME type for text content.static String
Attempts to guess the MIME type for a file, based on the file name (extension).static String
Attempts to guess the MIME type for a file name (extension).
-
Field Details
-
TEXT
The MIME types commonly used for plain text. -
HTML
The MIME types commonly used for HTML. -
CSS
The MIME types commonly used for CSS. -
JS
The MIME types commonly used for JavaScript. -
JSON
The MIME types commonly used for JSON. -
PROPERTIES
The MIME types commonly used for Java Properties. -
XML
The MIME types commonly used for XML. -
YAML
The MIME types commonly used for YAML. -
MARKDOWN
The MIME types commonly used for Markdown. -
GIF
The MIME types commonly used for GIF images. -
JPEG
The MIME types commonly used for JPEG images. -
PNG
The MIME types commonly used for PNG images. -
SVG
The MIME types commonly used for SVG images. -
ICO
The MIME types commonly used for ICO images. -
BIN
The MIME types commonly used for binary data. -
WWW_FORM
The MIME types commonly used for web form data. -
context
public static javax.servlet.ServletContext contextThe helper servlet context. This can be set by the application to access the servlet container MIME type configuration.
-
-
Method Details
-
type
Attempts to guess the MIME type for a file, based on the file name (extension). This method will always return a valid MIME type, defaulting to the binary MIME type if unknown.- Parameters:
file
- the file to check- Returns:
- the file MIME type, or a binary MIME type if unknown
-
type
Attempts to guess the MIME type for a file name (extension). This method will always return a valid MIME type, defaulting to the binary MIME type if unknown.- Parameters:
fileName
- the file name to check- Returns:
- the file MIME type, or a binary MIME type if unknown
-
isText
Checks if a specified content type is a known MIME type for text content.- Parameters:
contentType
- the content type to analyze- Returns:
- true if the MIME type is for text content, or false otherwise
-
isMatch
Checks if a specified content type matches one of the specified MIME types. Note that this method checks for any match, without regard for any embedded quality or encoding value.- Parameters:
contentType
- the content type to analyzemimes
- the MIME types to check for- Returns:
- true if one of the MIME types is accepted, or false otherwise
-
isInputMatch
Checks if the request input matches one of the specified MIME types. The input MIME type is read from the 'Content-Type' HTTP header, not from the data stream itself.- Parameters:
request
- the request to analyzemimes
- the MIME types to check for- Returns:
- true if one of the MIME types match, or false otherwise
-
isOutputMatch
Checks if the accepted request output matches one of the specified MIME types. The accepted output MIME type is read from the 'Accept' HTTP header. Note that this method accept matches without regard for quality values in the header.- Parameters:
request
- the request to analyzemimes
- the MIME types to check for- Returns:
- true if one of the MIME types is accepted, or false otherwise
-