getLanguage()源码实例Demo

javax.ws.rs.core.Variant#getLanguage()源码实例Demo

下面列出了javax.ws.rs.core.Variant#getLanguage() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cxf   文件: VariantListBuilderImplTest.java
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;
}
 
源代码2 项目: ldp4j   文件: VariantHelper.java
private static boolean hasMatchingLanguage(Variant supported, Variant required) {
	Locale requiredLanguage = required.getLanguage();
	Locale supportedLanguage = supported.getLanguage();
	return
		requiredLanguage == null ||
		supportedLanguage ==null ||
		isLanguageMatched(supportedLanguage, requiredLanguage);
}
 
源代码3 项目: ldp4j   文件: VariantUtils.java
private static String getLanguage(Variant v) {
	String language="*";
	Locale locale = v.getLanguage();
	if(locale!=null) {
		language=locale.toString();
	}
	return language;
}
 
源代码4 项目: ldp4j   文件: EndpointControllerUtils.java
static void populateResponseBody(ResponseBuilder builder, String entity, Variant variant, boolean includeEntity) {
	MediaType mediaType = variant.getMediaType();

	String charsetName=mediaType.getParameters().get(MediaType.CHARSET_PARAMETER);
	Charset charset=StandardCharsets.UTF_8;
	if(charsetName!=null && !charsetName.isEmpty() && Charset.isSupported(charsetName)) {
		charset=Charset.forName(charsetName);
	} else {
		LOGGER.error("Missing of invalid charset information {}",mediaType);
		charsetName=charset.name();
	}

	MediaType target=
		Configuration.includeCharsetInformation()?
			mediaType.withCharset(charsetName):
			new MediaType(mediaType.getType(),mediaType.getSubtype());

	byte[] bytes = entity.getBytes(charset);
	builder.
		type(target).
		header(MoreHttp.CONTENT_LENGTH_HEADER,bytes.length);

	if(variant.getLanguage()!=null) {
		builder.language(variant.getLanguage());
	}

	if(includeEntity) {
		builder.entity(new ByteArrayInputStream(bytes));
	}
}
 
源代码5 项目: cxf   文件: RequestImpl.java
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;
}
 
源代码评论
动弹
沙发等你来抢
 方法所在类