Class ContentType

java.lang.Object
org.apache.olingo.commons.api.format.ContentType

public final class ContentType extends Object
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 Details

    • PARAMETER_CHARSET

      public static final String PARAMETER_CHARSET
      See Also:
    • PARAMETER_IEEE754_COMPATIBLE

      public static final String PARAMETER_IEEE754_COMPATIBLE
      See Also:
    • PARAMETER_ODATA_METADATA

      public static final String PARAMETER_ODATA_METADATA
      See Also:
    • VALUE_ODATA_METADATA_NONE

      public static final String VALUE_ODATA_METADATA_NONE
      See Also:
    • VALUE_ODATA_METADATA_MINIMAL

      public static final String VALUE_ODATA_METADATA_MINIMAL
      See Also:
    • VALUE_ODATA_METADATA_FULL

      public static final String VALUE_ODATA_METADATA_FULL
      See Also:
    • APPLICATION_JSON

      public static final ContentType APPLICATION_JSON
    • JSON

      public static final ContentType JSON
    • JSON_NO_METADATA

      public static final ContentType JSON_NO_METADATA
    • JSON_FULL_METADATA

      public static final ContentType JSON_FULL_METADATA
    • APPLICATION_XML

      public static final ContentType APPLICATION_XML
    • APPLICATION_ATOM_XML

      public static final ContentType APPLICATION_ATOM_XML
    • APPLICATION_ATOM_XML_ENTRY

      public static final ContentType APPLICATION_ATOM_XML_ENTRY
    • APPLICATION_ATOM_XML_ENTRY_UTF8

      public static final ContentType APPLICATION_ATOM_XML_ENTRY_UTF8
    • APPLICATION_ATOM_XML_FEED

      public static final ContentType APPLICATION_ATOM_XML_FEED
    • APPLICATION_ATOM_XML_FEED_UTF8

      public static final ContentType APPLICATION_ATOM_XML_FEED_UTF8
    • APPLICATION_ATOM_SVC

      public static final ContentType APPLICATION_ATOM_SVC
    • APPLICATION_OCTET_STREAM

      public static final ContentType APPLICATION_OCTET_STREAM
    • APPLICATION_XHTML_XML

      public static final ContentType APPLICATION_XHTML_XML
    • TEXT_HTML

      public static final ContentType TEXT_HTML
    • TEXT_XML

      public static final ContentType TEXT_XML
    • TEXT_PLAIN

      public static final ContentType TEXT_PLAIN
    • APPLICATION_SVG_XML

      public static final ContentType APPLICATION_SVG_XML
    • APPLICATION_FORM_URLENCODED

      public static final ContentType APPLICATION_FORM_URLENCODED
    • APPLICATION_HTTP

      public static final ContentType APPLICATION_HTTP
    • MULTIPART_MIXED

      public static final ContentType MULTIPART_MIXED
    • MULTIPART_FORM_DATA

      public static final ContentType 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 type
      parameterName - the name of the additional parameter
      parameterValue - the value of the additional parameter
      Returns:
      a new ContentType object
      Throws:
      IllegalArgumentException
    • create

      public static ContentType create(String format) throws IllegalArgumentException
      Creates a ContentType based on given input string (format). Supported format is Media 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

      public static ContentType parse(String format)
      Parses the given input string (format) and returns created ContentType if input was valid or return NULL if input was not parseable. For the definition of the supported format see create(String).
      Parameters:
      format - a string in format as defined in RFC 7231, chapter 3.1.1.1
      Returns:
      a new ContentType object
    • fromAcceptHeader

      public static ContentType fromAcceptHeader(String accept)
      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

      public String getType()
      Gets the type of this content type.
    • getSubtype

      public String getSubtype()
      Gets the subtype of this content type.
    • getParameters

      public Map<String,String> getParameters()
      Gets the parameters of this content type.
      Returns:
      parameters of this ContentType as unmodifiable map
    • getParameter

      public String getParameter(String name)
      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()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      ContentTypes are equal if type, subtype, and all parameters have the same value.
      Overrides:
      equals in class Object
    • isCompatible

      public boolean isCompatible(ContentType other)

      ContentTypes are compatible if type and subtype have the same value.

      The set parameters are always ignored (for compare with parameters see equals(Object)).

      Returns:
      true if both instances are compatible (see definition above), otherwise false.
    • toContentTypeString

      public String toContentTypeString()
      Gets ContentType as string as defined in RFC 7231, chapter 3.1.1.1: Media Type.
      Returns:
      string representation of ContentType object
    • toString

      public String toString()
      Overrides:
      toString in class Object