You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/05/18 21:12:38 UTC

[maven-doxia] branch DOXIA-590-1.x created (now ee7862f6)

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

michaelo pushed a change to branch DOXIA-590-1.x
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git


      at ee7862f6 [DOXIA-590] Either provided element class or default class gets ignored

This branch includes the following new commits:

     new ee7862f6 [DOXIA-590] Either provided element class or default class gets ignored

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-doxia] 01/01: [DOXIA-590] Either provided element class or default class gets ignored

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ee7862f6a2d52b0f4bb58f4412c3ce537f719cae
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Wed May 18 23:12:22 2022 +0200

    [DOXIA-590] Either provided element class or default class gets ignored
---
 .../maven/doxia/sink/impl/Xhtml5BaseSink.java      | 86 ++++++++++------------
 .../maven/doxia/sink/impl/XhtmlBaseSink.java       | 86 ++++++++++------------
 .../maven/doxia/sink/impl/Xhtml5BaseSinkTest.java  |  4 +-
 .../maven/doxia/sink/impl/XhtmlBaseSinkTest.java   |  4 +-
 4 files changed, 78 insertions(+), 102 deletions(-)

diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java
index 45d726ff..f30403ec 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSink.java
@@ -1567,21 +1567,24 @@ public class Xhtml5BaseSink
     @Override
     public void tableRow( SinkEventAttributes attributes )
     {
-        MutableAttributeSet att = new SinkEventAttributeSet();
+        MutableAttributeSet atts = SinkUtils.filterAttributes(
+                attributes, SinkUtils.SINK_TR_ATTRIBUTES );
 
-        if ( evenTableRow )
+        if ( atts == null )
         {
-            att.addAttribute( Attribute.CLASS, "a" );
+            atts = new SinkEventAttributeSet();
         }
-        else
+
+        String rowClass = evenTableRow ? "a" : "b";
+        if ( atts.isDefined( Attribute.CLASS.toString() ) )
         {
-            att.addAttribute( Attribute.CLASS, "b" );
+            String givenRowClass = (String) atts.getAttribute( Attribute.CLASS.toString() );
+            rowClass = givenRowClass + " " + rowClass;
         }
 
-        att.addAttributes( SinkUtils.filterAttributes(
-                attributes, SinkUtils.SINK_TR_ATTRIBUTES  ) );
+        atts.addAttribute( Attribute.CLASS, rowClass );
 
-        writeStartTag( HtmlMarkup.TR, att );
+        writeStartTag( HtmlMarkup.TR, atts );
 
         evenTableRow = !evenTableRow;
 
@@ -1833,44 +1836,28 @@ public class Xhtml5BaseSink
         }
     }
 
-    /** {@inheritDoc} */
+    /**
+     * The default style class for external link is <code>externalLink</code>.
+     *
+     * {@inheritDoc}
+     * @see javax.swing.text.html.HTML.Tag#A
+     **/
     @Override
     public void link( String name )
     {
         link( name, null );
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public void link( String name, SinkEventAttributes attributes )
-    {
-        if ( attributes == null )
-        {
-            link( name, null, null );
-        }
-        else
-        {
-            String target = (String) attributes.getAttribute( Attribute.TARGET.toString() );
-            MutableAttributeSet atts = SinkUtils.filterAttributes(
-                    attributes, SinkUtils.SINK_LINK_ATTRIBUTES  );
-
-            link( name, target, atts );
-        }
-    }
-
     /**
-     * Adds a link with an optional target.
      * The default style class for external link is <code>externalLink</code>.
      *
-     * @param href the link href.
-     * @param target the link target, may be null.
-     * @param attributes an AttributeSet, may be null.
-     *      This is supposed to be filtered already.
+     * {@inheritDoc}
      * @see javax.swing.text.html.HTML.Tag#A
-     */
-    private void link( String href, String target, MutableAttributeSet attributes )
+     **/
+    @Override
+    public void link( String name, SinkEventAttributes attributes )
     {
-        if ( href == null )
+        if ( name == null )
         {
             throw new NullPointerException( "Link name cannot be null!" );
         }
@@ -1880,28 +1867,29 @@ public class Xhtml5BaseSink
             return;
         }
 
-        MutableAttributeSet att = new SinkEventAttributeSet();
+        MutableAttributeSet atts = SinkUtils.filterAttributes(
+                attributes, SinkUtils.SINK_LINK_ATTRIBUTES );
 
-        if ( DoxiaUtils.isExternalLink( href  ) )
+        if ( atts == null )
         {
-            att.addAttribute( Attribute.CLASS, "externalLink" );
+            atts = new SinkEventAttributeSet();
         }
 
-        att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( href  ) );
-
-        if ( target != null )
+        if ( DoxiaUtils.isExternalLink( name ) )
         {
-            att.addAttribute( Attribute.TARGET, target );
-        }
+            String hrefClass = "externalLink";
+            if ( atts.isDefined( Attribute.CLASS.toString() ) )
+             {
+                 String givenClass = (String) atts.getAttribute( Attribute.CLASS.toString() );
+                 hrefClass = givenClass + " " + hrefClass;
+             }
 
