org.eclipse.lyo.oslc4j.utils
Class AcceptUtil

java.lang.Object
  extended by org.eclipse.lyo.oslc4j.utils.AcceptUtil

public class AcceptUtil
extends Object

Utilities for matching media types from an HTTP Accept header. Note it is usually better if using Wink to annotate methods with Produces and let JAX-RS process the Accept header for you, but in some contexts, it's not possible.


Field Summary
static javax.ws.rs.core.MediaType[] OSLC_ACCEPTABLE
           
 
Constructor Summary
AcceptUtil()
           
 
Method Summary
static javax.ws.rs.core.MediaType matchMediaType(javax.servlet.http.HttpServletRequest request)
          Matches requested media types against OSLC_ACCEPTABLE media types.
static javax.ws.rs.core.MediaType matchMediaType(javax.servlet.http.HttpServletRequest request, javax.ws.rs.core.MediaType[] acceptable)
          Matches requested media types against a list of acceptable media types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OSLC_ACCEPTABLE

public static final javax.ws.rs.core.MediaType[] OSLC_ACCEPTABLE
Constructor Detail

AcceptUtil

public AcceptUtil()
Method Detail

matchMediaType

public static javax.ws.rs.core.MediaType matchMediaType(javax.servlet.http.HttpServletRequest request)
Matches requested media types against OSLC_ACCEPTABLE media types.

Parameters:
request - the HTTP request
Returns:
A matching media type, or null if none match. If there is no Accept header, returns OslcMediaType.APPLICATION_RDF_XML_TYPE.

matchMediaType

public static javax.ws.rs.core.MediaType matchMediaType(javax.servlet.http.HttpServletRequest request,
                                                        javax.ws.rs.core.MediaType[] acceptable)
Matches requested media types against a list of acceptable media types.

Parameters:
request - the HTTP request
acceptable - a list of acceptable media types in order of preference
Returns:
A matching media type, or null if none match. If there is no Accept header, returns the first media type in acceptable.


Copyright © 2014. All Rights Reserved.