本文整理汇总了Java中io.vertx.ext.web.LanguageHeader类的典型用法代码示例。如果您正苦于以下问题:Java LanguageHeader类的具体用法?Java LanguageHeader怎么用?Java LanguageHeader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LanguageHeader类属于io.vertx.ext.web包,在下文中一共展示了LanguageHeader类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebIContext
import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
private WebIContext(Map<String, Object> data, LanguageHeader locale) {
this.data = data;
if (locale == null) {
this.locale = java.util.Locale.getDefault();
} else {
String country = locale.subtag();
String variant = locale.subtag(2);
this.locale = new java.util.Locale(locale.tag(), country == null ? "" : country, variant == null ? "" : variant);
}
}
示例2: render
import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
public void render(RoutingContext context, String templateDirectory, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
try {
templateFileName = templateDirectory + templateFileName;
PebbleTemplate template = isCachingEnabled() ? cache.get(templateFileName) : null;
if (template == null) {
// real compile
final String loc = adjustLocation(templateFileName);
template = pebbleEngine.getTemplate(loc);
if (isCachingEnabled()) {
cache.put(templateFileName, template);
}
}
final Locale locale = context.acceptableLanguages()
.stream()
.findFirst()
.map(LanguageHeader::value)
.map(Locale::forLanguageTag)
.orElseGet(Locale::getDefault);
final Map<String, Object> variables = new HashMap<>(1);
variables.put("context", context);
// Pass defined variables in context to engine
variables.putAll(context.data());
final StringWriter stringWriter = new StringWriter();
template.evaluate(stringWriter, variables, locale);
handler.handle(Future.succeededFuture(Buffer.buffer(stringWriter.toString())));
} catch (final Exception ex) {
handler.handle(Future.failedFuture(ex));
}
}
示例3: ParsableHeaderValuesContainer
import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
public ParsableHeaderValuesContainer(
List<MIMEHeader> accept, List<ParsedHeaderValue> acceptCharset, List<ParsedHeaderValue> acceptEncoding,
List<LanguageHeader> acceptLanguage, ParsableMIMEValue contentType) {
this.accept = accept;
this.acceptCharset = acceptCharset;
this.acceptEncoding = acceptEncoding;
this.acceptLanguage = acceptLanguage;
this.contentType = contentType;
}
示例4: acceptableLanguages
import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
public List<LanguageHeader> acceptableLanguages() {
return delegate.acceptableLanguages();
}
示例5: preferredLanguage
import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
public LanguageHeader preferredLanguage() {
return delegate.preferredLanguage();
}
示例6: acceptableLanguages
import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
@CacheReturn
public List<LanguageHeader> acceptableLanguages() {
return context.acceptableLanguages();
}
示例7: preferredLanguage
import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
@CacheReturn
public LanguageHeader preferredLanguage() {
return context.preferredLanguage();
}
示例8: render
import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
public void render(RoutingContext context, String templateDirectory, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
templateFileName = templateDirectory + templateFileName;
Buffer buffer = Buffer.buffer();
try {
Map<String, Object> data = new HashMap<>();
data.put("context", context);
data.putAll(context.data());
synchronized (this) {
templateResolver.setVertx(context.vertx());
final List<LanguageHeader> acceptableLocales = context.acceptableLanguages();
LanguageHeader locale = null;
if (acceptableLocales.size() > 0) {
// this is the users preferred locale
locale = acceptableLocales.get(0);
}
templateEngine.process(templateFileName, new WebIContext(data, locale), new Writer() {
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
buffer.appendString(new String(cbuf, off, len));
}
@Override
public void flush() throws IOException {
}
@Override
public void close() throws IOException {
}
});
}
handler.handle(Future.succeededFuture(buffer));
} catch (Exception ex) {
handler.handle(Future.failedFuture(ex));
}
}
示例9: acceptLanguage
import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
public List<LanguageHeader> acceptLanguage() {
return acceptLanguage;
}