Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4306753

JEditorPane cannot display non ISO-8859-1 characters in HTML with frames

    XMLWordPrintable

Details

    • rc2
    • generic
    • generic
    • Verified

    Backports

      Description



        Name: clC74495 Date: 01/24/2000


        JDK1.3 PreFCS build-S. <<<<--- where's the -fullversion string?

        main cause:
          JEditorPane initializes JEditorPane#charSetName with Fixed Value "8859_1".


        If HTTP server add charset parameter to the MIME header, JEditorPane
        recognizes the charset.

        In the case that HTTP server does not specify the charset, if the document has a
        META tag like <META HTTP-EQUIV="Content-Type" CONTENT="text/html;
        charset=Shift_JIS">, JEditorPane recognizes charset.

        But most of HTTP server does not add charset to the MIME header.
        And most of HTML documents does not have this META tag.

        So JEditorPane#JEditorPane(URL) and JEditorPane#setPage(URL) are not
        useful for most of cases.

        All we can use is JEditorPane#setContentType(String).
        But we cannot use the method for the case of displaying non ISO-8859-1
        characters in HTML with frames.

        javax.swing.text.FrameView creates JEditorPane instance for child frame
        with the constructor JEditorPane#JEditorPane(URL), so if there is no
        information of charset, JEditorPane#charSetName is initialized with
        "8859_1".

        And we can't call JEditorPane#setContentType() for this JEditorPane
        instance before the call of JEditorPane#read(), so child frame document
        is always treated as ISO-8859-1, and we can't read NOTHING.

        In other words, JEditorPane cannot display most of non ISO-8859-1
        characters in HTML with frames.

        This is a severe problem!! We can't change the behavior of all HTTP
        server in the world. We can't add META tag to all HTML documents in
        the world. So we have no workaround.

        The Local documents(ex. file:///C:/Documents/foo.html)&#39; case is same
        as Web documents. There is no way to tell the charset to the
        JEditorPane for child frame, too.

        The main cause of this case is that JEditorPane initializes
        JEditorPane#charSetName with Fixed Value "8859_1".

        We have found the simple way to fix this case;

        - Add system property for default charset name. (ex. user.defaultcharset)
           (file.encoding is not useful for this case)
        - Add some lines to JEditorPane.java. (after line 1290)
           1290:private String charSetName = "8859_1";
                {
                  try {
                    String value = System.getProperty("user.defaultcharset");
                    if (value != null) {
                      charSetName = value;
                    }
                  } catch (SecurityException e) {
                  }
                }
                  
        These simple changes fix all problems above, and this way has some
        advantages;

        - No need new APIs.
        - No effect on other objects, APIs.
        - Easy to make browser which has change-charset menu with JEditorPane.
           (Like Netscape's [View]-[Character Set] menu)

        If you want to display non ISO-8859-1 characters in HTML with frames,
        you just set "user.defaultcharset", and create JEditorPane for parent
        frame like below.

           private JEditorPane pane = new JEditorPane();
           
           System.setProperty("user.defaultcharset","Shift_JIS");
           pane.setPage(url);
        (Review ID: 100212)
        ======================================================================

        Attachments

          Issue Links

            Activity

              People

                tprinzing Tim Prinzing
                clucasius Carlos Lucasius (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: