Java Code Examples for javax.ws.rs.core.Variant#getEncoding()

The following examples show how to use javax.ws.rs.core.Variant#getEncoding() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariantListBuilderImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private boolean verifyVariant(List<Variant> vs, Variant var) {
    for (Variant v : vs) {

        if (v.getLanguage() == null
            && v.getEncoding() == null
            && v.getMediaType() == null) {
            return false;
        }
        boolean encodCheck = v.getEncoding() == null && var.getEncoding() == null
                             || v.getEncoding().equals(var.getEncoding());
        boolean langCheck = v.getLanguage() == null && var.getLanguage() == null
                            || v.getLanguage().equals(var.getLanguage());
        boolean typeCheck = v.getMediaType() == null && var.getMediaType() == null
                            || v.getMediaType().equals(var.getMediaType());
        if (encodCheck && langCheck && typeCheck) {
            return true;
        }
    }

    return false;
}
 
Example 2
Source File: VariantHelper.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
private static boolean hasMatchingEncoding(Variant supported, Variant required) {
	String requiredEncoding = required.getEncoding();
	String supportedEncoding = supported.getEncoding();
	return
		requiredEncoding==null ||
		supportedEncoding==null ||
		supportedEncoding.equals(requiredEncoding);
}
 
Example 3
Source File: VariantUtils.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
private static String getEncoding(Variant v) {
	String encoding = v.getEncoding();
	if(encoding==null) {
		encoding="*";
	}
	return encoding;
}
 
Example 4
Source File: RequestImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Variant selectVariant(List<Variant> vars) throws IllegalArgumentException {
    if (vars == null || vars.isEmpty()) {
        throw new IllegalArgumentException("List of Variants is either null or empty");
    }
    List<MediaType> acceptMediaTypes = headers.getAcceptableMediaTypes();
    List<Locale> acceptLangs = headers.getAcceptableLanguages();
    List<String> acceptEncs = parseAcceptEnc(
        headers.getRequestHeaders().getFirst(HttpHeaders.ACCEPT_ENCODING));
    List<Variant> requestVariants = sortAllCombinations(acceptMediaTypes, acceptLangs, acceptEncs);
    List<Object> varyValues = new LinkedList<>();
    for (Variant requestVar : requestVariants) {
        for (Variant var : vars) {
            MediaType mt = var.getMediaType();
            Locale lang = var.getLanguage();
            String enc = var.getEncoding();

            boolean mtMatched = mt == null || requestVar.getMediaType().isCompatible(mt);
            if (mtMatched) {
                handleVaryValues(varyValues, HttpHeaders.ACCEPT);
            }

            boolean langMatched = lang == null || isLanguageMatched(requestVar.getLanguage(), lang);
            if (langMatched) {
                handleVaryValues(varyValues, HttpHeaders.ACCEPT_LANGUAGE);
            }

            boolean encMatched = acceptEncs.isEmpty() || enc == null 
                || isEncMatached(requestVar.getEncoding(), enc);
            if (encMatched) {
                handleVaryValues(varyValues, HttpHeaders.ACCEPT_ENCODING);
            }

            if (mtMatched && encMatched && langMatched) {
                addVaryHeader(varyValues);
                return var;
            }
        }
    }
    return null;
}
 
Example 5
Source File: VariantUtils.java    From ldp4j with Apache License 2.0 4 votes vote down vote up
private static String getTemplate(Variant v) {
	return
		v.getEncoding()!=null?
			TEMPLATES[0]:
			TEMPLATES[1];
}