javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-2462

Add an ability to specify charset of the properties file while using ResourceBundle

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: resources
    • Labels:
      None

      Description

      Frankly I don't understand why properties use ISO-8859-1 as a default for i18n. I assume this is for historical reasons and must be kept for backward compatibility.

      With that in mind I think you should keep it default but add an ability override it to at least UTF-8.

      Only one thing to change would be to change ResourceBundle.Control#newBundle like that:

      // change from this
      bundle = new PropertyResourceBundle(stream);
      // to this
      bundle = new PropertyResourceBundle(new InputStreamReader(stream, charset));
      

      or something like that. And add a constructor for Control to set the charset property.

      Then one could simply use:

      ResourceBundle.getBundle(bundleName, locale, new Control("UTF-8")).getString(code);
      

      Currently you have to re-implement Control and override newBundle changing just one line with every JSF update...

        Issue Links

          Activity

          Hide
          Ed Burns added a comment -

          The right thing to do here is to interrogate the Resource instance for its charset and the use the reader form of the PropertyResourceBundle() as you suggest.

          Unfortunately, the Resource doesn't have a way to get at its charset.

          How do you propose getting the charset in a robust manner?

          Show
          Ed Burns added a comment - The right thing to do here is to interrogate the Resource instance for its charset and the use the reader form of the PropertyResourceBundle() as you suggest. Unfortunately, the Resource doesn't have a way to get at its charset. How do you propose getting the charset in a robust manner?
          Hide
          Eccenux added a comment -

          I'm not an expert, but above seems the smallest and most backward compatible change.

          Not sure where would you get the charset from (you could check for BOM I guess or use something more sophisticated). None the less I think users should simply be able to set the charset as it is the only sure way (after all you don't have to have BOM in a UTF-8 file so it's kinda tricky). Would be nice to be able to read charset from xml configuration file(s) too, but that's a separate story.

          Show
          Eccenux added a comment - I'm not an expert, but above seems the smallest and most backward compatible change. Not sure where would you get the charset from (you could check for BOM I guess or use something more sophisticated). None the less I think users should simply be able to set the charset as it is the only sure way (after all you don't have to have BOM in a UTF-8 file so it's kinda tricky). Would be nice to be able to read charset from xml configuration file(s) too, but that's a separate story.
          Hide
          Manfred Riem added a comment -

          Unfortunately your suggestion would require everybody to update to UTF-8 which would be a lot to require from everyone. However you have a way out, as the documentation of PropertyResourceBundle (see http://docs.oracle.com/javase/6/docs/api/java/util/PropertyResourceBundle.html) states the following:

          Note: PropertyResourceBundle can be constructed either from an InputStream or a Reader, which represents a property file. Constructing a PropertyResourceBundle instance from an InputStream requires that the input stream be encoded in ISO-8859-1. In that case, characters that cannot be represented in ISO-8859-1 encoding must be represented by Unicode Escapes, whereas the other constructor which takes a Reader does not have that limitation.

          Show
          Manfred Riem added a comment - Unfortunately your suggestion would require everybody to update to UTF-8 which would be a lot to require from everyone. However you have a way out, as the documentation of PropertyResourceBundle (see http://docs.oracle.com/javase/6/docs/api/java/util/PropertyResourceBundle.html ) states the following: Note: PropertyResourceBundle can be constructed either from an InputStream or a Reader, which represents a property file. Constructing a PropertyResourceBundle instance from an InputStream requires that the input stream be encoded in ISO-8859-1. In that case, characters that cannot be represented in ISO-8859-1 encoding must be represented by Unicode Escapes, whereas the other constructor which takes a Reader does not have that limitation.
          Hide
          Manfred Riem added a comment -

          Closing as "Incomplete" here, and filed it as a spec issue #1123

          Show
          Manfred Riem added a comment - Closing as "Incomplete" here, and filed it as a spec issue #1123

            People

            • Assignee:
              Unassigned
              Reporter:
              Eccenux
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: