private void generateError(MacroBlock macroToReplace, String message, String description) { List<Block> errorBlocks = new ArrayList<Block>(); Map<String, String> errorBlockParams = Collections.singletonMap("class", "xwikirenderingerror"); Map<String, String> errorDescriptionBlockParams = Collections.singletonMap("class", "xwikirenderingerrordescription hidden"); Block descriptionBlock = new VerbatimBlock(description, macroToReplace.isInline()); if (macroToReplace.isInline()) { errorBlocks.add(new FormatBlock(Arrays.<Block> asList(new WordBlock(message)), Format.NONE, errorBlockParams)); errorBlocks.add(new FormatBlock(Arrays.asList(descriptionBlock), Format.NONE, errorDescriptionBlockParams)); } else { errorBlocks.add(new GroupBlock(Arrays.<Block> asList(new WordBlock(message)), errorBlockParams)); errorBlocks.add(new GroupBlock(Arrays.asList(descriptionBlock), errorDescriptionBlockParams)); } macroToReplace.getParent().replaceChild(wrapInMacroMarker(macroToReplace, errorBlocks), macroToReplace); }
/** * Wrap the output of a macro block with a {@link MacroMarkerBlock}. * * @param macroBlockToWrap the block that should be replaced * @param newBlocks list of blocks to wrap * @return the wrapper */ private Block wrapInMacroMarker(MacroBlock macroBlockToWrap, List<Block> newBlocks) { return new MacroMarkerBlock(macroBlockToWrap.getId(), macroBlockToWrap.getParameters(), macroBlockToWrap .getContent(), newBlocks, macroBlockToWrap.isInline()); }
/** * @param xdom the {@link XDOM} to convert * @return an inline version of the passed {@link XDOM} */ private XDOM convertToInline(XDOM xdom) { List<Block> blocks = new ArrayList<Block>(xdom.getChildren()); // TODO: use inline parser instead if (!blocks.isEmpty()) { this.parserUtils.removeTopLevelParagraph(blocks); // Make sure included macro is inline when script macro itself is inline Block block = blocks.get(0); if (block instanceof MacroBlock) { MacroBlock macro = (MacroBlock) block; if (!macro.isInline()) { blocks.set(0, new MacroBlock(macro.getId(), macro.getParameters(), macro.getContent(), true)); } } xdom.setChildren(blocks); } return xdom; }
/** * Wrap the output of a macro block with a {@link MacroMarkerBlock}. * * @param macroBlockToWrap the block that should be replaced * @param newBlocks list of blocks to wrap * @return the wrapper */ private Block wrapInMacroMarker(MacroBlock macroBlockToWrap, List<Block> newBlocks) { return new MacroMarkerBlock(macroBlockToWrap.getId(), macroBlockToWrap.getParameters(), macroBlockToWrap.getContent(), newBlocks, macroBlockToWrap.isInline()); }
/** * Wrap the output of a macro block with a {@link org.xwiki.rendering.block.MacroMarkerBlock}. * * @param macroBlockToWrap the block that should be replaced * @param newBlocks list of blocks to wrap * @return the wrapper */ private Block wrapInMacroMarker(MacroBlock macroBlockToWrap, List<Block> newBlocks) { return new MacroMarkerBlock(macroBlockToWrap.getId(), macroBlockToWrap.getParameters(), macroBlockToWrap.getContent(), newBlocks, macroBlockToWrap.isInline()); } }
/** * Generates Blocks to signify that the passed Macro Block has failed to execute. * * @param macroToReplace the block for the macro that failed to execute and that we'll replace with Block * showing to the user that macro has failed * @param message the message to display to the user in place of the macro result * @param description the long description of the error to display to the user in place of the macro result */ public void generateError(MacroBlock macroToReplace, String message, String description) { List<Block> errorBlocks = this.errorBlockGenerator.generateErrorBlocks(message, description, macroToReplace.isInline()); macroToReplace.getParent().replaceChild(wrapInMacroMarker(macroToReplace, errorBlocks), macroToReplace); }
/** * Generates Blocks to signify that the passed Macro Block has failed to execute. * * @param macroToReplace the block for the macro that failed to execute and that we'll replace with Block * showing to the user that macro has failed * @param message the message to display to the user in place of the macro result * @param throwable the exception for the failed macro execution to display to the user in place of the macro result */ public void generateError(MacroBlock macroToReplace, String message, Throwable throwable) { List<Block> errorBlocks = this.errorBlockGenerator.generateErrorBlocks(message, throwable, macroToReplace.isInline()); macroToReplace.getParent().replaceChild(wrapInMacroMarker(macroToReplace, errorBlocks), macroToReplace); }
/** * {@inheritDoc} * * @see org.xwiki.rendering.block.AbstractBlock#traverse(org.xwiki.rendering.listener.Listener) */ public void traverse(Listener listener) { // Don't do anything here since we want the Macro Transformer component to take in charge // Macro execution. This is because Macro execution is a complex process that involves: // * computing the order in which the macros should be evaluated. For example the TOC macro // should evaluate last since other macros can contribute headers/sections blocks. // * some macros need to modify blocks in the XDOM object // * macro execution is a multi-pass process // In essence the Macro Transformer will replace all MacroBlock blocks with other Blocks // generated from the execution of the Macros when XDOM.traverse() is called there // won't be any MacroBlock.traverse() method called at all. // Note: We're calling the event to let other listener downstream decide what to do with it. // In practice as described above this method will never get called when the whole rendering // process is executed. This does get called during our unit tests though. listener.onMacro(getId(), getParameters(), getContent(), isInline()); } }
if (!result.isEmpty() && result.get(0) instanceof MacroBlock && !((MacroBlock) result.get(0)).isInline()) { MacroBlock macro = (MacroBlock) result.get(0); result.set(0, new MacroBlock(macro.getId(), macro.getParameters(), macro.getContent(), true));
if (!result.isEmpty() && result.get(0) instanceof MacroBlock && !((MacroBlock) result.get(0)).isInline()) { MacroBlock macro = (MacroBlock) result.get(0); result.set(0, new MacroBlock(macro.getId(), macro.getParameters(), macro.getContent(), true));
if (!context.getCurrentMacroBlock().isInline()) { this.macroContentParser.parse(content, context, false, context.getCurrentMacroBlock().isInline()) .getChildren(); } else { blocks = this.plainParser.parse(new StringReader(parameters.getKey())).getChildren(); if (context.getCurrentMacroBlock().isInline()) { PARSERUTILS.removeTopLevelParagraph(blocks);
.getContent(), xdom.getChildren(), htmlMacroBlock.isInline());
htmlMacroBlock.getContent(), xdom.getChildren(), htmlMacroBlock.isInline());
try { if (macroBlock.isInline()) { macroContext.setInline(true); if (!macro.supportsInlineMode()) {
if (macroHolder.macroBlock.isInline()) { context.setInline(true); if (!macroHolder.macro.supportsInlineMode()) {
wikiMacroBlock.getContent(), macroXDOM.getChildren(), wikiMacroBlock.isInline());