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

Uppercase class attribute in HTML (JTextPane / JEditorPane) are ignored

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • None
    • 6u3
    • client-libs

      If the CSS style class names are in uppercase then it will be ignored. The follow test program show with Java 5 a blue and a red string. In Java 6 there is a black and red string because the BLUE attribute is in uppercase. If you request the HTML with getText() then you see that Java 5 has convert all class names to lowercase. In Java 6 there are only the definition in lowercase. I think this is the cause because the attribute are not found.

       
      To reproduce:
      1. Compile & run the code below in 1.5 & 1.6 and observe the difference in "blue" color attribute.
       

      ---------------- Code Begins ---------------------
      import javax.swing.*;

      import javax.swing.text.Document;

      import javax.swing.text.EditorKit;

      import javax.swing.text.StyledEditorKit;

      import javax.swing.text.html.HTMLDocument;

       

      public class UpperCaseClass {

       

          public static void main( String[] args ){

              JFrame frame = new JFrame();

              frame.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );

             

              JTextPane text = new JTextPane();

             

              frame.add( text );

             

              String anyText = "<html>" +

                               "<head>" +

                                   "<style type='text/css'><!--" +

                                       "SPAN.BLUE { color: #0000FF }" +

                                       "SPAN.red { color: #FF0000 }" +

                                   "--></style>" +

                               "</head><body>" +

                               "<SPAN class=BLUE>blue</SPAN> <SPAN class=red>red</SPAN>" +

                               "</body></html>";

       

              text.setContentType( "text/html" );

              Document doc = text.getDocument();

              doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);

              text.setText( anyText );

              System.out.println( text.getText() );

             

              frame.pack();

              frame.show();

          }

      }

      ---------------- Source Ends ---------------------

       

      Output with 1.6.0

      ===============

      <html>

        <head>

          <style type="text/css">

            <!--

              span.red { color: #FF0000 }

              span.blue { color: #0000FF }

            -->

          </style>

         

        </head>

        <body>

          <span class="BLUE">blue</span> <span class="red">red</span>

        </body>

      </html>

       

       

      Output with 1.5.0

      ==================

      <html>

        <head>

          <style type="text/css">

            <!--

              span.red { color: #FF0000 }

              span.blue { color: #0000FF }

            -->

          </style>

             

        </head>

        <body>

          <span class="blue">blue</span> <span class="red">red</span>

        </body>

      </html>

            peterz Peter Zhelezniakov
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: