Package javax.servlet.jsp.jstl.fmt

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


    //*********************************************************************
    // Tag logic

    public int doEndTag() throws JspException {
  LocalizationContext locCtxt =
      BundleSupport.getLocalizationContext(pageContext, basename);

  if (var != null) {
      pageContext.setAttribute(var, locCtxt, scope);
  } else {
View Full Code Here


    }

    public int doEndTag() throws JspException {

        String key = null;
  LocalizationContext locCtxt = null;

        // determine the message key by...
        if (keySpecified) {
      // ... reading 'key' attribute
      key = keyAttrValue;
  } else {
      // ... retrieving and trimming our body
      if (bodyContent != null && bodyContent.getString() != null)
          key = bodyContent.getString().trim();
  }

  if ((key == null) || key.equals("")) {
      try {
    pageContext.getOut().print("??????");
      } catch (IOException ioe) {
    throw new JspTagException(ioe.toString(), ioe);
      }
      return EVAL_PAGE;
  }

  String prefix = null;
  if (!bundleSpecified) {
      Tag t = findAncestorWithClass(this, BundleSupport.class);
      if (t != null) {
    // use resource bundle from parent <bundle> tag
    BundleSupport parent = (BundleSupport) t;
    locCtxt = parent.getLocalizationContext();
    prefix = parent.getPrefix();
      } else {
    locCtxt = BundleSupport.getLocalizationContext(pageContext);
      }
  } else {
      // localization context taken from 'bundle' attribute
      locCtxt = bundleAttrValue;
      if (locCtxt.getLocale() != null) {
    SetLocaleSupport.setResponseLocale(pageContext,
               locCtxt.getLocale());
      }
  }
       
   String message = UNDEFINED_KEY + key + UNDEFINED_KEY;
  if (locCtxt != null) {
      ResourceBundle bundle = locCtxt.getResourceBundle();
      if (bundle != null) {
    try {
        // prepend 'prefix' attribute from parent bundle
        if (prefix != null)
      key = prefix + key;
        message = bundle.getString(key);
        // Perform parametric replacement if required
        if (!params.isEmpty()) {
      Object[] messageArgs = params.toArray();
      MessageFormat formatter = new MessageFormat(""); // empty pattern, default Locale
      if (locCtxt.getLocale() != null) {
          formatter.setLocale(locCtxt.getLocale());
      } else {
                            // For consistency with the <fmt:formatXXX> actions,
                            // we try to get a locale that matches the user's preferences
                            // as well as the locales supported by 'date' and 'number'.
                            //System.out.println("LOCALE-LESS LOCCTXT: GETTING FORMATTING LOCALE");
View Full Code Here

     * 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

     * 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

     * the given base name and best matching locale, or <tt>null</tt> if no
     * resource bundle match was found
     */
    private static LocalizationContext findMatch(PageContext pageContext,
             String basename) {
  LocalizationContext locCtxt = null;
 
  // Determine locale from client's browser settings.
       
  for (Enumeration enum_ = Util.getRequestLocales((HttpServletRequest)pageContext.getRequest());
       enum_.hasMoreElements(); ) {
      Locale pref = (Locale) enum_.nextElement();
      ResourceBundle match = findMatch(basename, pref);
      if (match != null) {
    locCtxt = new LocalizationContext(match, pref);
    break;
      }
  }
         
  return locCtxt;
View Full Code Here

    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

    //*********************************************************************
    // Tag logic

    public int doEndTag() throws JspException {
  LocalizationContext locCtxt =
      BundleSupport.getLocalizationContext(pageContext, basename);

  if (var != null) {
      pageContext.setAttribute(var, locCtxt, scope);
  } else {
View Full Code Here

  public void setUp() {
  MockitoAnnotations.initMocks(this);
  RequestInfo webRequest = new RequestInfo(servletContext, null, request, null);
  localization = new JstlLocalization(webRequest);

  LocalizationContext context = new LocalizationContext(bundle);
  when(request.getAttribute(FMT_LOCALIZATION_CONTEXT + ".request")).thenReturn(context);

  when(request.getSession()).thenReturn(session);
  }
View Full Code Here

    }

    public int doEndTag() throws JspException {

        String key = null;
  LocalizationContext locCtxt = null;

        // determine the message key by...
        if (keySpecified) {
      // ... reading 'key' attribute
      key = keyAttrValue;
  } else {
      // ... retrieving and trimming our body
      if (bodyContent != null && bodyContent.getString() != null)
          key = bodyContent.getString().trim();
  }

  if ((key == null) || key.equals("")) {
      try {
    pageContext.getOut().print("??????");
      } catch (IOException ioe) {
    throw new JspTagException(ioe.getMessage());
      }
      return EVAL_PAGE;
  }

  String prefix = null;
  if (!bundleSpecified) {
      Tag t = findAncestorWithClass(this, BundleSupport.class);
      if (t != null) {
    // use resource bundle from parent <bundle> tag
    BundleSupport parent = (BundleSupport) t;
    locCtxt = parent.getLocalizationContext();
    prefix = parent.getPrefix();
      } else {
    locCtxt = BundleSupport.getLocalizationContext(pageContext);
      }
  } else {
      // localization context taken from 'bundle' attribute
      locCtxt = bundleAttrValue;
      if (locCtxt.getLocale() != null) {
    SetLocaleSupport.setResponseLocale(pageContext,
               locCtxt.getLocale());
      }
  }

  String message = UNDEFINED_KEY + key + UNDEFINED_KEY;
  if (locCtxt != null) {
      ResourceBundle bundle = locCtxt.getResourceBundle();
      if (bundle != null) {
    try {
        // prepend 'prefix' attribute from parent bundle
        if (prefix != null)
      key = prefix + key;
        message = bundle.getString(key);
        // Perform parametric replacement if required
        if (!params.isEmpty()) {
      Object[] messageArgs = params.toArray();
      MessageFormat formatter = new MessageFormat("");
      if (locCtxt.getLocale() != null) {
          formatter.setLocale(locCtxt.getLocale());
      }
      formatter.applyPattern(message);
      message = formatter.format(messageArgs);
        }
    } catch (MissingResourceException mre) {
View Full Code Here

     * 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

TOP

Related Classes of javax.servlet.jsp.jstl.fmt.LocalizationContext

Copyright © 2018 www.massapicom. 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.