當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。