Example usage for org.springframework.http MediaType getQualityValue

List of usage examples for org.springframework.http MediaType getQualityValue

Introduction

In this page you can find the example usage for org.springframework.http MediaType getQualityValue.

Prototype

public double getQualityValue() 

Source Link

Document

Return the quality factor, as indicated by a q parameter, if any.

Usage

From source file:ar.com.zauber.commons.web.filter.webkit.WebKitContentTypeFilter.java

/**
 * @param request/* ww  w .  jav  a2 s  .  c  o m*/
 *            con user Agent de webkit
 * @return si existe un text/html con q < 1.
 */
private boolean wrongMediaType(final HttpServletRequest request) {
    for (MediaType mediaType : getMediaTypes(request)) {
        if (mediaType.getType().contains(TEXT) && mediaType.getSubtype().contains(HTML)
                && mediaType.getQualityValue() < 1.0) {
            // si tiene prioridad menor a 1 y es de tipo text/html
            return true;
        }
    }
    return false;
}

From source file:com.asual.summer.core.spring.ViewResolverConfiguration.java

public AbstractView handleViews(Collection<AbstractView> views, NativeWebRequest request) {
    List<MediaType> requestedMediaTypes;
    try {/*from ww  w .j ava 2 s  .  com*/
        requestedMediaTypes = contentNegotiationManager.resolveMediaTypes(request);
        for (MediaType requestedMediaType : requestedMediaTypes) {
            for (AbstractView view : views) {
                MediaType producableMediaType = MediaType.parseMediaType(view.getContentType());
                if (requestedMediaType.isCompatibleWith(producableMediaType)
                        && !requestedMediaType.isWildcardType() && requestedMediaType.getQualityValue() > 0.9) {
                    return view;
                }
            }

        }
    } catch (HttpMediaTypeNotAcceptableException e) {
        logger.debug(e.getMessage(), e);
    }
    return null;
}