Package org.apache.wicket

Examples of org.apache.wicket.Localizer$ClassMetaDatabase


        super(id, model, metaData, viewOnly);
       
        type = metaData.getPropertyType();
        boolean displayTz = false;
        Component metaDataComponent = metaData.getBeanMetaData().getComponent();
        Localizer localizer = metaDataComponent.getLocalizer();
        if (Time.class.isAssignableFrom(type) ||
            java.sql.Date.class.isAssignableFrom(type) ||
            Date.class.isAssignableFrom(type) ||
            Timestamp.class.isAssignableFrom(type)) {
            fmt = localizer.getString(DATE_TIME_FIELD_PREFIX + "date" + FORMAT_SUFFIX, metaDataComponent, DATE_FMT_STR);
        }
        else if (Calendar.class.isAssignableFrom(type)) {
            fmt = viewOnly ? localizer.getString(DATE_TIME_FIELD_PREFIX + "datetz" + FORMAT_SUFFIX, metaDataComponent, DATE_ZONE_FMT_STR) :
                             localizer.getString(DATE_TIME_FIELD_PREFIX + "date" + FORMAT_SUFFIX, metaDataComponent, DATE_FMT_STR);
            displayTz = true;
        }
        else {
            throw new RuntimeException("YUIDateField does not handle " + type);
        }
