You are viewing a plain text version of this content. The canonical link for it is here.
Posted to doxia-commits@maven.apache.org by vs...@apache.org on 2008/10/25 15:36:51 UTC

svn commit: r707842 - in /maven/doxia/doxia/trunk: doxia-core/src/main/java/org/apache/maven/doxia/parser/ doxia-core/src/main/java/org/apache/maven/doxia/sink/ doxia-core/src/test/java/org/apache/maven/doxia/module/ doxia-modules/doxia-module-xdoc/src...

Author: vsiveton
Date: Sat Oct 25 06:36:50 2008
New Revision: 707842

URL: http://svn.apache.org/viewvc?rev=707842&view=rev
Log:
DOXIA-177: Invalid XHTML because of wrong position of table caption

p patch applied

Modified:
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java
    maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/AbstractIdentityTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocIdentityTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java

Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java?rev=707842&r1=707841&r2=707842&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/parser/XhtmlBaseParser.java Sat Oct 25 06:36:50 2008
@@ -51,9 +51,6 @@
     /** Used for nested lists. */
     private int orderedListDepth = 0;
 
-    /** For tables. */
-    private boolean hasCaption;
-
     /** Counts section level. */
     private int sectionLevel;
 
@@ -370,8 +367,6 @@
         }
         else if ( parser.getName().equals( Tag.CAPTION.toString() ) )
         {
-            sink.tableRows_();
-            this.hasCaption = true;
             sink.tableCaption( attribs );
         }
 
@@ -548,12 +543,7 @@
 
         else if ( parser.getName().equals( Tag.TABLE.toString() ) )
         {
-            if ( !hasCaption )
-            {
-                sink.tableRows_();
-            }
-
-            this.hasCaption = false;
+            sink.tableRows_();
 
             sink.table_();
         }

Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java?rev=707842&r1=707841&r2=707842&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java Sat Oct 25 06:36:50 2008
@@ -20,6 +20,7 @@
  */
 
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.io.Writer;
 
 import javax.swing.text.MutableAttributeSet;
@@ -29,6 +30,7 @@
 import org.apache.maven.doxia.markup.HtmlMarkup;
 import org.apache.maven.doxia.util.DoxiaUtils;
 import org.apache.maven.doxia.util.HtmlTools;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Abstract base xhtml sink implementation.
@@ -82,6 +84,9 @@
     /** Indicates that an image is part of a figure. */
     private boolean inFigure;
 
+    /** The StringWriter to write the table content (DOXIA-177). */
+    private StringWriter tableWriter;
+
     // ----------------------------------------------------------------------
     // Constructor
     // ----------------------------------------------------------------------
@@ -989,6 +994,8 @@
     /** {@inheritDoc} */
     public void table( SinkEventAttributes attributes )
     {
+        tableWriter = new StringWriter();
+
         // start table with tableRows
         if ( attributes == null )
         {
@@ -1008,6 +1015,38 @@
     public void table_()
     {
         writeEndTag( Tag.TABLE );
+
+        if ( tableWriter == null )
+        {
+            throw new IllegalArgumentException( "table( SinkEventAttributes attributes ) was not called before." );
+        }
+
+        String content = tableWriter.toString();
+        tableWriter = null;
+
+        String startCaption = "<" + Tag.CAPTION.toString() + ">";
+        String endCaption = "</" + Tag.CAPTION.toString() + ">";
+
+        if ( content.indexOf( startCaption ) == -1 && content.indexOf( endCaption ) == -1 )
+        {
+            write( content );
+        }
+        else
+        {
+            // DOXIA-177
+            int iStartCaption = content.indexOf( startCaption );
+            int iEndCaption = content.indexOf( endCaption ) + endCaption.length();
+
+            String captionTag = content.substring( iStartCaption, iEndCaption );
+            content = StringUtils.replace( content, captionTag, "" );
+
+            StringBuffer text = new StringBuffer();
+            text.append( content.substring( 0, content.indexOf( "<" + Tag.TR.toString() ) ) );
+            text.append( captionTag );
+            text.append( content.substring( content.indexOf( "<" + Tag.TR.toString() ) ) );
+
+            write( text.toString() );
+        }
     }
 
     /**
@@ -1709,7 +1748,14 @@
     /** {@inheritDoc} */
     protected void write( String text )
     {
-        writer.write( unifyEOLs( text ) );
+        if ( tableWriter == null )
+        {
+            writer.write( unifyEOLs( text ) );
+        }
+        else
+        {
+            tableWriter.write( unifyEOLs( text ) );
+        }
     }
 
 }

Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/AbstractIdentityTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/AbstractIdentityTest.java?rev=707842&r1=707841&r2=707842&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/AbstractIdentityTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/module/AbstractIdentityTest.java Sat Oct 25 06:36:50 2008
@@ -46,6 +46,9 @@
 public abstract class AbstractIdentityTest
     extends AbstractModuleTest
 {
+    /** Expected Identity String */
+    private String expected;
+
     /**
      * Set to true if the identity transformation should actually be asserted,
      * by default only the expected and actual results are written to a file, but not compared.
@@ -93,7 +96,7 @@
             // generate the expected model
             writer = new StringWriter();
             SinkTestDocument.generate( new TextSink( writer ) );
-            String expected = writer.toString();
+            expected = writer.toString();
 
             // write to file for comparison
             fileWriter = getTestWriter( "expected" );
@@ -121,7 +124,7 @@
             if ( assertIdentity )
             {
                 // TODO: make this work for at least apt and xdoc modules?
-                assertEquals( "Identity test failed!", expected, actual );
+                assertEquals( "Identity test failed!", getExpected(), actual );
             }
 
         }
@@ -163,4 +166,12 @@
     {
         this.assertIdentity = doAssert;
     }
+
+    /**
+     * @return the expected identity string
+     */
+    protected String getExpected()
+    {
+        return expected;
+    }
 }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocIdentityTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocIdentityTest.java?rev=707842&r1=707841&r2=707842&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocIdentityTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocIdentityTest.java Sat Oct 25 06:36:50 2008
@@ -24,6 +24,7 @@
 import org.apache.maven.doxia.module.AbstractIdentityTest;
 import org.apache.maven.doxia.parser.Parser;
 import org.apache.maven.doxia.sink.Sink;
+import org.codehaus.plexus.util.StringUtils;
 
 
 /**
@@ -50,4 +51,32 @@
     {
         return new XdocParser();
     }
+
+    /** {@inheritDoc} */
+    protected String getExpected()
+    {
+        // DOXIA-177
+        String expected = super.getExpected();
+
+        String startCaption = "begin:tableCaption";
+        String endCaption = "end:tableCaption";
+
+        int iStartCaption = expected.indexOf( startCaption );
+        int iEndCaption = expected.indexOf( endCaption ) + endCaption.length();
+
+        String captionTag = expected.substring( iStartCaption, iEndCaption ) + EOL + EOL + EOL;
+        expected = StringUtils.replace( expected, captionTag, "" );
+
+        int iStartTableRows =
+            expected.substring( 0, iStartCaption ).lastIndexOf( "begin:tableRows" ) + "begin:tableRows".length();
+
+        StringBuffer text = new StringBuffer();
+        text.append( expected.substring( 0, iStartTableRows ) );
+        text.append( EOL + EOL + EOL );
+        text.append( captionTag.subSequence( 0, captionTag.indexOf( "end:tableCaption" )
+            + "end:tableCaption".length() ) );
+        text.append( expected.substring( iStartTableRows ) );
+
+        return text.toString();
+    }
 }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java?rev=707842&r1=707841&r2=707842&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java Sat Oct 25 06:36:50 2008
