harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r564566 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/html/ main/java/common/javax/swing/text/html/parser/ test/api/java.injected/javax/swing/text/html/
Date Fri, 10 Aug 2007 11:50:24 GMT
Author: apetrenko
Date: Fri Aug 10 04:50:23 2007
New Revision: 564566

URL: http://svn.apache.org/viewvc?view=rev&rev=564566
Log:
Patch for HARMONY-4582 "[classlib][swing] JEditorPane does not support <pre> tag in
text/html mode"

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTMLDocument.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Lexer.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_ActionsTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTMLDocument.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTMLDocument.java?view=diff&rev=564566&r1=564565&r2=564566
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTMLDocument.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTMLDocument.java
Fri Aug 10 04:50:23 2007
@@ -690,8 +690,22 @@
             }
         }
 
-        protected void preContent(final char[] data) {
-            addContent(data, 0, data.length);
+        protected void preContent(char[] data) {
+            int offset = 0;
+
+            for (int i = 0; i < data.length; i++) {
+                if ((data[i] == '\n') || (data[i] == '\r')) {
+                    addContent(data, offset, i - offset);
+                    blockClose(HTML.Tag.IMPLIED);
+
+                    blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
+                    offset = i + 1;
+                }
+            }
+
+            if (offset < data.length) {
+                addContent(data, offset, data.length - offset);
+            }
         }
 
         protected void addContent(final char[] data, final int offset,

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Lexer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Lexer.java?view=diff&rev=564566&r1=564565&r2=564566
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Lexer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/parser/Lexer.java
Fri Aug 10 04:50:23 2007
@@ -544,17 +544,8 @@
 						buffer.append(yytext());
 					break;
 					case LINE_TERMINATOR:
-						if (terminatorSkipped) {
-							buffer.append(yytext());
-						}  
-						/* 
-						* Collapses if there is only one last line terminator. 
-						* If there are more then doesn't do it (same as RI)
-						* FIXME 
-						*/
-						skipLastLineTerminator = !lastWasLineTerminator;
-						lastWasLineTerminator = true;
-						terminatorSkipped = true;
+					    buffer.append(yytext());
+					    terminatorSkipped = false;
 					break;
 					case TEXT:
 						buffer.append(yytext());

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_ActionsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_ActionsTest.java?view=diff&rev=564566&r1=564565&r2=564566
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_ActionsTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_ActionsTest.java
Fri Aug 10 04:50:23 2007
@@ -20,10 +20,12 @@
 */
 package javax.swing.text.html;
 
+import java.io.StringReader;
 import java.net.URL;
 import java.util.ArrayList;
 
 import javax.swing.text.AttributeSet;
+import javax.swing.text.Element;
 import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.Style;
@@ -543,9 +545,8 @@
         assertEquals(2, reader.parseBuffer.size());
         reader.handleText(text.toCharArray(), 0);
         
-        assertEquals(3, reader.parseBuffer.size());
-        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
-        assertEquals(text.length(), spec.getLength());
+        assertEquals(7, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(6);
         assertEquals(text.length(), spec.getArray().length);
     }
     
@@ -559,10 +560,26 @@
         assertEquals(2, reader.parseBuffer.size());
         reader.preContent(text.toCharArray());
         
-        assertEquals(3, reader.parseBuffer.size());
-        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
-        assertEquals(text.length(), spec.getLength());
+        assertEquals(7, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(6);
         assertEquals(text.length(), spec.getArray().length);
+    }
+    
+    public void testHarmony_4582() throws Exception {
+        final Element pre;
+        final HTMLDocument doc = new HTMLDocument();
+
+        new HTMLEditorKit().read(new StringReader("<html><body><pre>line1\n"
//$NON-NLS-1$
+                + "line2</pre></body></html>"), doc, 0); //$NON-NLS-1$
+
+        assertEquals("line1", doc.getText(1, 5)); //$NON-NLS-1$
+        assertEquals("line2", doc.getText(7, 5)); //$NON-NLS-1$
+
+        pre = doc.getRootElements()[0].getElement(1).getElement(0);
+        assertEquals(1, pre.getElement(0).getStartOffset());
+        assertEquals(7, pre.getElement(0).getEndOffset());
+        assertEquals(7, pre.getElement(1).getStartOffset());
+        assertEquals(13, pre.getElement(1).getEndOffset());
     }
     
     public void testTag_ContentWhitespaces() {



Mime
View raw message