Package org.apache.tapestry.util.text

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


      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


    {
        if (resourceURL == null) return parent;

        Properties result = new Properties(parent);

        LocalizedProperties wrapper = new LocalizedProperties(result);

        InputStream input = null;

        try
        {
            input = new BufferedInputStream(resourceURL.openStream());

            if (encoding == null)
                wrapper.load(input);
            else wrapper.load(input, encoding);

            input.close();
        }
        catch (IOException ex)
        {
View Full Code Here

        if (resourceURL == null)
            return parent;

        Properties result = new Properties(parent);

        LocalizedProperties wrapper = new LocalizedProperties(result);

        InputStream input = null;

        try
        {
            input = new BufferedInputStream(resourceURL.openStream());

            if (encoding == null)
                wrapper.load(input);
            else
                wrapper.load(input, encoding);

            input.close();
        }
        catch (IOException ex)
        {
View Full Code Here

            standardException = e;
        }

        InputStream localizedIns = getClass().getResourceAsStream(fileName2);
        Properties localized = new Properties();
        LocalizedProperties localizedProperties = new LocalizedProperties(localized);
        Exception localizedException = null;
        try
        {
            localizedProperties.load(localizedIns, encoding);
        }
        catch (Exception e)
        {
            localizedException = e;
        }
View Full Code Here

        if (resourceURL == null)
            return parent;

        Properties result = new Properties(parent);

        LocalizedProperties wrapper = new LocalizedProperties(result);

        InputStream input = null;

        try
        {
            input = new BufferedInputStream(resourceURL.openStream());

            if (encoding == null)
                wrapper.load(input);
            else
                wrapper.load(input, encoding);

            input.close();
        }
        catch (IOException ex)
        {
View Full Code Here

            standardException = e;
        }

        InputStream localizedIns = getClass().getResourceAsStream(fileName2);
        Properties localized = new Properties();
        LocalizedProperties localizedProperties = new LocalizedProperties(localized);
        Exception localizedException = null;
        try
        {
            localizedProperties.load(localizedIns, encoding);
        }
        catch (Exception e)
        {
            localizedException = e;
        }
View Full Code Here

  }

  private LocalizedProperties props;

  public LocalizedPropertiesResource(InputStream m) {
    props = new LocalizedProperties();
    try {
      props.load(m, Util.DEFAULT_ENCODING);
    } catch (IOException e) {
      throw new RuntimeException("Failed to load " + this.getPath(), e);
    }
View Full Code Here

        __CLOVER_305_0.S[14035]++;if ((((parent == null) && (++__CLOVER_305_0.CT[2349] != 0)) || (++__CLOVER_305_0.CF[2349] == 0))){
            __CLOVER_305_0.S[14036]++;result = new Properties();}
        else{
            __CLOVER_305_0.S[14037]++;result = new Properties(parent);}

        __CLOVER_305_0.S[14038]++;LocalizedProperties localizedResult = new LocalizedProperties(result);
        __CLOVER_305_0.S[14039]++;String encoding = getMessagesEncoding(component, locale);

        __CLOVER_305_0.S[14040]++;try
        {
            __CLOVER_305_0.S[14041]++;InputStream input = propertiesURL.openStream();

            __CLOVER_305_0.S[14042]++;if ((((encoding == null) && (++__CLOVER_305_0.CT[2350] != 0)) || (++__CLOVER_305_0.CF[2350] == 0))){
                __CLOVER_305_0.S[14043]++;localizedResult.load(input);}
            else{
                __CLOVER_305_0.S[14044]++;localizedResult.load(input, encoding);}

            __CLOVER_305_0.S[14045]++;input.close();
        }
        catch (IOException ex)
        {
View Full Code Here

        __CLOVER_305_0.S[7097]++;if ((((parent == null) && (++__CLOVER_305_0.CT[1237] != 0)) || (++__CLOVER_305_0.CF[1237] == 0))){
            __CLOVER_305_0.S[7098]++;result = new Properties();}
        else{
            __CLOVER_305_0.S[7099]++;result = new Properties(parent);}

        __CLOVER_305_0.S[7100]++;LocalizedProperties localizedResult = new LocalizedProperties(result);
        __CLOVER_305_0.S[7101]++;String encoding = getMessagesEncoding(component, locale);

        __CLOVER_305_0.S[7102]++;try
        {
            __CLOVER_305_0.S[7103]++;InputStream input = propertiesURL.openStream();

            __CLOVER_305_0.S[7104]++;if ((((encoding == null) && (++__CLOVER_305_0.CT[1238] != 0)) || (++__CLOVER_305_0.CF[1238] == 0))){
                __CLOVER_305_0.S[7105]++;localizedResult.load(input);}
            else{
                __CLOVER_305_0.S[7106]++;localizedResult.load(input, encoding);}

            __CLOVER_305_0.S[7107]++;input.close();
        }
        catch (IOException ex)
        {
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();
      try {
        InputStream str = ResourceLocatorImpl.tryFindResourceAsStream(logger,
            context.getResourcesOracle(), GENERATED_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNames.load(str, "UTF-8");
        }
        str = ResourceLocatorImpl.tryFindResourceAsStream(logger, context.getResourcesOracle(),
            MANUAL_LOCALE_NATIVE_DISPLAY_NAMES);
        if (str != null) {
          displayNamesManual.load(str, "UTF-8");
        }
        str = ResourceLocatorImpl.tryFindResourceAsStream(logger, context.getResourcesOracle(),
            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

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.