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); }
continue; } else if (PutFootnotesMacro.MACRO_NAME.equals(macro.getId())) { macro.getParent().replaceChild(Collections.<Block>emptyList(), macro);
/** * 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); }
@Override public void transform(Block block, TransformationContext transformationContext) throws TransformationException { // Find all Word blocks and for each of them check if they're a wiki word or not for (WordBlock wordBlock : this.filter.getChildrenByType(block, WordBlock.class, true)) { Matcher matcher = WIKIWORD_PATTERN.matcher(wordBlock.getWord()); if (matcher.matches()) { ResourceReference linkReference = new DocumentResourceReference(wordBlock.getWord()); wordBlock.getParent().replaceChild(new LinkBlock(wordBlock.getChildren(), linkReference, false), wordBlock); } } } }
/** * {@inheritDoc} * @see AbstractTransformation#transform(Block, TransformationContext) */ public void transform(Block block, TransformationContext transformationContext) throws TransformationException { // Find all Word blocks and for each of them check if they're a wiki word or not for (WordBlock wordBlock : this.filter.getChildrenByType(block, WordBlock.class, true)) { Matcher matcher = WIKIWORD_PATTERN.matcher(wordBlock.getWord()); if (matcher.matches()) { ResourceReference linkReference = new DocumentResourceReference(wordBlock.getWord()); wordBlock.getParent().replaceChild(new LinkBlock(wordBlock.getChildren(), linkReference, false), wordBlock); } } } }
imgBlock.getParent().replaceChild(Arrays.asList(newImgBlock), imgBlock);
section.getParent().replaceChild(blocks, section);
private void maybeFixExpandedMacroAncestor(Block block) { ExpandedMacroBlock expandedMacro = block.getFirstBlock(new ClassBlockMatcher(ExpandedMacroBlock.class), Block.Axes.ANCESTOR_OR_SELF); if (expandedMacro != null) { Block parent = expandedMacro.getParent(); if (!(parent instanceof MetaDataBlock) || !((MetaDataBlock) parent).getMetaData().contains(MODULE_NAME)) { MetaDataBlock metaData = new MetaDataBlock(Collections.<Block>emptyList()); // Use a syntax that supports relative path resource references (we use relative paths to include the // temporary files). metaData.getMetaData().addMetaData(MetaData.SYNTAX, Syntax.XWIKI_2_1); metaData.getMetaData().addMetaData(MODULE_NAME, true); parent.replaceChild(metaData, expandedMacro); metaData.addChild(expandedMacro); } } }
header.getId() ); header.getParent().replaceChild(nheader, header); substitution.src.getParent().replaceChild(substitution.dst, substitution.src);
htmlMacroBlock.getParent().replaceChild(htmlMacroMarker, htmlMacroBlock); } finally { htmlMacroMarker.getParent().replaceChild(htmlMacroBlock, htmlMacroMarker);
wikiMacroBlock.getParent().replaceChild(syncMetaDataBlock, wikiMacroBlock); if (syncMetaDataBlock != null) { syncMetaDataBlock.getParent().replaceChild(this.syncContext.getCurrentMacroBlock(), syncMetaDataBlock);
macroHolder.macroBlock.getParent().replaceChild(resultBlock, macroHolder.macroBlock);
macroBlock.getParent().replaceChild(resultBlock, macroBlock);