/** * 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()); }
/** * {@inheritDoc} * * @see org.xwiki.rendering.listener.Listener#onMacro(java.lang.String, java.util.Map, java.lang.String, boolean) */ public void onMacro(String id, Map<String, String> macroParameters, String content, boolean isInline) { this.stack.push(new MacroBlock(id, macroParameters, content, 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); }
new MacroMarkerBlock(wikiMacroBlock.getId(), wikiMacroBlock.getParameters(), wikiMacroBlock.getContent(), macroXDOM.getChildren(), wikiMacroBlock.isInline()); wikiMacroBlock.getParent().replaceChild(syncMetaDataBlock, wikiMacroBlock); wikiMacroBlock.setParent(syncMetaDataBlock.getParent()); wikiMacroBlock.setNextSiblingBlock(syncMetaDataBlock.getNextSibling()); wikiMacroBlock.setPreviousSiblingBlock(syncMetaDataBlock.getPreviousSibling());
public List<String> getIncludedPages(XWikiContext context) { if (is10Syntax()) { return getIncludedPagesForXWiki10Syntax(getContent(), context); } else { // Find all include macros listed on the page XDOM dom = getXDOM(); List<String> result = new ArrayList<String>(); for (MacroBlock macroBlock : dom.getChildrenByType(MacroBlock.class, true)) { // - Add each document pointed to by the include macro // - Also add all the included pages found in the velocity macro when using the deprecated #include* // macros // This should be removed when we fully drop support for the XWiki Syntax 1.0 but for now we want to // play // nice with people migrating from 1.0 to 2.0 syntax if (macroBlock.getId().equalsIgnoreCase("include")) { String documentName = macroBlock.getParameters().get("document"); if (documentName.indexOf('.') == -1) { documentName = getSpace() + "." + documentName; } result.add(documentName); } else if (macroBlock.getId().equalsIgnoreCase("velocity") && !StringUtils.isEmpty(macroBlock.getContent())) { // Try to find matching content inside each velocity macro result.addAll(getIncludedPagesForXWiki10Syntax(macroBlock.getContent(), context)); } } return result; } }
/** * Method to overwrite to indicate the script engine name. * * @param parameters the macro parameters. * @param context the context of the macro transformation. * @return the name of the script engine to use. */ protected String getScriptEngineName(P parameters, MacroTransformationContext context) { return context.getCurrentMacroBlock().getId().toLowerCase(); }
String id = macro.getId(); if ("include".equals(id)) String includedId = macro.getParameter("document"); String syntaxId = macro.getParameter("syntax"); if (syntaxId == null)
MacroMarkerBlock parent = context.getCurrentMacroBlock().getFirstBlock( new ClassBlockMatcher(MacroMarkerBlock.class), Block.Axes.ANCESTOR); while (parent != null) { context.getCurrentMacroBlock().getId(), extractSourceContentReference(context.getCurrentMacroBlock()), parentId, extractSourceContentReference(parent)));
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);
resolvedRootBlock = context.getCurrentMacroBlock().getParent(); } else { resolvedRootBlock = context.getXDOM(); SectionBlock rootSection = context.getCurrentMacroBlock().getFirstBlock( new ClassBlockMatcher(SectionBlock.class), Block.Axes.ANCESTOR); if (rootSection != null) {
@Override public Syntax getCurrentSyntax(MacroTransformationContext context) { Syntax currentSyntax = context.getSyntax(); MacroBlock currentMacroBlock = context.getCurrentMacroBlock(); if (currentMacroBlock != null) { MetaDataBlock metaDataBlock = currentMacroBlock.getFirstBlock(new MetadataBlockMatcher(MetaData.SYNTAX), Axes.ANCESTOR_OR_SELF); if (metaDataBlock != null) { currentSyntax = (Syntax) metaDataBlock.getMetaData().getMetaData(MetaData.SYNTAX); } } return currentSyntax; } }
/** * Method to overwrite to indicate the script engine name. * * @param parameters the macro parameters. * @param context the context of the macro transformation. * @return the name of the script engine to use. */ protected String getScriptEngineName(P parameters, MacroTransformationContext context) { return context.getCurrentMacroBlock().getId().toLowerCase(); }
if ("include".equals(macroBlock.getId())) { String documentName = macroBlock.getParameter("document"); if (documentName != null) {
.getFirstBlock(new MetadataBlockMatcher(MetaData.SOURCE), Axes.ANCESTOR_OR_SELF); if (metaDataBlock != null) { scriptContext.setAttribute(ScriptEngine.FILENAME, metaDataBlock.getMetaData().getMetaData(MetaData.SOURCE),
/** * 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()); }
@Override protected String getScriptEngineName(DefaultScriptMacroParameters parameters, MacroTransformationContext context) { String engineName; if (this.language == null) { String macroName = context.getCurrentMacroBlock().getId().toLowerCase(); if ("script".equals(macroName)) { engineName = parameters.getLanguage(); } else { engineName = macroName; } } else { engineName = this.language; } return engineName; } }
/** * 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); }
/** * @see #onMacroBlock(String, org.wikimodel.wem.WikiParameters, String) */ public void onMacroInline(String macroName, WikiParameters params, String content) { this.stack.push(new MacroBlock(macroName, convertParameters(params), content, true)); }
/** * 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()); } }
/** * {@inheritDoc} * * @see org.xwiki.rendering.macro.script.AbstractJSR223ScriptMacro#getScriptEngineName(org.xwiki.rendering.macro.script.JSR223ScriptMacroParameters, * org.xwiki.rendering.transformation.MacroTransformationContext) */ @Override protected String getScriptEngineName(DefaultScriptMacroParameters parameters, MacroTransformationContext context) { String engineName; if (this.language == null) { String macroName = context.getCurrentMacroBlock().getId().toLowerCase(); if ("script".equals(macroName)) { engineName = parameters.getLanguage(); } else { engineName = macroName; } } else { engineName = this.language; } return engineName; } }