Class ContentType
java.lang.Object
org.apache.olingo.odata2.core.commons.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 2616 chapter 3.7
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html).
media-type = type "/" subtype *( ";" parameter )
type = token
subtype = token
Especially for Accept Header as defined in
RFC 2616 chapter 14.1 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html):
Accept = "Accept" ":"
#( media-range [ accept-params ] )
media-range = ( "* /*"
| ( type "/" "*" )
| ( type "/" subtype )
) *( ";" parameter )
accept-params = ";" "q" "=" qvalue *( accept-extension )
accept-extension = ";" token [ "=" ( token | quoted-string ) ]
Especially for Content-Type Header as defined in
RFC 2616 chapter 14.7 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html):
Content-Type = "Content-Type" ":" media-type
Once created a ContentType is IMMUTABLE.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final Stringstatic final ContentTypestatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentTypestatic final ContentType -
Method Summary
Modifier and TypeMethodDescriptionintcompareWildcardCounts(ContentType otherContentType) Compare wildcards counts/weights of bothContentType.static List<ContentType> static ContentTypeCreate aContentTypebased on given input string (format).static ContentTypeCreates a content type from type and subtypestatic ContentTypestatic List<ContentType> Create a list ofContentTypebased on given input strings (contentTypes).static ContentTypecreate(ContentType contentType, String parameterKey, String parameterValue) static ContentTypecreateAsCustom(String format) Create aContentTypebased on given input string (format).static List<ContentType> createAsCustom(List<String> contentTypeStrings) Create a list ofContentTypebased on given input strings (contentTypes).booleanContentTypes are equal iftype,subtypeand allparametershave the same value. iftypeand/orsubtypeis set to "*" (in such a case theparametersare ignored).getType()booleanhasCompatible(List<ContentType> toMatchContentTypes) Check if a valid compatible match for thisContentTypeexists in given list.inthashCode()booleanhasMatch(List<ContentType> toMatchContentTypes) Check if a valid match for thisContentTypeexists in given list.booleanbooleanisCompatible(ContentType obj) ContentTypes are compatible iftype,subtypehave the same value. iftypeand/orsubtypeis set to "*" The setparametersare always ignored (for compare with parameters seeequals(Object)).booleanstatic booleanisParseable(String format) Validates if givenformatis parseable and can be used as input forcreate(String)method.static booleanisParseableAsCustom(String format) Validates if givenformatis parseable and can be used as input forcreate(String)method.booleanstatic booleanmatch(String toMatch, ContentType... matchExamples) Check if a valid match for given content type formated string (toMatch) exists in given list.match(List<ContentType> toMatchContentTypes) Find best match between thisContentTypeand theContentTypein the list.matchCompatible(List<ContentType> toMatchContentTypes) Find best match between thisContentTypeand theContentTypein the list ignoring all set parameters.static ContentTypeParses the given input string (format) and returns createdContentTypeif input was valid or returnNULLif input was not parseable.receiveWithCharsetParameter(String defaultCharset) Ensure that charset parameter (PARAMETER_CHARSET) is set on returned content type if thisContentTypeis aodata text relatedcontent type (@seeisContentTypeODataTextRelated()).static voidsortForQParameter(List<String> toSort) Sort given list (which must contains content type formated string) for their "q" value as defined in RFC 2616 section 4.1 and RFC 2616 Section 3.9.GetContentTypeas string as defined in RFC 2616 (http://www.ietf.org/rfc/rfc2616.txt - chapter 14.17: Content-Type)toString()
-
Field Details
-
PARAMETER_CHARSET
- See Also:
-
PARAMETER_ODATA
- See Also:
-
PARAMETER_Q
- See Also:
-
PARAMETER_TYPE
- See Also:
-
CHARSET_UTF_8
- See Also:
-
WILDCARD
-
APPLICATION_XML
-
APPLICATION_XML_CS_UTF_8
-
APPLICATION_ATOM_XML
-
APPLICATION_ATOM_XML_CS_UTF_8
-
APPLICATION_ATOM_XML_ENTRY
-
APPLICATION_ATOM_XML_ENTRY_CS_UTF_8
-
APPLICATION_ATOM_XML_FEED
-
APPLICATION_ATOM_XML_FEED_CS_UTF_8
-
APPLICATION_ATOM_SVC
-
APPLICATION_ATOM_SVC_CS_UTF_8
-
APPLICATION_JSON
-
APPLICATION_JSON_ODATA_VERBOSE
-
APPLICATION_JSON_CS_UTF_8
-
APPLICATION_OCTET_STREAM
-
TEXT_PLAIN
-
TEXT_PLAIN_CS_UTF_8
-
MULTIPART_MIXED
-
TEXT_JAVASCRIPT
-
TEXT_JAVASCRIPT_UTF_8
-
-
Method Details
-
isParseable
Validates if givenformatis parseable and can be used as input forcreate(String)method.- Parameters:
format- to be validated string- Returns:
trueif format is parseable otherwisefalse
-
isParseableAsCustom
Validates if givenformatis parseable and can be used as input forcreate(String)method.- Parameters:
format- to be validated string- Returns:
trueif format is parseable otherwisefalse
-
create
Creates a content type from type and subtype- Parameters:
type- Tiposubtype- Subtipo- Returns:
- a new
ContentTypeobject
-
create
- Parameters:
type- Tiposubtype- Subtipoparameters- Parametros- Returns:
- a new
ContentTypeobject
-
create
public static ContentType create(ContentType contentType, String parameterKey, String parameterValue) - Parameters:
contentType- TipoparameterKey- ChaveparameterValue- Valor- Returns:
- a new
ContentTypeobject
-
create
Create aContentTypebased on given input string (format). Supported format isMedia Typeformat as defined inRFC 2616 chapter 3.7. This format is used asHTTP Accept HEADERformat as defined inRFC 2616 chapter 14.1andHTTP Content-Type HEADERformat as defined inRFC 2616 chapter 14.17- Parameters:
format- a string in format as defined inRFC 2616 section 3.7- Returns:
- a new
ContentTypeobject - Throws:
IllegalArgumentException- if input string is not parseable
-
createAsCustom
Create aContentTypebased on given input string (format). Supported format isMedia Typeformat as defined inRFC 2616 chapter 3.7. andContentTypewithContentType.ODataFormat.CUSTOM. TheMedia Typeformat can be used asHTTP Accept HEADERformat as defined inRFC 2616 chapter 14.1andHTTP Content-Type HEADERformat as defined inRFC 2616 chapter 14.17. TheContentTypewithContentType.ODataFormat.CUSTOMcan only be used as$formatsystem query option (as defined http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/#47_Format_System_Query_Option_format).- Parameters:
format- a string in format as defined inRFC 2616 section 3.7- Returns:
- a new
ContentTypeobject - Throws:
IllegalArgumentException- if input string is not parseable
-
create
Create a list ofContentTypebased on given input strings (contentTypes). Supported format isMedia Typeformat as defined inRFC 2616 chapter 3.7. This format is used asHTTP Accept HEADERformat as defined inRFC 2616 chapter 14.1andHTTP Content-Type HEADERformat as defined inRFC 2616 chapter 14.17.If one of the given strings can not be parsed an exception is thrown (hence no list is returned with the parseable strings).
- Parameters:
contentTypeStrings- a list of strings in format as defined inRFC 2616 section 3.7- Returns:
- a list of new
ContentTypeobject - Throws:
IllegalArgumentException- if one of the given input string is not parseable this exceptions is thrown
-
createAsCustom
Create a list ofContentTypebased on given input strings (contentTypes). Supported format isMedia Typeformat as defined inRFC 2616 chapter 3.7. andContentTypewithContentType.ODataFormat.CUSTOM. TheMedia Typeformat can be used asHTTP Accept HEADERformat as defined inRFC 2616 chapter 14.1andHTTP Content-Type HEADERformat as defined inRFC 2616 chapter 14.17. TheContentTypewithContentType.ODataFormat.CUSTOMcan only be used as$formatsystem query option (as defined http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/#47_Format_System_Query_Option_format).- Parameters:
contentTypeStrings- a list of strings in format as defined inRFC 2616 section 3.7or as defined http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/#47_Format_System_Query_Option_format- Returns:
- a list of new
ContentTypeobject - Throws:
IllegalArgumentException- if one of the given input string is not parseable this exceptions is thrown
-
parse
Parses the given input string (format) and returns createdContentTypeif input was valid or returnNULLif input was not parseable. For the definition of the supported format seecreate(String).- Parameters:
format- a string in format as defined inRFC 2616 section 3.7- Returns:
- a new
ContentTypeobject
-
sortForQParameter
Sort given list (which must contains content type formated string) for their "q" value as defined in RFC 2616 section 4.1 and RFC 2616 Section 3.9. Attention: For invalid values a "q" value from-1is used for sorting.- Parameters:
toSort- list which is sorted and hence re-arranged
-
receiveWithCharsetParameter
Ensure that charset parameter (PARAMETER_CHARSET) is set on returned content type if thisContentTypeis aodata text relatedcontent type (@seeisContentTypeODataTextRelated()). IfthisContentTypehas no charset parameter set a newContentTypewith givendefaultCharsetis created. Otherwise if charset parameter is already set nothing is done.- Parameters:
defaultCharset- Charset- Returns:
- ContentType
-
isContentTypeODataTextRelated
public boolean isContentTypeODataTextRelated()- Returns:
trueif thisContentTypeis text related (in the view of OData)
-
getType
-
getSubtype
-
getParameters
- Returns:
- parameters of this
ContentTypeas unmodifiable map.
-
hashCode
public int hashCode() -
equals
ContentTypes are equal- if
type,subtypeand allparametershave the same value. - if
typeand/orsubtypeis set to "*" (in such a case theparametersare ignored).
- if
-
isCompatible
ContentTypes are compatible- if
type,subtypehave the same value. - if
typeand/orsubtypeis set to "*"
parametersare always ignored (for compare with parameters seeequals(Object)).- Parameters:
obj- Objeto- Returns:
trueif both instances are equal (see definition above), otherwisefalse.
- if
-
toContentTypeString
GetContentTypeas string as defined in RFC 2616 (http://www.ietf.org/rfc/rfc2616.txt - chapter 14.17: Content-Type)- Returns:
- string representation of
ContentTypeobject
-
toString
-
getODataFormat
-
match
Find best match between thisContentTypeand theContentTypein the list. If a match (thisContentTypeis equal to aContentTypein list) is found either this or theContentTypefrom the list is returned based on whichContentTypehas less "**" characters set (checked withcompareWildcardCounts(ContentType). If no match (noneContentTypein list is equal to thisContentType) is foundNULLis returned.- Parameters:
toMatchContentTypes- list ofContentTypes which are matches against thisContentType- Returns:
- best matched content type in list or
NULLif none content type match to this content type instance
-
matchCompatible
Find best match between thisContentTypeand theContentTypein the list ignoring all set parameters. If a match (thisContentTypeis equal to aContentTypein list) is found either this or theContentTypefrom the list is returned based on whichContentTypehas less "**" characters set (checked withcompareWildcardCounts(ContentType). If no match (noneContentTypein list is equal to thisContentType) is foundNULLis returned.- Parameters:
toMatchContentTypes- list ofContentTypes which are matches against thisContentType- Returns:
- best matched content type in list or
NULLif none content type match to this content type instance
-
hasCompatible
Check if a valid compatible match for thisContentTypeexists in given list. Compatible in this case means that all set parameters are ignored. For more detail what a valid match is seematchCompatible(List).- Parameters:
toMatchContentTypes- list ofContentTypes which are matches against thisContentType- Returns:
trueif a compatible content type was found in given list orfalseif none compatible content type match was found
-
hasMatch
Check if a valid match for thisContentTypeexists in given list. For more detail what a valid match is seematch(List).- Parameters:
toMatchContentTypes- list ofContentTypes which are matches against thisContentType- Returns:
trueif a matching content type was found in given list orfalseif none matching content type match was found
-
compareWildcardCounts
Compare wildcards counts/weights of bothContentType. The smallerContentTypehas lesser weighted wildcards then the biggerContentType. As result this method returns this object weighted wildcards minus the given parameter object weighted wildcards. A type wildcard is weighted with2and a subtype wildcard is weighted with1.- Parameters:
otherContentType-ContentTypeto be compared to- Returns:
- this object weighted wildcards minus the given parameter object weighted wildcards.
-
hasWildcard
public boolean hasWildcard()- Returns:
trueiftypeorsubtypeof this instance is a "*".
-
isWildcard
public boolean isWildcard()- Returns:
trueif bothtypeandsubtypeof this instance are a "*".
-
convert
-
match
Check if a valid match for given content type formated string (toMatch) exists in given list. Therefore the given content type formated string (toMatch) is converted into aContentTypewith a simplecreate(String)call (during which an exception can occur). For more detail in general seehasMatch(List)and for what a valid match is seematch(List).- Parameters:
toMatch- content type formated string (toMatch) for which is checked if a match exists in given listmatchExamples- list ofContentTypes which are matches against content type formated string (toMatch)- Returns:
trueif a matching content type was found in given list orfalseif none matching content type match was found
-