diff --git a/xwiki-rendering-macros/xwiki-rendering-macro-message/src/main/java/org/xwiki/rendering/internal/macro/message/AbstractMessageMacro.java b/xwiki-rendering-macros/xwiki-rendering-macro-message/src/main/java/org/xwiki/rendering/internal/macro/message/AbstractMessageMacro.java index 3257495ea..16b8692f2 100644 --- a/xwiki-rendering-macros/xwiki-rendering-macro-message/src/main/java/org/xwiki/rendering/internal/macro/message/AbstractMessageMacro.java +++ b/xwiki-rendering-macros/xwiki-rendering-macro-message/src/main/java/org/xwiki/rendering/internal/macro/message/AbstractMessageMacro.java @@ -37,7 +37,6 @@ import org.xwiki.rendering.macro.MacroExecutionException; import org.xwiki.rendering.macro.MacroPreparationException; import org.xwiki.rendering.macro.box.AbstractBoxMacro; -import org.xwiki.rendering.macro.box.BoxMacroParameters; import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor; import org.xwiki.rendering.parser.ParseException; import org.xwiki.rendering.parser.Parser; @@ -50,7 +49,7 @@ * @version $Id$ * @since 2.0M3 */ -public abstract class AbstractMessageMacro extends AbstractBoxMacro +public abstract class AbstractMessageMacro extends AbstractBoxMacro { private String iconName; @@ -77,11 +76,10 @@ public AbstractMessageMacro(String macroName, String macroDescription) { super(macroName, macroDescription, new DefaultContentDescriptor("Content of the message", true, Block.LIST_BLOCK_TYPE), - BoxMacroParameters.class); + MessageMacroParameters.class); } - - @Override - protected List parseContent(BoxMacroParameters parameters, String content, + + protected List parseContent(MessageMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { List macroContent = getMacroContentParser().parse(content, context, false, context.isInline()) @@ -118,12 +116,15 @@ public void prepare(MacroBlock macroBlock) throws MacroPreparationException } @Override - public List execute(BoxMacroParameters parameters, String content, MacroTransformationContext context) + public List execute(MessageMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { List boxFoundation = super.execute(parameters, content, context); if (!boxFoundation.isEmpty() && getIconName() != null) { Block defaultBox = boxFoundation.get(0); + if (parameters.isStatus()) { + defaultBox.setParameter("role", "status"); + } // For an easier styling, we wrap the content and title together if they are non-empty and visible if (defaultBox.getChildren().size() > 1) { Block boxTextContent = new GroupBlock(defaultBox.getChildren()); diff --git a/xwiki-rendering-macros/xwiki-rendering-macro-message/src/main/java/org/xwiki/rendering/internal/macro/message/MessageMacroParameters.java b/xwiki-rendering-macros/xwiki-rendering-macro-message/src/main/java/org/xwiki/rendering/internal/macro/message/MessageMacroParameters.java new file mode 100644 index 000000000..49a41763c --- /dev/null +++ b/xwiki-rendering-macros/xwiki-rendering-macro-message/src/main/java/org/xwiki/rendering/internal/macro/message/MessageMacroParameters.java @@ -0,0 +1,62 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.xwiki.rendering.internal.macro.message; + +import org.xwiki.properties.annotation.PropertyAdvanced; +import org.xwiki.properties.annotation.PropertyDescription; +import org.xwiki.properties.annotation.PropertyDisplayType; +import org.xwiki.rendering.macro.box.BoxMacroParameters; +import org.xwiki.stability.Unstable; + +/** + * Parameters for the Message macro. + * + * @version $Id$ + * @since 17.0.0RC1 + */ +public class MessageMacroParameters extends BoxMacroParameters +{ + /** + * @see #isStatus() + */ + private boolean isStatus; + + /** + * @since 17.0.0RC1 + * @return whether or not the current message is a status. + */ + @Unstable + public boolean isStatus() + { + return this.isStatus; + } + + /** + * @since 17.0.0RC1 + * @param isStatus refers to {@link #isStatus()} + */ + @PropertyDescription("Whether or not this message should be announced as a status.") + @PropertyAdvanced + @Unstable + public void setStatus(boolean isStatus) + { + this.isStatus = isStatus; + } +} diff --git a/xwiki-rendering-macros/xwiki-rendering-macro-message/src/test/java/org/xwiki/rendering/macro/message/MessageMacroTest.java b/xwiki-rendering-macros/xwiki-rendering-macro-message/src/test/java/org/xwiki/rendering/macro/message/MessageMacroTest.java index 7c607484c..abd930468 100644 --- a/xwiki-rendering-macros/xwiki-rendering-macro-message/src/test/java/org/xwiki/rendering/macro/message/MessageMacroTest.java +++ b/xwiki-rendering-macros/xwiki-rendering-macro-message/src/test/java/org/xwiki/rendering/macro/message/MessageMacroTest.java @@ -25,9 +25,9 @@ import org.junit.jupiter.api.Test; import org.xwiki.rendering.block.Block; import org.xwiki.rendering.block.RawBlock; +import org.xwiki.rendering.internal.macro.message.MessageMacroParameters; import org.xwiki.rendering.macro.Macro; import org.xwiki.rendering.macro.MacroExecutionException; -import org.xwiki.rendering.macro.box.BoxMacroParameters; import org.xwiki.rendering.parser.ParseException; import org.xwiki.rendering.parser.Parser; import org.xwiki.rendering.renderer.BlockRenderer; @@ -88,7 +88,7 @@ void executeWithRawBlockForIconBlock() throws Exception IconProvider iconProvider = this.componentManager.registerMockComponent(IconProvider.class); when(iconProvider.get("information")).thenReturn(new RawBlock("some html", Syntax.HTML_4_01)); Macro messageMacro = this.componentManager.getInstance(Macro.class, "info"); - BoxMacroParameters parameters = new BoxMacroParameters(); + MessageMacroParameters parameters = new MessageMacroParameters(); when(this.context.getSyntax()).thenReturn(Syntax.XWIKI_2_1); List blocks = messageMacro.execute(parameters, "content", this.context); @@ -112,7 +112,7 @@ void executeWhenParsingErrorForIconPrettyName() throws Exception Parser plainTextParser = this.componentManager.registerMockComponent(Parser.class, "plain/1.0"); doThrow(new ParseException("error")).when(plainTextParser).parse(any(Reader.class)); Macro messageMacro = this.componentManager.getInstance(Macro.class, "info"); - BoxMacroParameters parameters = new BoxMacroParameters(); + MessageMacroParameters parameters = new MessageMacroParameters(); when(this.context.getSyntax()).thenReturn(Syntax.XWIKI_2_1); Throwable exception = assertThrows(MacroExecutionException.class,