Skip to content
Snippets Groups Projects
Commit a8690cbe authored by Simon Urli's avatar Simon Urli
Browse files

XWIKI-15878: RSS macro should use AbstractBoxMacro instead of BoxMacro

  * Refactor RssMacro to use AbstractBoxMacro instead of BoxMacro
parent 9085b301
No related branches found
No related tags found
No related merge requests found
......@@ -152,6 +152,17 @@
},
"ignore" : [
// Add more ignores below...
{
"code": "java.class.nonFinalClassInheritsFromNewClass",
"old": "class org.xwiki.rendering.macro.rss.RssMacroParameters",
"new": "class org.xwiki.rendering.macro.rss.RssMacroParameters",
"superClass": "org.xwiki.rendering.macro.box.BoxMacroParameters",
"justification": "As RssMacro now inherits from AbstractBoxMacro, its parameter class needs to
inherits from BoxMacroParameters. This could only break compatibility if a class inheriting from
RssMacroParameters defines a method with same name and parameters than in BoxMacroParameters but
different return type. We consider this risk as acceptable since the chances are very low and in
case it occurs, the fix for the user would be easy."
}
]
}
}
......
......@@ -42,7 +42,9 @@
import org.xwiki.rendering.macro.AbstractMacro;
import org.xwiki.rendering.macro.Macro;
import org.xwiki.rendering.macro.MacroExecutionException;
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.macro.rss.RssMacroParameters;
import org.xwiki.rendering.parser.ParseException;
import org.xwiki.rendering.parser.Parser;
......@@ -61,7 +63,7 @@
@Component
@Named("rss")
@Singleton
public class RssMacro extends AbstractMacro<RssMacroParameters>
public class RssMacro extends AbstractBoxMacro<RssMacroParameters>
{
/**
* The name of the CSS class attribute.
......@@ -110,7 +112,7 @@ public class RssMacro extends AbstractMacro<RssMacroParameters>
*/
public RssMacro()
{
super("RSS", DESCRIPTION, RssMacroParameters.class);
super("RSS", DESCRIPTION, new DefaultContentDescriptor(DESCRIPTION, false), RssMacroParameters.class);
setDefaultCategory(DEFAULT_CATEGORY_CONTENT);
}
......@@ -128,21 +130,16 @@ public List<Block> execute(RssMacroParameters parameters, String content, MacroT
SyndFeed feed = this.romeFeedFactory.createFeed(parameters);
if (parameters.isDecoration()) {
BoxMacroParameters boxParameters = new BoxMacroParameters();
boolean hasImage = parameters.isImage() && (feed.getImage() != null);
boxParameters.setCssClass(FEED_CLASS_VALUE);
parameters.setCssClass(FEED_CLASS_VALUE);
if (StringUtils.isNotEmpty(parameters.getWidth())) {
boxParameters.setWidth(parameters.getWidth());
}
boxParameters.setBlockTitle(generateBoxTitle("rsschanneltitle", feed));
parameters.setBlockTitle(generateBoxTitle("rsschanneltitle", feed));
if (hasImage) {
boxParameters.setImage(new ResourceReference(feed.getImage().getUrl(), ResourceType.URL));
parameters.setImage(new ResourceReference(feed.getImage().getUrl(), ResourceType.URL));
}
result = this.boxMacro.execute(boxParameters, content == null ? StringUtils.EMPTY : content, context);
result = super.execute(parameters, content == null ? StringUtils.EMPTY : content, context);
} else {
result = Arrays.<Block>asList(new GroupBlock(Collections.singletonMap(CLASS_ATTRIBUTE, FEED_CLASS_VALUE)));
}
......@@ -152,6 +149,16 @@ public List<Block> execute(RssMacroParameters parameters, String content, MacroT
return result;
}
@Override
protected List<Block> parseContent(RssMacroParameters parameters, String content,
MacroTransformationContext context) throws MacroExecutionException
{
if (content == null) {
content = StringUtils.EMPTY;
}
return this.getMacroContentParser().parse(content, context, false, context.isInline()).getChildren();
}
/**
* Renders the RSS's title.
*
......
......@@ -25,6 +25,7 @@
import org.apache.commons.lang3.StringUtils;
import org.xwiki.properties.annotation.PropertyDescription;
import org.xwiki.properties.annotation.PropertyMandatory;
import org.xwiki.rendering.macro.box.BoxMacroParameters;
import org.xwiki.rendering.macro.parameter.MacroParameterException;
/**
......@@ -33,7 +34,7 @@
* @version $Id$
* @since 1.8RC1
*/
public class RssMacroParameters
public class RssMacroParameters extends BoxMacroParameters
{
/**
* The URL of the RSS feed.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment