public class ContentType
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
static ContentType |
ANY
Wildcard content type that will match any MIME type
|
static ContentType |
APPLICATION_XML
A ContentType constant that describes the application/xml content
type.
|
static ContentType |
ATOM
A ContentType constant that describes the base unqualified Atom content
type.
|
static ContentType |
ATOM_ENTRY
A ContentType constant that describes the qualified Atom entry content
type.
|
static ContentType |
ATOM_FEED
A ContentType constant that describes the qualified Atom feed content
type.
|
static ContentType |
ATOM_SERVICE
A ContentType constant that describes the Atom Service content type.
|
static java.lang.String |
ATTR_CHARSET
Name of the attribute that contains the encoding character set for
the content type.
|
static ContentType |
GDATA_ERROR
A ContentType constant that describes the GData error content type.
|
static ContentType |
JAVASCRIPT
A ContentType constant that describes the Javascript content type.
|
static ContentType |
JSON
A ContentType constant that describes the JSON content type.
|
static ContentType |
MESSAGE_RFC822
A ContentType constant that indicates that the body contains an
encapsulated message, with the syntax of an RFC 822 email message.
|
static ContentType |
MULTIPART_RELATED
A ContentType constant that describes the MIME multipart/related content
type.
|
static ContentType |
OPENSEARCH
A ContentType constant that describes the OpenSearch description document
|
static ContentType |
RSS
A ContentType constant that describes the RSS channel/item content type.
|
static ContentType |
TEXT_HTML
A ContentType constant that describes the generic text/html content type.
|
static ContentType |
TEXT_PLAIN
A ContentType constant that describes the generic text/plain content type.
|
static ContentType |
TEXT_XML
A ContentType constant that describes the generic text/xml content type.
|
Constructor and Description |
---|
ContentType()
Constructs a new instance with default media type
|
ContentType(java.lang.String typeHeader)
Constructs a new instance from a content-type header value
parsing the MIME content type (RFC2045) format.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
static ContentType |
getAtomEntry()
Returns the ContentType that should be used in contexts that expect
an Atom entry.
|
static ContentType |
getAtomFeed()
Returns the ContentType that should be used in contexts that expect
an Atom feed.
|
java.lang.String |
getAttribute(java.lang.String name)
Returns the additional attribute by name of the content type.
|
java.util.Map<java.lang.String,java.lang.String> |
getAttributes()
Returns the additional attributes of the content type.
|
static ContentType |
getBestContentType(java.lang.String acceptHeader,
java.util.List<ContentType> actualContentTypes)
Determines the best "Content-Type" header to use in a servlet response
based on the "Accept" header from a servlet request.
|
java.lang.String |
getCharset() |
java.lang.String |
getMediaType()
Returns the full media type
|
java.lang.String |
getSubType() |
java.lang.String |
getType() |
int |
hashCode() |
ContentType |
lock()
Makes the object immutable and returns it.
|
boolean |
match(ContentType acceptedContentType)
Returns whether this content type is match by the content type found in the
"Accept" header field of an HTTP request.
|
void |
setSubType(java.lang.String subType) |
void |
setType(java.lang.String type) |
java.lang.String |
toString()
Generates the Content-Type value
|
public static final java.lang.String ATTR_CHARSET
getCharset()
,
Constant Field Valuespublic static final ContentType ATOM
public static final ContentType ATOM_ENTRY
getAtomEntry()
public static final ContentType ATOM_FEED
getAtomFeed()
public static final ContentType ATOM_SERVICE
public static final ContentType RSS
public static final ContentType JSON
public static final ContentType JAVASCRIPT
public static final ContentType TEXT_XML
public static final ContentType TEXT_HTML
public static final ContentType TEXT_PLAIN
public static final ContentType GDATA_ERROR
public static final ContentType OPENSEARCH
public static final ContentType MULTIPART_RELATED
public static final ContentType APPLICATION_XML
public static final ContentType MESSAGE_RFC822
public static final ContentType ANY
public ContentType()
public ContentType(java.lang.String typeHeader)
null
, then media type and charset will be
initialized to default values.typeHeader
- content type value in RFC2045 header format.public static ContentType getAtomEntry()
public static ContentType getAtomFeed()
public static ContentType getBestContentType(java.lang.String acceptHeader, java.util.List<ContentType> actualContentTypes)
acceptHeader
- "Accept" header value from a servlet request (not
null
)actualContentTypes
- actual content types in descending order of
preference (non-empty, and each entry is of the
form "type/subtype" without the wildcard char
'*') or null
if no "Accept" header
was specifiednull
on no match).public java.lang.String getType()
public void setType(java.lang.String type)
public java.lang.String getSubType()
public void setSubType(java.lang.String subType)
public java.lang.String getMediaType()
public ContentType lock()
ContentType
instance as
a static.public java.util.Map<java.lang.String,java.lang.String> getAttributes()
public java.lang.String getAttribute(java.lang.String name)
name
- attribute namepublic java.lang.String getCharset()
public boolean match(ContentType acceptedContentType)
For atom content type, this method will check the optional attribute
'type'. If the type attribute is set in both this and acceptedContentType
, then they must be the same. That is, application/atom+xml
will match both application/atom+xml;type=feed
and application/atom+xml;type=entry
, but application/atom+xml;type=entry
will not match application/atom+xml;type=feed
.a
acceptedContentType
- content type found in the "Accept" header field
of an HTTP requestpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object