use of org.xwiki.rendering.block.ImageBlock in project xwiki-platform by xwiki.
the class RssMacro method generateBoxTitle.
/**
* Renders the RSS's title.
*
* @param cssClass the CSS sheet
* @param feed the RSS feed data
* @return the list of blocks making the RSS Box title
*/
private List<? extends Block> generateBoxTitle(String cssClass, SyndFeed feed) {
List<Block> titleBlocks;
if (feed.getLink() == null) {
titleBlocks = parsePlainText(feed.getTitle());
} else {
// Title link.
ResourceReference titleResourceReference = new ResourceReference(feed.getLink(), ResourceType.URL);
// Title text link.
Block titleTextLinkBlock = new LinkBlock(parsePlainText(feed.getTitle()), titleResourceReference, true);
// Rss icon.
String imagePath = this.skinAccessBridge.getSkinFile(FEED_ICON_RESOURCE_PATH);
ImageBlock imageBlock = new ImageBlock(new ResourceReference(imagePath, ResourceType.URL), false);
// Title rss icon link.
Block titleImageLinkBlock = new LinkBlock(Arrays.<Block>asList(imageBlock), titleResourceReference, true);
titleBlocks = Arrays.<Block>asList(titleTextLinkBlock, titleImageLinkBlock);
}
ParagraphBlock titleBlock = new ParagraphBlock(titleBlocks);
titleBlock.setParameter(CLASS_ATTRIBUTE, cssClass);
return Collections.singletonList(titleBlock);
}
use of org.xwiki.rendering.block.ImageBlock in project xwiki-platform by xwiki.
the class ChartMacro method execute.
@Override
public List<Block> execute(ChartMacroParameters macroParams, String content, MacroTransformationContext context) throws MacroExecutionException {
// Generate the chart image in a temporary location.
generateChart(macroParams, content, context);
String imageLocation = this.imageWriter.getURL(new ImageId(macroParams));
String title = macroParams.getTitle();
ResourceReference reference = new ResourceReference(imageLocation, ResourceType.URL);
ImageBlock imageBlock = new ImageBlock(new ResourceReference(imageLocation, ResourceType.URL), true);
imageBlock.setParameter("alt", title);
LinkBlock linkBlock = new LinkBlock(Collections.singletonList((Block) imageBlock), reference, true);
linkBlock.setParameter("title", title);
// If the macro is used standalone then we need to wrap it in a paragraph block.
Block resultBlock;
if (context.isInline()) {
resultBlock = linkBlock;
} else {
resultBlock = new ParagraphBlock(Collections.singletonList((Block) linkBlock));
}
return Collections.singletonList(resultBlock);
}
Aggregations