Package org.apache.tapestry.util.text

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


    /**
     * 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(logger, CURRENCY_EXTRA_PREFIX, search, context.getResourcesOracle());
      if (newExtra != null) {
        currencyExtra = newExtra;
      }
      Map<String, String> currencyData =
View Full Code Here


   * not-used-flag=1 Trailing empty fields can be omitted
   */
  @SuppressWarnings("unchecked")
  private Map<String, String> getCurrencyData(TreeLogger logger, GwtLocale locale,
      ResourceOracle resourceOracle) {
    LocalizedProperties currencyData =
        getProperties(logger, CURRENCY_DATA_PREFIX, locale, resourceOracle);
    if (currencyData == null) {
      return Collections.emptyMap();
    }
    return currencyData.getPropertyMap();
  }
View Full Code Here

   * Returns the default currency code for the requested locale.
   */
  private String getDefaultCurrency(TreeLogger logger, GwtLocale locale,
      ResourceOracle resourceOracle) {
    String defCurrencyCode = null;
    LocalizedProperties numberConstants =
        getProperties(logger, NUMBER_CONSTANTS_PREFIX, locale, resourceOracle);
    if (numberConstants != null) {
      defCurrencyCode = numberConstants.getProperty("defCurrencyCode");
    }
    if (defCurrencyCode == null && locale.isDefault()) {
      defCurrencyCode = "USD";
    }
    return defCurrencyCode;
View Full Code Here

    if (!locale.isDefault()) {
      propFile += "_" + locale.getAsString();
    }
    propFile += ".properties";
    InputStream str = null;
    LocalizedProperties props = new LocalizedProperties();
    try {
      str = ResourceLocatorImpl.tryFindResourceAsStream(logger, resourceOracle, 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

  private Map<String, MultipleFormEntry> entries;

  @SuppressWarnings("unchecked")
  public LocalizedPropertiesResource(InputStream m, GwtLocale locale) {
    super(locale);
    LocalizedProperties props = new LocalizedProperties();
    try {
      props.load(m, Util.DEFAULT_ENCODING);
    } catch (IOException e) {
      throw new RuntimeException("Failed to load " + this.getPath(), e);
    }
    entries = new HashMap<String, MultipleFormEntry>();
    for (Object propEntryObj : props.getPropertyMap().entrySet()) {
      Map.Entry<String, String> propEntry = (Entry<String, String>) propEntryObj;
      String key = propEntry.getKey().trim();
      String value = propEntry.getValue();
      int startBracket = key.indexOf('[');
      int endBracket = key.indexOf(']', startBracket + 1);
View Full Code Here

      writer.println("private native void ensureNativeDisplayNames() /*-{");
      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 (String propval : localeValues) {
        String displayName = displayNamesOverride.getProperty(propval);
        if (displayName == null) {
          displayName = displayNamesManual.getProperty(propval);
        }
        if (displayName == null) {
          displayName = displayNames.getProperty(propval);
View Full Code Here

      factory.addImport(CURRENCY_LIST);
      factory.addImport(CURRENCY_DATA);
      SourceWriter writer = factory.createSourceWriter(context, pw);
     
      // Load property files for this locale, handling inheritance properly.
      LocalizedProperties currencyData = readProperties(logger, CURRENCY_DATA_PREFIX, locale);
      LocalizedProperties currencyExtra = readProperties(logger, CURRENCY_EXTRA_PREFIX, locale);
      LocalizedProperties numberConstants = readProperties(logger, NUMBER_CONSTANTS_PREFIX, locale);
     
      // Get default currency code, set defaults in case it isn't found.
      String defCurrencyCode = numberConstants.getProperty("defCurrencyCode");
      if (defCurrencyCode == null) {
        defCurrencyCode = "USD";
      }
     
      // Sort for deterministic output.
View Full Code Here

   * @return a LocalizedProperties object containing all properties
   * @throws UnableToCompleteException if an error occurs reading the file
   */
  private LocalizedProperties readProperties(TreeLogger logger, String propFilePrefix,
      String locale) throws UnableToCompleteException {
    LocalizedProperties props = new LocalizedProperties();
    ClassLoader classLoader = getClass().getClassLoader();
    readProperties(logger, classLoader, propFilePrefix, props);
    if (locale.equals("default")) {
      return props;
    }
View Full Code Here

        GwtLocale locale = factory.fromString(suffix).getCanonicalForm();
        File f = new File(propDir, propFile);
        FileInputStream str = null;
        try {
          str = new FileInputStream(f);
          LocalizedProperties props = new LocalizedProperties();
          props.load(str);
          Map<String, String> map = props.getPropertyMap();
          for (Map.Entry<String, String> entry : map.entrySet()) {
            String[] value = split(entry.getValue());
            if ("dateFormats".equals(entry.getKey()) || "timeFormats".equals(entry.getKey())
                || "weekendRange".equals(entry.getKey())) {
              // split these out into separate fields
View Full Code Here

  protected abstract String javaDocComment(String path);

  @SuppressWarnings("unchecked") // use of raw type from LocalizedProperties
  void generateFromPropertiesFile() throws IOException {
    InputStream propStream = new FileInputStream(resourceFile);
    LocalizedProperties p = new LocalizedProperties();
    p.load(propStream, Util.DEFAULT_ENCODING);
    addFormatters();
    // TODO: Look for a generic version of Tapestry's LocalizedProperties class
    Set<String> keySet = p.getPropertyMap().keySet();
    // sort keys for deterministic results
    String[] keys = keySet.toArray(new String[keySet.size()]);
    Arrays.sort(keys);
    if (keys.length == 0) {
      throw new IllegalStateException(
          "File '"
              + resourceFile
              + "' cannot be used to generate message classes, as it has no key/value pairs defined.");
    }
    for (String key : keys) {
      String value = p.getProperty(key);
      genSimpleMethodDecl(key, value);
    }
    composer.commit(new PrintWriterTreeLogger());
  }
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.