本文整理匯總了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;
}