Search in sources :

Example 6 with ImageBlock

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);
}
Also used : ImageBlock(org.xwiki.rendering.block.ImageBlock) LinkBlock(org.xwiki.rendering.block.LinkBlock) LinkBlock(org.xwiki.rendering.block.LinkBlock) Block(org.xwiki.rendering.block.Block) ImageBlock(org.xwiki.rendering.block.ImageBlock) RawBlock(org.xwiki.rendering.block.RawBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) GroupBlock(org.xwiki.rendering.block.GroupBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference)

Example 7 with ImageBlock

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);
}
Also used : ImageBlock(org.xwiki.rendering.block.ImageBlock) LinkBlock(org.xwiki.rendering.block.LinkBlock) LinkBlock(org.xwiki.rendering.block.LinkBlock) Block(org.xwiki.rendering.block.Block) ImageBlock(org.xwiki.rendering.block.ImageBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference)

Aggregations

ImageBlock (org.xwiki.rendering.block.ImageBlock)7 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)6 Block (org.xwiki.rendering.block.Block)4 AttachmentReference (org.xwiki.model.reference.AttachmentReference)3 ClassBlockMatcher (org.xwiki.rendering.block.match.ClassBlockMatcher)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 ExpandedMacroBlock (org.xwiki.rendering.block.ExpandedMacroBlock)2 GroupBlock (org.xwiki.rendering.block.GroupBlock)2 LinkBlock (org.xwiki.rendering.block.LinkBlock)2 MetaDataBlock (org.xwiki.rendering.block.MetaDataBlock)2 ParagraphBlock (org.xwiki.rendering.block.ParagraphBlock)2 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)2 TemporaryResourceReference (org.xwiki.resource.temporary.TemporaryResourceReference)2 File (java.io.File)1 InputStream (java.io.InputStream)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1