View Full Code Here


        super(id, model, metaData, viewOnly);
       
        type = metaData.getPropertyType();
        boolean displayTz = false;
        Component metaDataComponent = metaData.getBeanMetaData().getComponent();
        Localizer localizer = metaDataComponent.getLocalizer();
        if (Time.class.isAssignableFrom(type)) {
            fmt = localizer.getString(DATE_TIME_FIELD_PREFIX + "time" + FORMAT_SUFFIX, metaDataComponent, TIME_FMT_STR);
        }
        else if (java.sql.Date.class.isAssignableFrom(type)) {
            fmt = localizer.getString(DATE_TIME_FIELD_PREFIX + "date" + FORMAT_SUFFIX, metaDataComponent, DATE_FMT_STR);
        }
        else if (Calendar.class.isAssignableFrom(type)) {
            fmt = viewOnly ? localizer.getString(DATE_TIME_FIELD_PREFIX + "datetimetz" + FORMAT_SUFFIX, metaDataComponent, DATE_TIME_ZONE_FMT_STR) :
                             localizer.getString(DATE_TIME_FIELD_PREFIX + "datetime" + FORMAT_SUFFIX, metaDataComponent, DATE_TIME_FMT_STR);
            displayTz = true;
        }
        else { // if (Date.class.isAssignableFrom(type) || Timestamp.class.isAssignableFrom(type))
            fmt = localizer.getString(DATE_TIME_FIELD_PREFIX + "datetime" + FORMAT_SUFFIX, metaDataComponent, DATE_TIME_FMT_STR);
        }
       
        String customFmt = getFormat();
        if (customFmt != null) {
            fmt = customFmt;
View Full Code Here

     * @return a String with the macros expanded. If a macro key cannot be found in
     *  localizer, the macro is substituted with "?string?".
     */
    public static String substituteMacros(String string, Component component)
    {
        Localizer localizer = component.getLocalizer();
        StringBuilder buf = new StringBuilder(string);
        int idx = 0;
        while ((idx = buf.indexOf("${", idx)) >= 0) {
            int endIdx = buf.indexOf("}", idx + 2);
            if (endIdx > 0) {
                String key = buf.substring(idx + 2, endIdx);
                String value = localizer.getString(key, component, '?' + key + '?');
                if (value != null) {
                    buf.replace(idx, endIdx + 1, value);
                }
                else {
                    // Nothing found, skip macro.
View Full Code Here

  }

  private String getString(final Component component)
  {

    final Localizer localizer = getLocalizer();

    String value;

    // Substitute any parameters if necessary
    Object[] parameters = getParameters();
    if (parameters == null || parameters.length == 0)
    {
      // Get the string resource, doing any property substitutions as part
      // of the get operation
      String defaultVal = defaultValue != null ? defaultValue.getObject() : null;
      value = localizer.getString(getResourceKey(), component, model, defaultVal);
      if (value == null)
      {
        value = defaultVal;
      }
    }
    else
    {
      // Get the string resource, doing not any property substitutions
      // that has to be done later after MessageFormat
      String defaultVal = defaultValue != null ? defaultValue.getObject() : null;
      value = localizer.getString(getResourceKey(), component, null, defaultVal);
      if (value == null)
      {
        value = defaultVal;
      }
      if (value != null)
      {
        // Build the real parameters
        Object[] realParams = new Object[parameters.length];
        for (int i = 0; i < parameters.length; i++)
        {
          if (parameters[i] instanceof IModel<?>)
          {
            realParams[i] = ((IModel<?>)parameters[i]).getObject();
          }
          else if (model != null && parameters[i] instanceof String)
          {
            realParams[i] = localizer.substitutePropertyExpressions(component,
              (String)parameters[i], model);
          }
          else
          {
            realParams[i] = parameters[i];
          }
        }

        // Escape all single quotes outside {..}
        if (value.indexOf('\'') != -1)
        {
          value = escapeQuotes(value);
        }

        if (model != null)
        {
          // First escape all substitute properties so that message format doesn't try to
          // parse that.
          value = Strings.replaceAll(value, "${", "$'{'").toString();
        }

        // Apply the parameters
        final MessageFormat format = new MessageFormat(value, getLocale());
        value = format.format(realParams);

        if (model != null)
        {
          // un escape the substitute properties
          value = Strings.replaceAll(value, "$'{'", "${").toString();
          // now substitute the properties
          value = localizer.substitutePropertyExpressions(component, value, model);
        }
      }
    }

    // Return the string resource
View Full Code Here

  public Localizer getLocalizer()
  {
    if (localizer == null)
    {
      localizer = new Localizer();
    }
    return localizer;
  }
View Full Code Here

      // Use the following log4j config for detailed logging on the property resolution
      // process
      // log4j.logger.org.apache.wicket.resource.loader=DEBUG
      // log4j.logger.org.apache.wicket.Localizer=DEBUG

      final Localizer localizer = formComponent.getLocalizer();

      // retrieve prefix that will be used to construct message keys
      String prefix = formComponent.getValidatorKeyPrefix();
      String message = null;
View Full Code Here

  @Override
  public Localizer getLocalizer()
  {
    if (localizer == null)
    {
      localizer = new Localizer();
    }
    return localizer;
  }
View Full Code Here

  }

  private String getString(final Component component)
  {

    final Localizer localizer = getLocalizer();

    String value;

    // Substitute any parameters if necessary
    Object[] parameters = getParameters();
    if (parameters == null || parameters.length == 0)
    {
      // Get the string resource, doing any property substitutions as part
      // of the get operation
      value = localizer.getString(getResourceKey(), component, model, defaultValue);
      if (value == null)
      {
        value = defaultValue;
      }
    }
    else
    {
      // Get the string resource, doing not any property substitutions
      // that has to be done later after MessageFormat
      value = localizer.getString(getResourceKey(), component, null, defaultValue);
      if (value == null)
      {
        value = defaultValue;
      }
      if (value != null)
      {
        // Build the real parameters
        Object[] realParams = new Object[parameters.length];
        for (int i = 0; i < parameters.length; i++)
        {
          if (parameters[i] instanceof IModel<?>)
          {
            realParams[i] = ((IModel<?>)parameters[i]).getObject();
          }
          else if (model != null && parameters[i] instanceof String)
          {
            realParams[i] = localizer.substitutePropertyExpressions(component,
              (String)parameters[i], model);
          }
          else
          {
            realParams[i] = parameters[i];
          }
        }

        // Escape all single quotes outside {..}
        if (value.indexOf('\'') != -1)
        {
          value = escapeQuotes(value);
        }

        if (model != null)
        {
          // First escape all substitute properties so that message format doesn't try to
          // parse that.
          value = Strings.replaceAll(value, "${", "$'{'").toString();
        }

        // Apply the parameters
        final MessageFormat format = new MessageFormat(value, getLocale());
        value = format.format(realParams);

        if (model != null)
        {
          // un escape the substitute properties
          value = Strings.replaceAll(value, "$'{'", "${").toString();
          // now substitute the properties
          value = localizer.substitutePropertyExpressions(component, value, model);
        }
      }
    }

    // Return the string resource
View Full Code Here

      // Use the following log4j config for detailed logging on the property resolution
      // process
      // log4j.logger.org.apache.wicket.resource.loader=DEBUG
      // log4j.logger.org.apache.wicket.Localizer=DEBUG

      final Localizer localizer = formComponent.getLocalizer();

      // retrieve prefix that will be used to construct message keys
      String prefix = formComponent.getValidatorKeyPrefix();
      String message = null;
View Full Code Here

      // Use the following log4j config for detailed logging on the property resolution
      // process
      // log4j.logger.org.apache.wicket.resource.loader=DEBUG
      // log4j.logger.org.apache.wicket.Localizer=DEBUG

      final Localizer localizer = formComponent.getLocalizer();

      // retrieve prefix that will be used to construct message keys
      String prefix = formComponent.getValidatorKeyPrefix();
      String message = null;
View Full Code Here

TOP

Related Classes of org.apache.wicket.Localizer$ClassMetaDatabase

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.