@Override public List<Block> execute(FootnoteMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { Block root = context.getXDOM(); Block matchingBlock = root.getFirstBlock(MACRO_BLOCK_MATCHER, Block.Axes.DESCENDANT); if (matchingBlock != null) { return Collections.emptyList(); } Block putFootnotesMacro = new MacroBlock(PutFootnotesMacro.MACRO_NAME, Collections.<String, String>emptyMap(), false); root.addChild(putFootnotesMacro); return Collections.emptyList(); } }
/** * @param source the blocks from where to try to extract the source content * @return the source content reference or null if none is found */ private String extractSourceContentReference(Block source) { String contentSource = null; MetaDataBlock metaDataBlock = source.getFirstBlock(new MetadataBlockMatcher(MetaData.SOURCE), Block.Axes.ANCESTOR); if (metaDataBlock != null) { contentSource = (String) metaDataBlock.getMetaData().getMetaData(MetaData.SOURCE); } return contentSource; } }
/** * @param source the blocks from where to try to extract the source content * @return the source content reference or null if none is found */ private String extractSourceContentReference(Block source) { String contentSource = null; MetaDataBlock metaDataBlock = source.getFirstBlock(new MetadataBlockMatcher(MetaData.SOURCE), Block.Axes.ANCESTOR); if (metaDataBlock != null) { contentSource = (String) metaDataBlock.getMetaData().getMetaData(MetaData.SOURCE); } return contentSource; } }
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); } } }
rootBlock.getFirstBlock(priorityMacroBlockMatcher, Block.Axes.DESCENDANT);