Search in sources :

Example 11 with GroupBlock

use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.

the class EditableGadgetRenderer method getGadgetEditMetadata.

/**
 * @param gadget the gadget to decorate
 * @return the block containing the metadata that will allow clients to edit this gadget
 */
protected Block getGadgetEditMetadata(Gadget gadget) {
    GroupBlock metadataBlock = new GroupBlock();
    metadataBlock.setParameter(CLASS, METADATA);
    // look at the content of the gadget and store whether it's a macro or not
    boolean isMacro = gadget.getContent().size() == 1 && gadget.getContent().get(0) instanceof MacroMarkerBlock;
    GroupBlock isMacroBlock = new GroupBlock();
    isMacroBlock.setParameter(CLASS, "isMacro");
    isMacroBlock.addChild(new WordBlock(Boolean.toString(isMacro)));
    metadataBlock.addChild(isMacroBlock);
    if (isMacro) {
        // render the annotated macro call in the page, to be able to edit it. Only the macro call comments will be
        // rendered, since transformations are not ran, so there is no content in the macro. But annotation is
        // enough.
        GroupBlock renderedContentBlock = new GroupBlock();
        renderedContentBlock.setParameter(CLASS, "content");
        WikiPrinter printer = new DefaultWikiPrinter();
        BlockRenderer gadgetContentRenderer = getGadgetContentRenderer();
        gadgetContentRenderer.render(gadget.getContent(), printer);
        RawBlock rawBlock = new RawBlock(printer.toString(), getRawBlockSyntax(gadgetContentRenderer));
        renderedContentBlock.addChild(rawBlock);
        // render the title in the page as well, to be edited as source
        GroupBlock gadgetTitleBlock = new GroupBlock();
        gadgetTitleBlock.setParameter(CLASS, "title");
        // even if it's not a word, it's fine since it will be rendered in one piece
        gadgetTitleBlock.addChild(new WordBlock(gadget.getTitleSource()));
        metadataBlock.addChild(renderedContentBlock);
        metadataBlock.addChild(gadgetTitleBlock);
    }
    return metadataBlock;
}
Also used : DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) WordBlock(org.xwiki.rendering.block.WordBlock) RawBlock(org.xwiki.rendering.block.RawBlock) GroupBlock(org.xwiki.rendering.block.GroupBlock) MacroMarkerBlock(org.xwiki.rendering.block.MacroMarkerBlock) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) BlockRenderer(org.xwiki.rendering.renderer.BlockRenderer)

Example 12 with GroupBlock

use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.

the class RssMacro method execute.

@Override
public List<Block> execute(RssMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
    List<Block> result;
    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);
        if (StringUtils.isNotEmpty(parameters.getWidth())) {
            boxParameters.setWidth(parameters.getWidth());
        }
        boxParameters.setBlockTitle(generateBoxTitle("rsschanneltitle", feed));
        if (hasImage) {
            boxParameters.setImage(new ResourceReference(feed.getImage().getUrl(), ResourceType.URL));
        }
        result = this.boxMacro.execute(boxParameters, content == null ? StringUtils.EMPTY : content, context);
    } else {
        result = Arrays.<Block>asList(new GroupBlock(Collections.singletonMap(CLASS_ATTRIBUTE, FEED_CLASS_VALUE)));
    }
    generateEntries(result.get(0), feed, parameters);
    return result;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) GroupBlock(org.xwiki.rendering.block.GroupBlock) 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) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) BoxMacroParameters(org.xwiki.rendering.macro.box.BoxMacroParameters)

Example 13 with GroupBlock

use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.

the class ColumnsLayoutManager method layoutContainer.

