Esempio n. 1
0
  /**
   * This code is currently common to all {@link ViewHandlingStrategy} instances.
   *
   * @see ViewHandler#calculateLocale(javax.faces.context.FacesContext)
   */
  public Locale calculateLocale(FacesContext context) {

    Util.notNull("context", context);

    Locale result = null;
    // determine the locales that are acceptable to the client based on the
    // Accept-Language header and the find the best match among the
    // supported locales specified by the client.
    Iterator<Locale> locales = context.getExternalContext().getRequestLocales();
    while (locales.hasNext()) {
      Locale perf = locales.next();
      result = findMatch(context, perf);
      if (result != null) {
        break;
      }
    }
    // no match is found.
    if (result == null) {
      if (context.getApplication().getDefaultLocale() == null) {
        result = Locale.getDefault();
      } else {
        result = context.getApplication().getDefaultLocale();
      }
    }
    return result;
  }
Esempio n. 2
0
  private void doSetBindings(ELContext elContext, UIComponent component) {
    if (component == null) return;

    ValueExpression binding = component.getValueExpression("binding");

    if (binding != null) binding.setValue(elContext, component);

    Iterator<UIComponent> iter = component.getFacetsAndChildren();
    while (iter.hasNext()) doSetBindings(elContext, iter.next());
  }
  private static String getSingleBehaviorEventName(Map<String, List<ClientBehavior>> behaviors) {
    assert (behaviors != null);

    int size = behaviors.size();
    if (size == 0) {
      return null;
    }

    assert (size == 1);

    Iterator<String> keys = behaviors.keySet().iterator();
    assert (keys.hasNext());

    return keys.next();
  }
Esempio n. 4
0
  /**
   * Attempts to find a matching locale based on <code>pref</code> and list of supported locales,
   * using the matching algorithm as described in JSTL 8.3.2.
   *
   * @param context the <code>FacesContext</code> for the current request
   * @param pref the preferred locale
   * @return the Locale based on pref and the matching alogritm specified in JSTL 8.3.2
   */
  protected Locale findMatch(FacesContext context, Locale pref) {

    Locale result = null;
    Iterator<Locale> it = context.getApplication().getSupportedLocales();
    while (it.hasNext()) {
      Locale supportedLocale = it.next();

      if (pref.equals(supportedLocale)) {
        // exact match
        result = supportedLocale;
        break;
      } else {
        // Make sure the preferred locale doesn't have country
        // set, when doing a language match, For ex., if the
        // preferred locale is "en-US", if one of supported
        // locales is "en-UK", even though its language matches
        // that of the preferred locale, we must ignore it.
        if (pref.getLanguage().equals(supportedLocale.getLanguage())
            && supportedLocale.getCountry().length() == 0) {
          result = supportedLocale;
        }
      }
    }
    // if it's not in the supported locales,
    if (null == result) {
      Locale defaultLocale = context.getApplication().getDefaultLocale();
      if (defaultLocale != null) {
        if (pref.equals(defaultLocale)) {
          // exact match
          result = defaultLocale;
        } else {
          // Make sure the preferred locale doesn't have country
          // set, when doing a language match, For ex., if the
          // preferred locale is "en-US", if one of supported
          // locales is "en-UK", even though its language matches
          // that of the preferred locale, we must ignore it.
          if (pref.getLanguage().equals(defaultLocale.getLanguage())
              && defaultLocale.getCountry().length() == 0) {
            result = defaultLocale;
          }
        }
      }
    }

    return result;
  }
Esempio n. 5
0
  private void logMessages(FacesContext context) {
    UIViewRoot root = context.getViewRoot();
    String viewId = "";

    if (root != null) viewId = root.getViewId();

    Iterator<FacesMessage> iter = context.getMessages();

    while (iter != null && iter.hasNext()) {
      FacesMessage msg = iter.next();

      if (log.isLoggable(Level.FINE)) {
        if (msg.getDetail() != null)
          log.fine(
              viewId + " [ " + msg.getSeverity() + "] " + msg.getSummary() + " " + msg.getDetail());
        else log.fine(viewId + " [ " + msg.getSeverity() + "] " + msg.getSummary());
      }
    }
  }