@@ -138,8 +138,8 @@
     /** {@inheritDoc} */
     protected String getTableBlock( String cell, String caption )
     {
-        return "<table align=\"center\" border=\"0\"><tr valign=\"top\"><td align=\"center\">"
-            + cell + "</td></tr><caption>" + caption + "</caption></table>";
+        return "<table align=\"center\" border=\"0\"><caption>" + caption + "</caption><tr valign=\"top\"><td align=\"center\">"
+            + cell + "</td></tr></table>";
     }
 
     /** {@inheritDoc} */

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java?rev=707842&r1=707841&r2=707842&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlIdentityTest.java Sat Oct 25 06:36:50 2008
@@ -24,6 +24,7 @@
 import org.apache.maven.doxia.module.AbstractIdentityTest;
 import org.apache.maven.doxia.parser.Parser;
 import org.apache.maven.doxia.sink.Sink;
+import org.codehaus.plexus.util.StringUtils;
 
 
 /**
@@ -51,4 +52,31 @@
         return new XhtmlParser();
     }
 
+    /** {@inheritDoc} */
+    protected String getExpected()
+    {
+        // DOXIA-177
+        String expected = super.getExpected();
+
+        String startCaption = "begin:tableCaption";
+        String endCaption = "end:tableCaption";
+
+        int iStartCaption = expected.indexOf( startCaption );
+        int iEndCaption = expected.indexOf( endCaption ) + endCaption.length();
+
+        String captionTag = expected.substring( iStartCaption, iEndCaption ) + EOL + EOL + EOL;
+        expected = StringUtils.replace( expected, captionTag, "" );
+
+        int iStartTableRows =
+            expected.substring( 0, iStartCaption ).lastIndexOf( "begin:tableRows" ) + "begin:tableRows".length();
+
+        StringBuffer text = new StringBuffer();
+        text.append( expected.substring( 0, iStartTableRows ) );
+        text.append( EOL + EOL + EOL );
+        text.append( captionTag.subSequence( 0, captionTag.indexOf( "end:tableCaption" )
+            + "end:tableCaption".length() ) );
+        text.append( expected.substring( iStartTableRows ) );
+
+        return text.toString();
+    }
 }

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java?rev=707842&r1=707841&r2=707842&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlSinkTest.java Sat Oct 25 06:36:50 2008
@@ -155,8 +155,8 @@
     protected String getTableBlock( String cell, String caption )
     {
         return "<table border=\"0\" class=\"bodyTable\" align=\"center\">"
-            + "<tr class=\"a\"><td align=\"center\">cell</td></tr>"
-            + "<caption>Table caption</caption></table>";
+            + "<caption>Table caption</caption><tr class=\"a\"><td align=\"center\">cell</td></tr>"
+            + "</table>";
     }
 
     // Disable testTable until the order of attributes issue is clarified