@Override
public void layoutContainer(Block container) {
    List<GroupBlock> innerGroups = container.getBlocks(new ClassBlockMatcher(GroupBlock.class), Block.Axes.CHILD);
    // FIXME Should we cry and throw an exception if ever we meet something else than a group right under
    // the container macro, or automatically put it in a group maybe ?
    int count = innerGroups.size();
    if (innerGroups.size() == 0) {
        // nothing inside, nothing to layout
        return;
    }
    Map<String, Object> skinxParams = new HashMap<String, Object>();
    skinxParams.put("forceSkinAction", true);
    ssfx.use("uicomponents/container/columns.css", skinxParams);
    // add styles to all columns inside
    for (int i = 0; i < count; i++) {
        GroupBlock column = innerGroups.get(i);
        String classValue = "column";
        if (i == 0) {
            // we're at the first element in the list, put a marker. Don't need it to do standard columns layout,
            // but maybe somebody needs it for customization...
            classValue = classValue + " first-column";
        }
        if (i == count - 1) {
            // we're at the last element in the list, put a marker
            classValue = classValue + " last-column";
        }
        String oldClass = column.getParameter(CLASS_ATTRIBUTE);
        column.setParameter(CLASS_ATTRIBUTE, (StringUtils.isEmpty(oldClass) ? classValue : oldClass + " " + classValue));
    }
    // finally, clear the floats introduced by the columns
    Map<String, String> clearFloatsParams = new HashMap<String, String>();
    clearFloatsParams.put(CLASS_ATTRIBUTE, "clearfloats");
    String oldClass = container.getParameter(CLASS_ATTRIBUTE);
    String newClass = "container-columns container-columns-" + count;
    container.setParameter(CLASS_ATTRIBUTE, StringUtils.isEmpty(oldClass) ? newClass : oldClass + " " + newClass);
    container.addChild(new GroupBlock(clearFloatsParams));
}
Also used : HashMap(java.util.HashMap) ClassBlockMatcher(org.xwiki.rendering.block.match.ClassBlockMatcher) GroupBlock(org.xwiki.rendering.block.GroupBlock)

Example 14 with GroupBlock

use of org.xwiki.rendering.block.GroupBlock in project xwiki-platform by xwiki.

the class TranslationMacro method execute.

@Override
public List<Block> execute(TranslationMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
    Locale locale = parameters.getLocale() != null ? parameters.getLocale() : this.localizationContext.getCurrentLocale();
    Translation translation = this.localization.getTranslation(parameters.getKey(), locale);
    List<Block> blocks;
    if (translation != null) {
        Block block = parameters.getParameters() != null ? translation.render(locale, (Object[]) parameters.getParameters()) : translation.render(locale);
        if (block instanceof CompositeBlock) {
            blocks = block.getChildren();
        } else {
            blocks = Arrays.asList(block);
        }
        if (!context.getCurrentMacroBlock().isInline()) {
            // Make the content standalone
            blocks = Arrays.<Block>asList(new GroupBlock(blocks));
        }
    } else if (content != null) {
        blocks = this.macroContentParser.parse(content, context, false, context.getCurrentMacroBlock().isInline()).getChildren();
    } else {
        try {
            blocks = this.plainParser.parse(new StringReader(parameters.getKey())).getChildren();
            if (context.getCurrentMacroBlock().isInline()) {
                PARSERUTILS.removeTopLevelParagraph(blocks);
            }
        } catch (ParseException e) {
            throw new MacroExecutionException("Failed to parse key [" + parameters.getKey() + "]", e);
        }
    }
    return blocks;
}
Also used : Locale(java.util.Locale) Translation(org.xwiki.localization.Translation) GroupBlock(org.xwiki.rendering.block.GroupBlock) StringReader(java.io.StringReader) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) CompositeBlock(org.xwiki.rendering.block.CompositeBlock) Block(org.xwiki.rendering.block.Block) GroupBlock(org.xwiki.rendering.block.GroupBlock) CompositeBlock(org.xwiki.rendering.block.CompositeBlock) ParseException(org.xwiki.rendering.parser.ParseException)

Aggregations

GroupBlock (org.xwiki.rendering.block.GroupBlock)14 Block (org.xwiki.rendering.block.Block)12 RawBlock (org.xwiki.rendering.block.RawBlock)4 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)4 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)4 HashMap (java.util.HashMap)3 ImageBlock (org.xwiki.rendering.block.ImageBlock)3 LinkBlock (org.xwiki.rendering.block.LinkBlock)3 WordBlock (org.xwiki.rendering.block.WordBlock)3 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 ParagraphBlock (org.xwiki.rendering.block.ParagraphBlock)2 Gadget (org.xwiki.rendering.macro.dashboard.Gadget)2 ParseException (org.xwiki.rendering.parser.ParseException)2 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 PrintWriter (java.io.PrintWriter)1