Class ContentType
java.lang.Object
org.apache.olingo.commons.api.format.ContentType
Internally used
ContentType
for OData library.
For more details on format and content of a ContentType
see
Media Type format as defined in
RFC 7231, chapter 3.1.1.1.
media-type = type "/" subtype *( OWS ";" OWS parameter ) type = token subtype = token OWS = *( SP / HTAB ) ; optional whitespace parameter = token "=" ( token / quoted-string )Once created a
ContentType
is IMMUTABLE.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final ContentType
static final String
static final String
static final String
static final ContentType
static final ContentType
static final ContentType
static final String
static final String
static final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic ContentType
Creates aContentType
based on given input string (format
).static ContentType
create
(ContentType contentType, String parameterName, String parameterValue) Creates a content type from an existing content type and an additional parameter as key-value pair.boolean
static ContentType
fromAcceptHeader
(String accept) Uses the first MIME type from the accept header to determine the content type.getParameter
(String name) Returns the value of a given parameter.Gets the parameters of this content type.Gets the subtype of this content type.getType()
Gets the type of this content type.int
hashCode()
boolean
isCompatible
(ContentType other) static ContentType
Parses the given input string (format
) and returns createdContentType
if input was valid or returnNULL
if input was not parseable.GetsContentType
as string as defined in RFC 7231, chapter 3.1.1.1: Media Type.toString()
-
Field Details
-
PARAMETER_CHARSET
- See Also:
-
PARAMETER_IEEE754_COMPATIBLE
- See Also:
-
PARAMETER_ODATA_METADATA
- See Also:
-
VALUE_ODATA_METADATA_NONE
- See Also:
-
VALUE_ODATA_METADATA_MINIMAL
- See Also:
-
VALUE_ODATA_METADATA_FULL
- See Also:
-
APPLICATION_JSON
-
JSON
-
JSON_NO_METADATA
-
JSON_FULL_METADATA
-
APPLICATION_XML
-
APPLICATION_ATOM_XML
-
APPLICATION_ATOM_XML_ENTRY
-
APPLICATION_ATOM_XML_ENTRY_UTF8
-
APPLICATION_ATOM_XML_FEED
-
APPLICATION_ATOM_XML_FEED_UTF8
-
APPLICATION_ATOM_SVC
-
APPLICATION_OCTET_STREAM
-
APPLICATION_XHTML_XML
-
TEXT_HTML
-
TEXT_XML
-
TEXT_PLAIN
-
APPLICATION_SVG_XML
-
APPLICATION_FORM_URLENCODED
-
APPLICATION_HTTP
-
MULTIPART_MIXED
-
MULTIPART_FORM_DATA
-
-
Method Details
-
create
public static ContentType create(ContentType contentType, String parameterName, String parameterValue) throws IllegalArgumentException Creates a content type from an existing content type and an additional parameter as key-value pair.- Parameters:
contentType
- an existing content typeparameterName
- the name of the additional parameterparameterValue
- the value of the additional parameter- Returns:
- a new
ContentType
object - Throws:
IllegalArgumentException
-
create
Creates aContentType
based on given input string (format
). Supported format isMedia Type
format as defined in RFC 7231, chapter 3.1.1.1.- Parameters:
format
- a string in format as defined in RFC 7231, chapter 3.1.1.1- Returns:
- a new
ContentType
object - Throws:
IllegalArgumentException
- if input string is not parseable
-
parse
Parses the given input string (format
) and returns createdContentType
if input was valid or returnNULL
if input was not parseable. For the definition of the supported format seecreate(String)
.- Parameters:
format
- a string in format as defined in RFC 7231, chapter 3.1.1.1- Returns:
- a new
ContentType
object
-
fromAcceptHeader
Uses the first MIME type from the accept header to determine the content type.- Parameters:
accept
- The accept header content, e.g. text/html,application/xhtml+xml,application/xml, may be null- Returns:
- The content type according to the accept header's first MIME type. Defaults to application/json if the accept header does not contain valid information. Never null.
-
getType
Gets the type of this content type. -
getSubtype
Gets the subtype of this content type. -
getParameters
Gets the parameters of this content type.- Returns:
- parameters of this
ContentType
as unmodifiable map
-
getParameter
Returns the value of a given parameter. If the parameter does not exist the method returns null.- Parameters:
name
- the name of the parameter to get (case-insensitive)- Returns:
- the value of the parameter or
null
if the parameter is not present
-
hashCode
public int hashCode() -
equals
-
isCompatible
ContentType
s are compatible iftype
andsubtype
have the same value.The set
parameters
are always ignored (for compare with parameters seeequals(Object)
).- Returns:
true
if both instances are compatible (see definition above), otherwisefalse
.
-
toContentTypeString
GetsContentType
as string as defined in RFC 7231, chapter 3.1.1.1: Media Type.- Returns:
- string representation of
ContentType
object
-
toString
-