This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch DOXIA-670
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git

commit c5efed4a05e93c5dcef82c4a3e14261f69555a21
Author: Michael Osipov <micha...@apache.org>
AuthorDate: Thu Aug 4 22:08:24 2022 +0200

    [DOXIA-670] Remove code duplication in XdocSink
---
 .../apache/maven/doxia/module/xdoc/XdocSink.java   | 37 ++--------------------
 .../maven/doxia/module/xdoc/XdocSinkTest.java      | 13 +++++---
 2 files changed, 11 insertions(+), 39 deletions(-)

diff --git 
a/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
 
b/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
index de012612..eafba081 100644
--- 
a/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
+++ 
b/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java
@@ -396,7 +396,6 @@ public class XdocSink
         MutableAttributeSet atts = SinkUtils.filterAttributes(
                 attributes, SinkUtils.SINK_VERBATIM_ATTRIBUTES  );
 
-
         if ( atts == null )
         {
             atts = new SinkEventAttributeSet();
@@ -406,10 +405,10 @@ public class XdocSink
 
         if ( atts.isDefined( SinkEventAttributes.DECORATION ) )
         {
-            boxed = "boxed".equals( atts.getAttribute( 
SinkEventAttributes.DECORATION ) );
+             boxedFlag = boxed =
+                "boxed".equals( atts.getAttribute( 
SinkEventAttributes.DECORATION ) );
         }
 
-        boxedFlag = boxed;
         atts.removeAttribute( SinkEventAttributes.DECORATION );
 
         if ( boxed )
@@ -418,7 +417,6 @@ public class XdocSink
         }
         else
         {
-            atts.removeAttribute( Attribute.ALIGN.toString() );
             writeStartTag( PRE, atts );
         }
     }
@@ -459,11 +457,6 @@ public class XdocSink
 
         setCellJustif( justification );
 
-        if ( this.tableAttributes == null )
-        {
-            this.tableAttributes = new SinkEventAttributeSet( 0 );
-        }
-
         MutableAttributeSet att = new SinkEventAttributeSet();
 
         if ( !tableAttributes.isDefined( Attribute.BORDER.toString() ) )
@@ -488,7 +481,6 @@ public class XdocSink
     public void tableRow()
     {
         MutableAttributeSet att = new SinkEventAttributeSet();
-        att.addAttribute( Attribute.VALIGN, "top" );
 
         writeStartTag( TR, att );
 
@@ -505,31 +497,6 @@ public class XdocSink
         init();
     }
 
-    /**
-     * Adds a link with an optional target.
-     *
-     * @param name the link name.
-     * @param target the link target, may be null.
-     */
-    public void link( String name, String target )
-    {
-        if ( isHeadFlag() )
-        {
-            return;
-        }
-
-        MutableAttributeSet att = new SinkEventAttributeSet();
-
-        att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) );
-
-        if ( target != null )
-        {
-            att.addAttribute( Attribute.TARGET, target );
-        }
-
-        writeStartTag( A, att );
-    }
-
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
diff --git 
a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
 
b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
index 3e8613f8..c439e7f2 100644
--- 
a/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
+++ 
b/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java
@@ -20,6 +20,7 @@ package org.apache.maven.doxia.module.xdoc;
  */
 
 import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.sink.SinkEventAttributes;
 import org.apache.maven.doxia.sink.impl.AbstractSinkTest;
 import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
 import org.junit.jupiter.api.Test;
@@ -27,6 +28,8 @@ import org.junit.jupiter.api.Test;
 import java.io.StringWriter;
 import java.io.Writer;
 
+import javax.swing.text.html.HTML.Attribute;
+
 import static org.apache.maven.doxia.util.HtmlTools.escapeHTML;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
@@ -233,7 +236,7 @@ public class XdocSinkTest
     protected String getTableBlock( String cell, String caption )
     {
         return "<table border=\"0\"><caption>" + caption
-                + "</caption>\n<tr valign=\"top\">\n<td align=\"center\">" + 
cell + "</td></tr></table>";
+                + "</caption>\n<tr>\n<td align=\"center\">" + cell + 
"</td></tr></table>";
     }
 
     /** {@inheritDoc} */
@@ -416,9 +419,11 @@ public class XdocSinkTest
         {
             sink = new XdocSink( writer );
 
-            sink.link( "name", (String) null );
+            sink.link( "name" );
             sink.link_();
-            sink.link( "name", "nirvana" );
+            SinkEventAttributes attrs = new SinkEventAttributeSet();
+            attrs.addAttribute( Attribute.TARGET, "nirvana" );
+            sink.link( "name", attrs );
             sink.link_();
         }
         finally
@@ -426,7 +431,7 @@ public class XdocSinkTest
             sink.close();
         }
 
-        assertEquals( "<a href=\"name\"></a><a href=\"name\" 
target=\"nirvana\"></a>", writer.toString() );
+        assertEquals( "<a href=\"name\"></a><a target=\"nirvana\" 
href=\"name\"></a>", writer.toString() );
     }
 
     /** {@inheritDoc} */

Reply via email to