-        if ( attributes != null )
-        {
-            attributes.removeAttribute( Attribute.HREF.toString() );
-            attributes.removeAttribute( Attribute.TARGET.toString() );
-            att.addAttributes( attributes );
+             atts.addAttribute( Attribute.CLASS, hrefClass );
         }
 
-        writeStartTag( HtmlMarkup.A, att );
+        atts.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) );
+
+        writeStartTag( HtmlMarkup.A, atts );
     }
 
     /**
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/XhtmlBaseSink.java b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/XhtmlBaseSink.java
index 10d08ec7..d019f666 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/XhtmlBaseSink.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/sink/impl/XhtmlBaseSink.java
@@ -1444,21 +1444,24 @@ public class XhtmlBaseSink
     @Override
     public void tableRow( SinkEventAttributes attributes )
     {
-        MutableAttributeSet att = new SinkEventAttributeSet();
+        MutableAttributeSet atts = SinkUtils.filterAttributes(
+                attributes, SinkUtils.SINK_TR_ATTRIBUTES );
 
-        if ( evenTableRow )
+        if ( atts == null )
         {
-            att.addAttribute( Attribute.CLASS, "a" );
+            atts = new SinkEventAttributeSet();
         }
-        else
+
+        String rowClass = evenTableRow ? "a" : "b";
+        if ( atts.isDefined( Attribute.CLASS.toString() ) )
         {
-            att.addAttribute( Attribute.CLASS, "b" );
+            String givenRowClass = (String) atts.getAttribute( Attribute.CLASS.toString() );
+            rowClass = givenRowClass + " " + rowClass;
         }
 
-        att.addAttributes( SinkUtils.filterAttributes(
-                attributes, SinkUtils.SINK_TR_ATTRIBUTES  ) );
+        atts.addAttribute( Attribute.CLASS, rowClass );
 
-        writeStartTag( HtmlMarkup.TR, att );
+        writeStartTag( HtmlMarkup.TR, atts );
 
         evenTableRow = !evenTableRow;
 
@@ -1710,44 +1713,28 @@ public class XhtmlBaseSink
         }
     }
 
-    /** {@inheritDoc} */
+    /**
+     * The default style class for external link is <code>externalLink</code>.
+     *
+     * {@inheritDoc}
+     * @see javax.swing.text.html.HTML.Tag#A
+     **/
     @Override
     public void link( String name )
     {
         link( name, null );
     }
 
