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 2009/08/18 23:40:36 UTC

svn commit: r805591 - in /maven/doxia/doxia/trunk: doxia-core/src/main/java/org/apache/maven/doxia/sink/ doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/ doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/mo...

Author: vsiveton
Date: Tue Aug 18 21:40:36 2009
New Revision: 805591

URL: http://svn.apache.org/viewvc?rev=805591&view=rev
Log:
DOXIA-360: Unable to specify table cell/row alignment

o fixed in XhtmlBaseSink, XdocSink and FoSink

Modified:
    maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/sink/XhtmlBaseSink.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java

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=805591&r1=805590&r2=805591&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 Tue Aug 18 21:40:36 2009
@@ -90,7 +90,7 @@
     private boolean evenTableRow = true;
 
     /** used to store attributes passed to table(). */
-    private MutableAttributeSet tableAttributes;
+    protected MutableAttributeSet tableAttributes;
 
     /** Used to distinguish old-style figure handling. */
     private boolean legacyFigure;
@@ -114,7 +114,7 @@
      * sink.tableRow();
      * </pre>
      * */
-    private boolean tableRows = false;
+    protected boolean tableRows = false;
 
     /** Map of warn messages with a String as key to describe the error type and a Set as value.
      * Using to reduce warn messages. */
@@ -1173,8 +1173,7 @@
     {
         this.tableRows = true;
 
-        this.cellJustif = justification;
-        this.isCellJustif = true;
+        setCellJustif( justification );
 
         if ( this.tableAttributes == null )
         {
@@ -1321,30 +1320,37 @@
      */
     private void tableCell( boolean headerRow, MutableAttributeSet attributes )
     {
+        Tag t = ( headerRow ? HtmlMarkup.TH : HtmlMarkup.TD );
+
+        MutableAttributeSet att = new SinkEventAttributeSet();
+
         String justif = null;
+        if ( attributes == null )
+        {
+            attributes = new SinkEventAttributeSet( 0 );
+        }
 
-        if ( cellJustif != null && isCellJustif )
+        if ( attributes.isDefined( Attribute.ALIGN.toString() ) )
+        {
+            justif = attributes.getAttribute( Attribute.ALIGN.toString() ).toString();
+        }
+
+        if ( justif == null && cellJustif != null && cellJustif.length > 0 && isCellJustif )
         {
             switch ( cellJustif[Math.min( cellCount, cellJustif.length - 1 )] )
             {
-                case Sink.JUSTIFY_LEFT:
+                case JUSTIFY_LEFT:
                     justif = "left";
                     break;
-                case Sink.JUSTIFY_RIGHT:
+                case JUSTIFY_RIGHT:
                     justif = "right";
                     break;
-                case Sink.JUSTIFY_CENTER:
+                case JUSTIFY_CENTER:
                 default:
                     justif = "center";
-                    break;
             }
         }
 
-
-        Tag t = ( headerRow ? HtmlMarkup.TH : HtmlMarkup.TD );
-
-        MutableAttributeSet att = new SinkEventAttributeSet();
-
         if ( justif != null )
         {
             att.addAttribute( Attribute.ALIGN, justif );

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java?rev=805591&r1=805590&r2=805591&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/main/java/org/apache/maven/doxia/module/fo/FoSink.java Tue Aug 18 21:40:36 2009
@@ -959,10 +959,7 @@
 
         if ( tableCaption != null )
         {
-            SinkEventAttributeSet atts = new SinkEventAttributeSet();
-            atts.addAttribute( SinkEventAttributes.ALIGN, "center" );
-
-            paragraph( atts );
+            paragraph( SinkEventAttributeSet.CENTER );
             write( tableCaption );
             paragraph_();
         }
@@ -1011,7 +1008,7 @@
     /** {@inheritDoc} */
     public void tableCell( SinkEventAttributes attributes )
     {
-        tableCell( false );
+        tableCell( false, attributes );
     }
 
     /** {@inheritDoc} */
@@ -1024,13 +1021,13 @@
     public void tableCell( String width )
     {
         // TODO: fop can't handle cell width
-        tableCell( false );
+        tableCell();
     }
 
     /** {@inheritDoc} */
     public void tableHeaderCell( SinkEventAttributes attributes )
     {
-        tableCell( true );
+        tableCell( true, attributes );
     }
 
     /** {@inheritDoc} */
@@ -1043,35 +1040,17 @@
     public void tableHeaderCell( String width )
     {
         // TODO: fop can't handle cell width
-        tableCell( true );
+        tableHeaderCell();
     }
 
     /**
      * Writes a table cell.
      *
      * @param headerRow true if this is a header cell.
+     * @param attributes the cell attributes, could be null.
      */
-    private void tableCell( boolean headerRow )
+    private void tableCell( boolean headerRow, SinkEventAttributes attributes )
     {
-         String justif = null;
-
-         if ( cellJustif != null && isCellJustif )
-         {
-             switch ( cellJustif[Math.min( cellCount, cellJustif.length - 1 )] )
-             {
-                 case JUSTIFY_LEFT:
-                     justif = "left";
-                     break;
-                 case JUSTIFY_RIGHT:
-                     justif = "right";
-                     break;
-                 case JUSTIFY_CENTER:
-                 default:
-                     justif = "center";
-                     break;
-             }
-         }
-
         MutableAttributeSet cellAtts = headerRow
                  ? config.getAttributeSet( "table.heading.cell" )
                  : config.getAttributeSet( "table.body.cell" );
@@ -1088,9 +1067,36 @@
                  ? config.getAttributeSet( "table.heading.block" )
                  : config.getAttributeSet( "table.body.block" );
 
+        String justif = null;
+        if ( attributes == null )
+        {
+            attributes = new SinkEventAttributeSet( 0 );
+        }
+
+        if ( attributes.isDefined( Attribute.ALIGN.toString() ) )
+        {
+            justif = attributes.getAttribute( Attribute.ALIGN.toString() ).toString();
+        }
+
+        if ( justif == null && cellJustif != null && cellJustif.length > 0 && isCellJustif )
+        {
+            switch ( cellJustif[Math.min( cellCount, cellJustif.length - 1 )] )
+            {
+                case JUSTIFY_LEFT:
+                    justif = "left";
+                    break;
+                case JUSTIFY_RIGHT:
+                    justif = "right";
+                    break;
+                case JUSTIFY_CENTER:
+                default:
+                    justif = "center";
+            }
+        }
+
         if ( justif != null )
         {
-           blockAtts.addAttribute( "text-align", justif );
+            blockAtts.addAttribute( "text-align", justif );
         }
 
         writeStartTag( TABLE_CELL_TAG, cellAtts );

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java?rev=805591&r1=805590&r2=805591&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-fo/src/test/java/org/apache/maven/doxia/module/fo/FoSinkTest.java Tue Aug 18 21:40:36 2009
@@ -21,7 +21,6 @@
 
 import java.io.File;
 import java.io.StringReader;
-import java.io.StringWriter;
 import java.io.Writer;
 
 import org.apache.maven.doxia.document.DocumentMeta;

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java?rev=805591&r1=805590&r2=805591&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java (original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java Tue Aug 18 21:40:36 2009
@@ -445,11 +445,32 @@
      */
     public void tableRows( int[] justification, boolean grid )
     {
+        // similar to super.tableRows( justification, grid ) but without class.
+
+        this.tableRows = true;
+
         setCellJustif( justification );
 
+        if ( this.tableAttributes == null )
+        {
+            this.tableAttributes = new SinkEventAttributeSet( 0 );
+        }
+
         MutableAttributeSet att = new SinkEventAttributeSet();
-        att.addAttribute( Attribute.ALIGN, "center" );
-        att.addAttribute( Attribute.BORDER, ( grid ? "1" : "0" ) );
+
+        if ( !tableAttributes.isDefined( Attribute.ALIGN.toString() ) )
+        {
+            att.addAttribute( Attribute.ALIGN, "center" );
+        }
+
+        if ( !tableAttributes.isDefined( Attribute.BORDER.toString() ) )
+        {
+            att.addAttribute( Attribute.BORDER, ( grid ? "1" : "0" ) );
+        }
+
+        att.addAttributes( tableAttributes );
+
+        tableAttributes.removeAttributes( tableAttributes );
 
         writeStartTag( TABLE, att );
     }