Examples of LocalizationContext


Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

    Locale locale = context.getViewRoot().getLocale();

    BundleManager bundleManager = BundleManager.create();

    LocalizationContext lc = null;

    if (locale != null)
      lc = bundleManager.getBundle(basename, locale);

    if (lc == null)
      lc = bundleManager.getBundle(basename);

    if (lc == null)
      throw new JspException(L.l("'{0}' is an unknown ResourceBundle basename.",
                                 basename));

    ResourceBundle bundle = lc.getResourceBundle();

    this.pageContext.getRequest().setAttribute(_var, new BundleMap(bundle));
   
    return SKIP_BODY;
  }
View Full Code Here

Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

    PageContext pageContext = (PageContext) params[0];
    String message = null;
    ResourceBundle bundle = null;

    LocalizationContext localizationContext = BundleSupport.getLocalizationContext(pageContext);

    if (localizationContext != null) {
      bundle = localizationContext.getResourceBundle();
    }

    if (bundle != null) {

      if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) {
        message = StringUtils.capitalize(defaultValue);
      } else {
        try {
          message = bundle.getString(messageKey);
        } catch (MissingResourceException e) {
          logger.warn("No message found with the key The message key {} and locale {}.", messageKey,
              localizationContext.getLocale());
          message = UNDEFINED_KEY + messageKey + UNDEFINED_KEY;
        }
      }
    } else {
      logger.warn("The bundle hasn't been retrieved. Please check your i18n configuration.");
View Full Code Here

Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

  public void should_return_error_message_when_the_key_is_undefined() throws UnsupportedEncodingException, IOException{
    // Setup
    InputStream stream = getClass().getClassLoader().getResourceAsStream("com/github/dandelion/datatables/jsp/i18n/datatables_en.properties");
    ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
    pageContext = new MockPageContext();
    pageContext.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".page", new LocalizationContext(bundle, new Locale("en", "US")));
    JstlMessageResolver messageResolver = new JstlMessageResolver(request);

    // Test
    String message = messageResolver.getResource("undefinedKey", "default", pageContext);
    assertThat(message).isEqualTo(MessageResolver.UNDEFINED_KEY + "undefinedKey" + MessageResolver.UNDEFINED_KEY);
View Full Code Here

Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

  public void should_return_blank_when_the_key_is_defined_but_message_is_blank() throws UnsupportedEncodingException, IOException{
    // Setup
    InputStream stream = getClass().getClassLoader().getResourceAsStream("com/github/dandelion/datatables/jsp/i18n/datatables_en.properties");
    ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
    pageContext = new MockPageContext();
    pageContext.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".page", new LocalizationContext(bundle, new Locale("en", "US")));
    JstlMessageResolver messageResolver = new JstlMessageResolver(request);

    // Test
    String message = messageResolver.getResource("global.blank.value", "default", pageContext);
    assertThat(message).isEqualTo("");
View Full Code Here

Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

  public void should_return_the_capitalized_default_message_when_the_key_is_null() throws UnsupportedEncodingException, IOException{
    // Setup
    InputStream stream = getClass().getClassLoader().getResourceAsStream("com/github/dandelion/datatables/jsp/i18n/datatables_en.properties");
    ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
    pageContext = new MockPageContext();
    pageContext.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".page", new LocalizationContext(bundle, new Locale("en", "US")));
    JstlMessageResolver messageResolver = new JstlMessageResolver(request);
   
    // Test
    String message = messageResolver.getResource(null, "default", pageContext);
    assertThat(message).isEqualTo("Default");
View Full Code Here

Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

  public void should_return_the_message_when_the_key_is_present_in_the_bundle() throws UnsupportedEncodingException, IOException{
    // Setup
    InputStream stream = getClass().getClassLoader().getResourceAsStream("com/github/dandelion/datatables/jsp/i18n/datatables_en.properties");
    ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
    pageContext = new MockPageContext();
    pageContext.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".page", new LocalizationContext(bundle, new Locale("en", "US")));
    JstlMessageResolver messageResolver = new JstlMessageResolver(request);

    // Test
    String message = messageResolver.getResource("global.msg.info", "default", pageContext);
    assertThat(message).isEqualTo("My infos");
View Full Code Here

Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

  public void should_return_the_capitalized_default_message_if_the_key_is_null() throws UnsupportedEncodingException, IOException{
    // Setup
    InputStream stream = getClass().getClassLoader().getResourceAsStream("com/github/dandelion/datatables/jsp/i18n/datatables_en.properties");
    ResourceBundle bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8"));
    pageContext = new MockPageContext();
    pageContext.setAttribute(Config.FMT_LOCALIZATION_CONTEXT + ".page", new LocalizationContext(bundle, new Locale("en", "US")));
    JstlMessageResolver messageResolver = new JstlMessageResolver(request);

    // Test
    String message = messageResolver.getResource(null, "default", pageContext);
    assertThat(message).isEqualTo("Default");
View Full Code Here

Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

     * Gets the default I18N localization context.
     *
     * @param pc Page in which to look up the default I18N localization context
     */   
    public static LocalizationContext getLocalizationContext(PageContext pc) {
  LocalizationContext locCtxt = null;

  Object obj = Config.find(pc, Config.FMT_LOCALIZATION_CONTEXT);
  if (obj == null) {
      return null;
  }
View Full Code Here

Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

     * given base name and the locale that led to the resource bundle match,
     * or the empty localization context if no resource bundle match was found
     */
    public static LocalizationContext getLocalizationContext(PageContext pc,
                   String basename) {
  LocalizationContext locCtxt = null;
  ResourceBundle bundle = null;

  if ((basename == null) || basename.equals("")) {
      return new LocalizationContext();
  }

  // Try preferred locales
  Locale pref = SetLocaleSupport.getLocale(pc, Config.FMT_LOCALE);
  if (pref != null) {
      // Preferred locale is application-based
      bundle = findMatch(basename, pref);
      if (bundle != null) {
    locCtxt = new LocalizationContext(bundle, pref);
      }
  } else {
      // Preferred locales are browser-based
      locCtxt = findMatch(pc, basename);
  }
 
  if (locCtxt == null) {
      // No match found with preferred locales, try using fallback locale
      pref = SetLocaleSupport.getLocale(pc, Config.FMT_FALLBACK_LOCALE);
      if (pref != null) {
    bundle = findMatch(basename, pref);
    if (bundle != null) {
        locCtxt = new LocalizationContext(bundle, pref);
    }
      }
  }

  if (locCtxt == null) {
      // try using the root resource bundle with the given basename
      try {
    bundle = ResourceBundle.getBundle(basename, EMPTY_LOCALE,
              Thread.currentThread().getContextClassLoader());
    if (bundle != null) {
        locCtxt = new LocalizationContext(bundle, null);
    }
      } catch (MissingResourceException mre) {
    // do nothing
      }
  }
    
  if (locCtxt != null) {
      // set response locale
      if (locCtxt.getLocale() != null) {
    SetLocaleSupport.setResponseLocale(pc, locCtxt.getLocale());
      }
  } else {
      // create empty localization context
      locCtxt = new LocalizationContext();
  }

  return locCtxt;
    }
View Full Code Here

Examples of javax.servlet.jsp.jstl.fmt.LocalizationContext

    static Locale getFormattingLocale(PageContext pc,
              Tag fromTag,
              boolean format,
              Locale[] avail) {

  LocalizationContext locCtxt = null;
 
  // Get formatting locale from enclosing <fmt:bundle>
  Tag parent = findAncestorWithClass(fromTag, BundleSupport.class);
  if (parent != null) {
      /*
       * use locale from localization context established by parent
       * <fmt:bundle> action, unless that locale is null
       */
      locCtxt = ((BundleSupport) parent).getLocalizationContext();
      if (locCtxt.getLocale() != null) {
    if (format) {
        setResponseLocale(pc, locCtxt.getLocale());
    }
    return locCtxt.getLocale();
      }
  }

  // Use locale from default I18N localization context, unless it is null
  if ((locCtxt = BundleSupport.getLocalizationContext(pc)) != null) {
      if (locCtxt.getLocale() != null) {
    if (format) {
        setResponseLocale(pc, locCtxt.getLocale());
    }
    return locCtxt.getLocale();
      }
  }

  /*
   * Establish formatting locale by comparing the preferred locales
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.