This is an automated email from the ASF dual-hosted git repository. michaelo pushed a commit to branch DOXIA-590 in repository https://gitbox.apache.org/repos/asf/maven-doxia.git
commit a3b5106f4fa313718e46aa241c92e9fdb76b4dac Author: Michael Osipov <[email protected]> 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 891471ad..13b4a99d 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 @@ -1532,21 +1532,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; @@ -1774,72 +1777,57 @@ 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 ) { - Objects.requireNonNull( href, "href cannot be null" ); + Objects.requireNonNull( name, "name cannot be null" ); if ( headFlag ) { 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 linkClass = "externalLink"; + if ( atts.isDefined( Attribute.CLASS.toString() ) ) + { + String givenLinkClass = (String) atts.getAttribute( Attribute.CLASS.toString() ); + linkClass = givenLinkClass + " " + linkClass; + } - if ( attributes != null ) - { - attributes.removeAttribute( Attribute.HREF.toString() ); - attributes.removeAttribute( Attribute.TARGET.toString() ); - att.addAttributes( attributes ); + atts.addAttribute( Attribute.CLASS, linkClass ); } - 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 8bccda25..b9da9ee1 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 @@ -1410,21 +1410,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; @@ -1652,72 +1655,57 @@ 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 ) { - Objects.requireNonNull( href, "href cannot be null" ); + Objects.requireNonNull( name, "name cannot be null" ); if ( headFlag ) { 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 linkClass = "externalLink"; + if ( atts.isDefined( Attribute.CLASS.toString() ) ) + { + String givenLinkClass = (String) atts.getAttribute( Attribute.CLASS.toString() ); + linkClass = givenLinkClass + " " + linkClass; + } - if ( attributes != null ) - { - attributes.removeAttribute( Attribute.HREF.toString() ); - attributes.removeAttribute( Attribute.TARGET.toString() ); - att.addAttributes( attributes ); + atts.addAttribute( Attribute.CLASS, linkClass ); } - 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 cf8f52c5..1e3ef4ec 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 @@ -1093,7 +1093,7 @@ public class Xhtml5BaseSinkTest sink.close(); } - assertEquals( "<tr class=\"a\" style=\"bold\"></tr>", writer.toString() ); + assertEquals( "<tr style=\"bold\" class=\"a\"></tr>", writer.toString() ); } /** @@ -1207,7 +1207,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 813d56f8..be4bd18c 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 @@ -713,7 +713,7 @@ public class XhtmlBaseSinkTest sink.close(); } - assertEquals( "<tr class=\"a\" style=\"bold\"></tr>", writer.toString() ); + assertEquals( "<tr style=\"bold\" class=\"a\"></tr>", writer.toString() ); } /** @@ -827,7 +827,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() ); } /**
