public class ContentType extends ParameterizedHeader
ContentType
- Parses value of MIME header Content-Type
Modifier and Type | Class and Description |
---|---|
static class |
ContentType.UnmodifiableContentType
ContentType.UnmodifiableContentType - An unmodifiable content type. |
Modifier and Type | Field and Description |
---|---|
static ContentType |
DEFAULT_CONTENT_TYPE
The (unmodifiable) default content type:
text/plain; charset=us-ascii |
Constructor and Description |
---|
ContentType()
Initializes a new
ContentType |
ContentType(java.lang.String contentType)
Initializes a new
ContentType |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ParameterizedHeader other) |
boolean |
containsCharsetParameter() |
boolean |
containsNameParameter() |
boolean |
equals(java.lang.Object obj) |
java.lang.String |
getBaseType()
Gets this content type's base type without any parameters appended; e.g.
|
static java.lang.String |
getBaseType(java.lang.String mimeType)
Detects the base type of given MIME type
|
java.lang.String |
getCharsetParameter() |
java.lang.String |
getNameParameter() |
java.lang.String |
getPrimaryType() |
java.lang.String |
getSubType() |
int |
hashCode() |
boolean |
isBaseType(java.lang.String primaryType,
java.lang.String subType)
Checks if this Content-Type has specified base type.
|
boolean |
isMimeType(java.lang.String pattern)
Checks if Content-Type's base type matches given wildcard pattern (e.g text/plain, text/* or text/htm*)
|
static boolean |
isMimeType(java.lang.String mimeType,
java.lang.String pattern)
Checks if given MIME type's base type matches given wildcard pattern (e.g text/plain, text/* or text/htm*)
|
boolean |
matchesBaseType(java.lang.String primaryType,
java.lang.String subTypeExpression)
Checks if this Content-Type has specified base type.
|
static java.lang.String |
prepareContentTypeString(java.lang.String contentType)
Parses and prepares specified content-type string for being inserted into a MIME part's headers.
|
static java.lang.String |
prepareContentTypeString(java.lang.String contentType,
java.lang.String name)
Parses and prepares specified content-type string for being inserted into a MIME part's headers.
|
java.lang.String |
removeCharsetParameter() |
java.lang.String |
removeNameParameter() |
void |
reset()
Resets this
ContentType instance. |
ContentType |
setBaseType(java.lang.String baseType)
Sets base type (e.g. text/plain)
|
ContentType |
setCharsetParameter(java.lang.String charset)
Sets
"charset" parameter |
void |
setContentType(ContentType contentType)
Applies given content type to this content type
|
void |
setContentType(java.lang.String contentType)
Sets the content type to specified content type string; e.g.
|
ContentType |
setNameParameter(java.lang.String filename)
Sets
"name" parameter |
ContentType |
setPrimaryType(java.lang.String primaryType)
Sets primary type
|
ContentType |
setSubType(java.lang.String subType)
Sets sub-type
|
boolean |
startsWith(java.lang.String prefix)
Checks if Content-Type's base type ignore-case starts with specified prefix.
|
boolean |
startsWithAny(java.lang.String... prefixes)
Checks if Content-Type's base type ignore-case starts with any of specified prefixes.
|
java.lang.String |
toString() |
java.lang.String |
toString(boolean skipEmptyParams)
Returns a RFC2045 style (ASCII-only) string representation of this content type.
|
addParameter, clearParameters, containsParameter, getParameter, getParameterNames, removeParameter, setParameter
public static final ContentType DEFAULT_CONTENT_TYPE
text/plain; charset=us-ascii
public ContentType()
ContentType
public ContentType(java.lang.String contentType) throws com.openexchange.exception.OXException
ContentType
contentType
- The content typecom.openexchange.exception.OXException
- If content type cannot be parsedpublic void reset()
ContentType
instance.public int compareTo(ParameterizedHeader other)
compareTo
in interface java.lang.Comparable<ParameterizedHeader>
compareTo
in class ParameterizedHeader
public int hashCode()
hashCode
in class ParameterizedHeader
public boolean equals(java.lang.Object obj)
equals
in class ParameterizedHeader
public void setContentType(ContentType contentType)
contentType
- The content type to applypublic java.lang.String getPrimaryType()
public ContentType setPrimaryType(java.lang.String primaryType)
public java.lang.String getSubType()
public ContentType setSubType(java.lang.String subType)
public boolean isBaseType(java.lang.String primaryType, java.lang.String subType)
primaryType
- The primary type; e.g. "text"
subType
- The secondary type; e.g. "plain"
true
if equals given base type; otherwise false
public boolean matchesBaseType(java.lang.String primaryType, java.lang.String subTypeExpression)
primaryType
- The primary type; e.g. "text"
subTypeExpression
- The expression for secondary type; e.g. "*"
true
if matches given base type; otherwise false
public java.lang.String getBaseType()
"text/plain"
.public ContentType setBaseType(java.lang.String baseType) throws com.openexchange.exception.OXException
com.openexchange.exception.OXException
public ContentType setCharsetParameter(java.lang.String charset)
"charset"
parametercharset
- The charset parameter value; e.g. "UTF-8"
"charset"
parameter appliedpublic java.lang.String getCharsetParameter()
"charset"
value or null
if not presentpublic boolean containsCharsetParameter()
true
if "charset"
parameter is present, false
otherwisepublic java.lang.String removeCharsetParameter()
"charset"
parameter value or null
if there was nonepublic ContentType setNameParameter(java.lang.String filename)
"name"
parameterfilename
- The name parameter"name"
parameter appliedpublic java.lang.String getNameParameter()
"name"
value or null
if not presentpublic boolean containsNameParameter()
true
if "name"
parameter is present, false
otherwisepublic java.lang.String removeNameParameter()
"name"
parameter value or null
if there was nonepublic void setContentType(java.lang.String contentType) throws com.openexchange.exception.OXException
contentType
- The content type stringcom.openexchange.exception.OXException
- If specified content type string cannot be parsedpublic boolean isMimeType(java.lang.String pattern)
true
if Content-Type's base type matches given pattern, false
otherwisepublic boolean startsWith(java.lang.String prefix)
prefix
- The prefixtrue
if Content-Type's base type ignore-case starts with specified prefix; otherwise false
java.lang.IllegalArgumentException
- If specified prefix is null
public boolean startsWithAny(java.lang.String... prefixes)
prefixes
- The prefixestrue
if Content-Type's base type ignore-case starts with any of specified prefixes; otherwise false
public static java.lang.String prepareContentTypeString(java.lang.String contentType) throws com.openexchange.exception.OXException
contentType
- The content-type string to processcom.openexchange.exception.OXException
- If parsing content-type string failspublic static java.lang.String prepareContentTypeString(java.lang.String contentType, java.lang.String name) throws com.openexchange.exception.OXException
contentType
- The content-type string to processname
- The optional name parameter to set if no "name" parameter is present in specified content-type string; pass
null
to ignorecom.openexchange.exception.OXException
- If parsing content-type string failspublic static boolean isMimeType(java.lang.String mimeType, java.lang.String pattern) throws com.openexchange.exception.OXException
mimeType
- The MIME typepattern
- The patterntrue
if pattern matches; otherwise false
com.openexchange.exception.OXException
- If an invalid MIME type is detectedpublic static java.lang.String getBaseType(java.lang.String mimeType) throws com.openexchange.exception.OXException
mimeType
- The MIME typecom.openexchange.exception.OXException
- If an invalid MIME type is detectedpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean skipEmptyParams)
skipEmptyParams
- true
to skip empty parameters; otherwise false