-    /** {@inheritDoc} */
-    @Override
-    public void link( String name, SinkEventAttributes attributes )
-    {
-        if ( attributes == null )
-        {
-            link( name, null, null );
-        }
-        else
-        {
-            String target = (String) attributes.getAttribute( Attribute.TARGET.toString() );
-            MutableAttributeSet atts = SinkUtils.filterAttributes(
-                    attributes, SinkUtils.SINK_LINK_ATTRIBUTES  );
-
-            link( name, target, atts );
-        }
-    }
-
     /**
-     * Adds a link with an optional target.
      * The default style class for external link is <code>externalLink</code>.
      *
-     * @param href the link href.
-     * @param target the link target, may be null.
-     * @param attributes an AttributeSet, may be null.
-     *      This is supposed to be filtered already.
+     * {@inheritDoc}
      * @see javax.swing.text.html.HTML.Tag#A
-     */
-    private void link( String href, String target, MutableAttributeSet attributes )
+     **/
+    @Override
+    public void link( String name, SinkEventAttributes attributes )
     {
-        if ( href == null )
+        if ( name == null )
         {
             throw new NullPointerException( "Link name cannot be null!" );
         }
@@ -1757,28 +1744,29 @@ public class XhtmlBaseSink
             return;
         }
 
-        MutableAttributeSet att = new SinkEventAttributeSet();
+        MutableAttributeSet atts = SinkUtils.filterAttributes(
+                attributes, SinkUtils.SINK_LINK_ATTRIBUTES );
 
-        if ( DoxiaUtils.isExternalLink( href  ) )
+        if ( atts == null )
         {
-            att.addAttribute( Attribute.CLASS, "externalLink" );
+            atts = new SinkEventAttributeSet();
         }
 
-        att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( href  ) );
-
-        if ( target != null )
+        if ( DoxiaUtils.isExternalLink( name ) )
         {
-            att.addAttribute( Attribute.TARGET, target );
-        }
+            String hrefClass = "externalLink";
+            if ( atts.isDefined( Attribute.CLASS.toString() ) )
+             {
+                 String givenClass = (String) atts.getAttribute( Attribute.CLASS.toString() );
+                 hrefClass = givenClass + " " + hrefClass;
+             }
 
-        if ( attributes != null )
-        {
-            attributes.removeAttribute( Attribute.HREF.toString() );
-            attributes.removeAttribute( Attribute.TARGET.toString() );
-            att.addAttributes( attributes );
+             atts.addAttribute( Attribute.CLASS, hrefClass );
         }
 
-        writeStartTag( HtmlMarkup.A, att );
+        atts.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) );
+
+        writeStartTag( HtmlMarkup.A, atts );
     }
 
     /**
diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSinkTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSinkTest.java
index 6e1652e6..098a8826 100644
--- a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSinkTest.java
+++ b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/Xhtml5BaseSinkTest.java
@@ -1094,7 +1094,7 @@ public class Xhtml5BaseSinkTest
             sink.close();
         }
 
-        assertEquals( "<tr class=\"a\" style=\"bold\"></tr>", writer.toString() );
+        assertEquals( "<tr style=\"bold\" class=\"a\"></tr>", writer.toString() );
     }
 
     /**
@@ -1208,7 +1208,7 @@ public class Xhtml5BaseSinkTest
             sink.close();
         }
 
-        assertEquals( "<a href=\"link.html\" style=\"bold\"></a>", writer.toString() );
+        assertEquals( "<a style=\"bold\" href=\"link.html\"></a>", writer.toString() );
     }
 
     /**
diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/XhtmlBaseSinkTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/XhtmlBaseSinkTest.java
index 9e498e25..a3c6d597 100644
--- a/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/XhtmlBaseSinkTest.java
+++ b/doxia-core/src/test/java/org/apache/maven/doxia/sink/impl/XhtmlBaseSinkTest.java
@@ -712,7 +712,7 @@ public class XhtmlBaseSinkTest
             sink.close();
         }
 
-        assertEquals( "<tr class=\"a\" style=\"bold\"></tr>", writer.toString() );
+        assertEquals( "<tr style=\"bold\" class=\"a\"></tr>", writer.toString() );
     }
 
     /**
@@ -826,7 +826,7 @@ public class XhtmlBaseSinkTest
             sink.close();
         }
 
-        assertEquals( "<a href=\"link.html\" style=\"bold\"></a>", writer.toString() );
+        assertEquals( "<a style=\"bold\" href=\"link.html\"></a>", writer.toString() );
     }
 
     /**