Package org.apache.tapestry.util.text

Examples of org.apache.tapestry.util.text.LocalizedProperties


   * @param locale
   * @return currency data map
   */
  @SuppressWarnings("unchecked")
  private Map<String, String> getCurrencyData(GwtLocale locale) {
    LocalizedProperties currencyData = getProperties(CURRENCY_DATA_PREFIX,
        locale);
    if (currencyData == null) {
      return Collections.emptyMap();
    }
    return currencyData.getPropertyMap();
  }
View Full Code Here


   * @param locale
   * @return ISO4217 currency code
   */
  private String getDefaultCurrency(GwtLocale locale) {
    String defCurrencyCode = null;
    LocalizedProperties numberConstants = getProperties(
        NUMBER_CONSTANTS_PREFIX, locale);
    if (numberConstants != null) {
      defCurrencyCode = numberConstants.getProperty("defCurrencyCode");
    }
    if (defCurrencyCode == null && locale.isDefault()) {
      defCurrencyCode = "USD";
    }
    return defCurrencyCode;
View Full Code Here

      propFile += "_" + locale.getAsString();
    }
    propFile += ".properties";
    InputStream str = null;
    ClassLoader classLoader = getClass().getClassLoader();
    LocalizedProperties props = new LocalizedProperties();
    try {
      str = classLoader.getResourceAsStream(propFile);
      if (str != null) {
        props.load(str, "UTF-8");
        return props;
      }
    } catch (UnsupportedEncodingException e) {
      // UTF-8 should always be defined
      return null;
View Full Code Here

      writer.println("  if (this.@" + qualName
          + "::nativeDisplayNames != null) {");
      writer.println("    return;");
      writer.println("  }");
      writer.println("  this.@" + qualName + "::nativeDisplayNames = {");
      LocalizedProperties displayNames = new LocalizedProperties();
      LocalizedProperties displayNamesManual = new LocalizedProperties();
      LocalizedProperties displayNamesOverride = new LocalizedProperties();
      ClassLoader classLoader = getClass().getClassLoader();
      try {
        InputStream str = classLoader.getResourceAsStream(GENERATED_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNames.load(str, "UTF-8");
        }
        str = classLoader.getResourceAsStream(MANUAL_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNamesManual.load(str, "UTF-8");
        }
        str = classLoader.getResourceAsStream(OVERRIDE_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNamesOverride.load(str, "UTF-8");
        }
      } catch (UnsupportedEncodingException e) {
        // UTF-8 should always be defined
        logger.log(TreeLogger.ERROR, "UTF-8 encoding is not defined", e);
        throw new UnableToCompleteException();
      } catch (IOException e) {
        logger.log(TreeLogger.ERROR, "Exception reading locale display names",
            e);
        throw new UnableToCompleteException();
      }
      boolean needComma = false;
      for (GwtLocaleImpl possibleLocale : allLocales) {
        String localeName = possibleLocale.toString();
        String displayName = displayNamesOverride.getProperty(localeName);
        if (displayName == null) {
          displayName = displayNamesManual.getProperty(localeName);
        }
        if (displayName == null) {
          displayName = displayNames.getProperty(localeName);
View Full Code Here

        new GwtLocaleImpl[localeSet.size()]);
    // sort for deterministic output
    Arrays.sort(allLocales);
    PrintWriter pw = context.tryCreate(logger, packageName, superClassName);
    if (pw != null) {
      LocalizedProperties displayNames = new LocalizedProperties();
      LocalizedProperties displayNamesManual = new LocalizedProperties();
      LocalizedProperties displayNamesOverride = new LocalizedProperties();
      ClassLoader classLoader = getClass().getClassLoader();
      try {
        InputStream str = classLoader.getResourceAsStream(GENERATED_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNames.load(str, "UTF-8");
        }
        str = classLoader.getResourceAsStream(MANUAL_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNamesManual.load(str, "UTF-8");
        }
        str = classLoader.getResourceAsStream(OVERRIDE_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNamesOverride.load(str, "UTF-8");
        }
      } catch (UnsupportedEncodingException e) {
        // UTF-8 should always be defined
        logger.log(TreeLogger.ERROR, "UTF-8 encoding is not defined", e);
        throw new UnableToCompleteException();
      } catch (IOException e) {
        logger.log(TreeLogger.ERROR, "Exception reading locale display names",
            e);
        throw new UnableToCompleteException();
      }

      ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(
          packageName, superClassName);
      factory.setSuperclass(targetClass.getQualifiedSourceName());
      factory.addImport(GWT.class.getCanonicalName());
      factory.addImport(JavaScriptObject.class.getCanonicalName());
      factory.addImport(HashMap.class.getCanonicalName());
      SourceWriter writer = factory.createSourceWriter(context, pw);
      writer.println("private static native String getLocaleNativeDisplayName(");
      writer.println("    JavaScriptObject nativeDisplayNamesNative,String localeName) /*-{");
      writer.println("  return nativeDisplayNamesNative[localeName];");
      writer.println("}-*/;");
      writer.println();
      writer.println("HashMap<String,String> nativeDisplayNamesJava;");
      writer.println("private JavaScriptObject nativeDisplayNamesNative;");
      writer.println();
      writer.println("@Override");
      writer.println("public String[] getAvailableLocaleNames() {");
      writer.println("  return new String[] {");
      boolean hasAnyRtl = false;
      for (GwtLocaleImpl possibleLocale : allLocales) {
        writer.println("    \""
            + possibleLocale.toString().replaceAll("\"", "\\\"") + "\",");
        if (RTL_LOCALES.contains(
            possibleLocale.getCanonicalForm().getLanguage())) {
          hasAnyRtl = true;
        }
      }
      writer.println("  };");
      writer.println("}");
      writer.println();
      writer.println("@Override");
      writer.println("public String getLocaleNativeDisplayName(String localeName) {");
      writer.println("  if (GWT.isScript()) {");
      writer.println("    if (nativeDisplayNamesNative == null) {");
      writer.println("      nativeDisplayNamesNative = loadNativeDisplayNamesNative();");
      writer.println("    }");
      writer.println("    return getLocaleNativeDisplayName(nativeDisplayNamesNative, localeName);");
      writer.println("  } else {");
      writer.println("    if (nativeDisplayNamesJava == null) {");
      writer.println("      nativeDisplayNamesJava = new HashMap<String, String>();");
      {
        for (GwtLocaleImpl possibleLocale : allLocales) {
          String localeName = possibleLocale.toString();
          String displayName = displayNamesOverride.getProperty(localeName);
          if (displayName == null) {
            displayName = displayNamesManual.getProperty(localeName);
          }
          if (displayName == null) {
            displayName = displayNames.getProperty(localeName);
          }
          if (displayName != null && displayName.length() != 0) {
            localeName = quoteQuotes(localeName);
            displayName = quoteQuotes(displayName);
            writer.println("      nativeDisplayNamesJava.put(\"" + localeName + "\", \"" + displayName + "\");");
          }
        }
      }

      writer.println("    }");
      writer.println("    return nativeDisplayNamesJava.get(localeName);");
      writer.println("  }");
      writer.println("}");
      writer.println();
      writer.println("@Override");
      writer.println("public boolean hasAnyRTL() {");
      writer.println("  return " + hasAnyRtl + ";");
      writer.println("}");
      writer.println();
      writer.println("private native JavaScriptObject loadNativeDisplayNamesNative() /*-{");
      writer.println("  return {");
      {
        boolean needComma = false;
        for (GwtLocaleImpl possibleLocale : allLocales) {
          String localeName = possibleLocale.toString();
          String displayName = displayNamesOverride.getProperty(localeName);
          if (displayName == null) {
            displayName = displayNamesManual.getProperty(localeName);
          }
          if (displayName == null) {
            displayName = displayNames.getProperty(localeName);
View Full Code Here

        new GwtLocaleImpl[localeSet.size()]);
    // sort for deterministic output
    Arrays.sort(allLocales);
    PrintWriter pw = context.tryCreate(logger, packageName, superClassName);
    if (pw != null) {
      LocalizedProperties displayNames = new LocalizedProperties();
      LocalizedProperties displayNamesManual = new LocalizedProperties();
      LocalizedProperties displayNamesOverride = new LocalizedProperties();
      ClassLoader classLoader = getClass().getClassLoader();
      try {
        InputStream str = classLoader.getResourceAsStream(GENERATED_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNames.load(str, "UTF-8");
        }
        str = classLoader.getResourceAsStream(MANUAL_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNamesManual.load(str, "UTF-8");
        }
        str = classLoader.getResourceAsStream(OVERRIDE_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNamesOverride.load(str, "UTF-8");
        }
      } catch (UnsupportedEncodingException e) {
        // UTF-8 should always be defined
        logger.log(TreeLogger.ERROR, "UTF-8 encoding is not defined", e);
        throw new UnableToCompleteException();
      } catch (IOException e) {
        logger.log(TreeLogger.ERROR, "Exception reading locale display names",
            e);
        throw new UnableToCompleteException();
      }

      ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(
          packageName, superClassName);
      factory.setSuperclass(targetClass.getQualifiedSourceName());
      factory.addImport(GWT.class.getCanonicalName());
      factory.addImport(JavaScriptObject.class.getCanonicalName());
      factory.addImport(HashMap.class.getCanonicalName());
      SourceWriter writer = factory.createSourceWriter(context, pw);
      writer.println("private static native String getLocaleNativeDisplayName(");
      writer.println("    JavaScriptObject nativeDisplayNamesNative,String localeName) /*-{");
      writer.println("  return nativeDisplayNamesNative[localeName];");
      writer.println("}-*/;");
      writer.println();
      writer.println("HashMap<String,String> nativeDisplayNamesJava;");
      writer.println("private JavaScriptObject nativeDisplayNamesNative;");
      writer.println();
      writer.println("@Override");
      writer.println("public String[] getAvailableLocaleNames() {");
      writer.println("  return new String[] {");
      boolean hasAnyRtl = false;
      for (GwtLocaleImpl possibleLocale : allLocales) {
        writer.println("    \""
            + possibleLocale.toString().replaceAll("\"", "\\\"") + "\",");
        if (RTL_LOCALES.contains(
            possibleLocale.getCanonicalForm().getLanguage())) {
          hasAnyRtl = true;
        }
      }
      writer.println("  };");
      writer.println("}");
      writer.println();
      writer.println("@Override");
      writer.println("public String getLocaleNativeDisplayName(String localeName) {");
      writer.println("  if (GWT.isScript()) {");
      writer.println("    if (nativeDisplayNamesNative == null) {");
      writer.println("      nativeDisplayNamesNative = loadNativeDisplayNamesNative();");
      writer.println("    }");
      writer.println("    return getLocaleNativeDisplayName(nativeDisplayNamesNative, localeName);");
      writer.println("  } else {");
      writer.println("    if (nativeDisplayNamesJava == null) {");
      writer.println("      nativeDisplayNamesJava = new HashMap<String, String>();");
      {
        for (GwtLocaleImpl possibleLocale : allLocales) {
          String localeName = possibleLocale.toString();
          String displayName = displayNamesOverride.getProperty(localeName);
          if (displayName == null) {
            displayName = displayNamesManual.getProperty(localeName);
          }
          if (displayName == null) {
            displayName = displayNames.getProperty(localeName);
          }
          if (displayName != null && displayName.length() != 0) {
            writer.println("      nativeDisplayNamesJava.put("
                + CodeGenUtils.asStringLiteral(localeName) + ", "
                + CodeGenUtils.asStringLiteral(displayName) + ");");
          }
        }
      }

      writer.println("    }");
      writer.println("    return nativeDisplayNamesJava.get(localeName);");
      writer.println("  }");
      writer.println("}");
      writer.println();
      writer.println("@Override");
      writer.println("public boolean hasAnyRTL() {");
      writer.println("  return " + hasAnyRtl + ";");
      writer.println("}");
      writer.println();
      writer.println("private native JavaScriptObject loadNativeDisplayNamesNative() /*-{");
      writer.println("  return {");
      {
        boolean needComma = false;
        for (GwtLocaleImpl possibleLocale : allLocales) {
          String localeName = possibleLocale.toString();
          String displayName = displayNamesOverride.getProperty(localeName);
          if (displayName == null) {
            displayName = displayNamesManual.getProperty(localeName);
          }
          if (displayName == null) {
            displayName = displayNames.getProperty(localeName);
View Full Code Here

    /**
     * Map of currency code -> CurrencyInfo for that code.
     */
    Map<String, CurrencyInfo> allCurrencyData = new HashMap<String, CurrencyInfo>();

    LocalizedProperties currencyExtra = null;
    /*
     * The searchList is guaranteed to be ordered such that subclasses always
     * precede superclasses. Therefore, we iterate backwards to ensure that
     * superclasses are always generated first.
     */
    String lastDefaultCurrencyCode = null;
    for (int i = searchList.size(); i-- > 0;) {
      GwtLocale search = searchList.get(i);
      LocalizedProperties newExtra = getProperties(CURRENCY_EXTRA_PREFIX,
          search);
      if (newExtra != null) {
        currencyExtra = newExtra;
      }
      Map<String, String> currencyData = getCurrencyData(search);
View Full Code Here

   * @param locale
   * @return currency data map
   */
  @SuppressWarnings("unchecked")
  private Map<String, String> getCurrencyData(GwtLocale locale) {
    LocalizedProperties currencyData = getProperties(CURRENCY_DATA_PREFIX,
        locale);
    if (currencyData == null) {
      return Collections.emptyMap();
    }
    return currencyData.getPropertyMap();
  }
View Full Code Here

   * @param locale
   * @return ISO4217 currency code
   */
  private String getDefaultCurrency(GwtLocale locale) {
    String defCurrencyCode = null;
    LocalizedProperties numberConstants = getProperties(NUMBER_CONSTANTS_PREFIX, locale);
    if (numberConstants != null) {
      defCurrencyCode = numberConstants.getProperty("defCurrencyCode");
    }
    if (defCurrencyCode == null && locale.isDefault()) {
      defCurrencyCode = "USD";
    }
    return defCurrencyCode;
View Full Code Here

      propFile += "_" + locale.getAsString();
    }
    propFile += ".properties";
    InputStream str = null;
    ClassLoader classLoader = getClass().getClassLoader();
    LocalizedProperties props = new LocalizedProperties();
    try {
      str = classLoader.getResourceAsStream(propFile);
      if (str != null) {
        props.load(str, "UTF-8");
        return props;
      }
    } catch (UnsupportedEncodingException e) {
      // UTF-8 should always be defined
      return null;
View Full Code Here

TOP

Related Classes of org.apache.tapestry.util.text.LocalizedProperties

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.