Class ConNeg


  • public class ConNeg
    extends java.lang.Object

    Content negotiation is a mechanism defined in the HTTP specification that makes it possible to serve different versions of a document (or more generally, a resource representation) at the same URI, so that user agents can specify which version fit their capabilities the best.

    ConNeg is used in Fuseki to help matching the content media type requested by the user, against the list of offered media types.

    See Also:
    http://en.wikipedia.org/wiki/Content_negotiation, http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
    • Constructor Summary

      Constructors 
      Constructor Description
      ConNeg()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static MediaType chooseCharset​(javax.servlet.http.HttpServletRequest httpRequest, AcceptList myPrefs, MediaType defaultMediaType)
      Chooses the charset by using the Accept-Charset HTTP header.
      static MediaType chooseContentType​(javax.servlet.http.HttpServletRequest httpRequest, AcceptList myPrefs, MediaType defaultMediaType)
      Choose the content media type by extracting the Accept HTTP header from the HTTP request and choosing (see choose(String, AcceptList, MediaType)) a content media type that matches the header.
      static java.lang.String match​(java.lang.String headerString, java.lang.String mediaRangeStr)
      Match a single media type against a header string.
      static MediaType match​(java.lang.String headerString, AcceptList offerList)
      Creates a AcceptList with the given HTTP header string and uses the AcceptList.match(MediaType) method to decide which media type matches the HTTP header string.
      static MediaType parse​(java.lang.String contentType)
      Parses the content type.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConNeg

        public ConNeg()
    • Method Detail

      • parse

        public static MediaType parse​(java.lang.String contentType)
        Parses the content type. It splits the string by semi-colon and finds the other features such as the "q" quality factor. For a complete documentation on how the parsing happens, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1.
        Parameters:
        contentType - content type string
        Returns:
        parsed media type
      • match

        public static MediaType match​(java.lang.String headerString,
                                      AcceptList offerList)

        Creates a AcceptList with the given HTTP header string and uses the AcceptList.match(MediaType) method to decide which media type matches the HTTP header string.

        The q quality factor is used to decide which choice is the best match.

        Parameters:
        headerString - HTTP header string
        offerList - accept list
        Returns:
        matched media type
      • match

        public static java.lang.String match​(java.lang.String headerString,
                                             java.lang.String mediaRangeStr)
        Match a single media type against a header string.
        Parameters:
        headerString - HTTP header string
        mediaRangeStr - Semi-colon separated list of media types
        Returns:
        the matched media type or null if there was no match
      • chooseCharset

        public static MediaType chooseCharset​(javax.servlet.http.HttpServletRequest httpRequest,
                                              AcceptList myPrefs,
                                              MediaType defaultMediaType)

        Chooses the charset by using the Accept-Charset HTTP header.

        See choose(String, AcceptList, MediaType).

        Parameters:
        httpRequest - HTTP request
        myPrefs - accept list
        defaultMediaType - default media type
        Returns:
        media type chosen
      • chooseContentType

        public static MediaType chooseContentType​(javax.servlet.http.HttpServletRequest httpRequest,
                                                  AcceptList myPrefs,
                                                  MediaType defaultMediaType)

        Choose the content media type by extracting the Accept HTTP header from the HTTP request and choosing (see choose(String, AcceptList, MediaType)) a content media type that matches the header.

        Parameters:
        httpRequest - HTTP request
        myPrefs - accept list
        defaultMediaType - default media type
        Returns:
        media type chosen