当前位置: 首页>>代码示例>>Java>>正文


Java LanguageHeader类代码示例

本文整理汇总了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);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:11,代码来源:ThymeleafTemplateEngineImpl.java

示例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));
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:31,代码来源:PebbleTemplateEngineImpl.java

示例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;
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:10,代码来源:ParsableHeaderValuesContainer.java

示例4: acceptableLanguages

import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
public List<LanguageHeader> acceptableLanguages() {
	return delegate.acceptableLanguages();
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:5,代码来源:ResteasyFilterContext.java

示例5: preferredLanguage

import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
public LanguageHeader preferredLanguage() {
	return delegate.preferredLanguage();
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:5,代码来源:ResteasyFilterContext.java

示例6: acceptableLanguages

import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
@CacheReturn
public List<LanguageHeader> acceptableLanguages() {
  return context.acceptableLanguages();
}
 
开发者ID:vietj,项目名称:vertx-service-flow,代码行数:6,代码来源:HttpFlowImpl.java

示例7: preferredLanguage

import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
@CacheReturn
public LanguageHeader preferredLanguage() {
  return context.preferredLanguage();
}
 
开发者ID:vietj,项目名称:vertx-service-flow,代码行数:6,代码来源:HttpFlowImpl.java

示例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));
  }
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:44,代码来源:ThymeleafTemplateEngineImpl.java

示例9: acceptLanguage

import io.vertx.ext.web.LanguageHeader; //导入依赖的package包/类
@Override
public List<LanguageHeader> acceptLanguage() {
  return acceptLanguage;
}
 
开发者ID:vert-x3,项目名称:vertx-web,代码行数:5,代码来源:ParsableHeaderValuesContainer.java


注:本文中的io.vertx.ext.web.LanguageHeader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。