/** * {@inheritDoc} * * @see org.xwiki.rendering.transformation.TransformationManager#performTransformations(org.xwiki.rendering.block.XDOM, * org.xwiki.rendering.syntax.Syntax) */ public void performTransformations(XDOM dom, Syntax syntax) throws TransformationException { performTransformations(dom, new TransformationContext(dom, syntax)); }
/** * Calls transformInContext on renderingContext. */ private void performTransformation(MutableRenderingContext renderingContext, Transformation transformation, TransformationContext context, Block block) throws MacroExecutionException { try { renderingContext.transformInContext(transformation, context, block); } catch (Exception e) { throw new MacroExecutionException("Failed to perform transformation", e); } }
/** * {@inheritDoc} * * @see org.xwiki.rendering.transformation.TransformationManager#performTransformations(org.xwiki.rendering.block.Block, * org.xwiki.rendering.transformation.TransformationContext) */ public void performTransformations(Block block, TransformationContext context) throws TransformationException { boolean error = false; for (Transformation transformation : this.configuration.getTransformations()) { try { transformation.transform(block, context); } catch (Exception e) { // Continue running the other transformations getLogger().error("Failed to execute transformation", e); error = true; } } if (error) { throw new TransformationException("One or several transformations failed to execute properly. " + "See the logs for details."); } } }
PriorityMacroBlockMatcher priorityMacroBlockMatcher = new PriorityMacroBlockMatcher(context.getSyntax()); rootBlock.getFirstBlock(priorityMacroBlockMatcher, Block.Axes.DESCENDANT); if (priorityMacroBlockMatcher.getErrors() != null) { for (MacroLookupExceptionElement error : priorityMacroBlockMatcher.getErrors()) { if (error.getException() instanceof MacroNotFoundException) { this.macroErrorManager.generateError(error.getMacroBlock(), String.format("Unknown macro: %s.", error.getMacroBlock().getId()), String.format( "The \"%s\" macro is not in the list of registered macros. Verify the spelling or " + "contact your administrator.", error.getMacroBlock().getId())); } else { this.macroErrorManager.generateError(error.getMacroBlock(), String.format("Invalid macro: %s", error.getMacroBlock().getId()), error.getException()); MacroBlock macroBlock = priorityMacroBlockMatcher.getBlock(); Macro<?> macro = priorityMacroBlockMatcher.getBlockMacro(); this.macroErrorManager.generateError(macroBlock, String.format( "The [%s] macro is a standalone macro and it cannot be used inline", macroBlock.getId()), ((MutableRenderingContext) this.renderingContext).setCurrentBlock(macroBlock); this.macroErrorManager.generateError(macroBlock, String.format("Invalid macro parameters used for the \"%s\" macro", macroBlock.getId()), e); continue;
private String convert(String source, String sourceSyntaxId, String targetSyntaxId) throws Exception { String result; ExecutionContext executionContext = new ExecutionContext(); ExecutionContextManager executionContextManager = componentManager.getInstance(ExecutionContextManager.class); executionContextManager.initialize(executionContext); // Set TargetSyntax for Macro tests RenderingContext renderingContext = componentManager.getInstance(RenderingContext.class); ((MutableRenderingContext) renderingContext).push(renderingContext.getTransformation(), renderingContext.getXDOM(), renderingContext.getDefaultSyntax(), renderingContext.getTransformationId(), renderingContext.isRestricted(), Syntax.valueOf(targetSyntaxId)); try { if (isStreamingTest(sourceSyntaxId, targetSyntaxId)) { StreamParser parser = getComponentManager().getInstance(StreamParser.class, sourceSyntaxId); PrintRendererFactory rendererFactory = getComponentManager().getInstance(PrintRendererFactory.class, targetSyntaxId); result = convert(source, parser, rendererFactory); } else { Parser parser = getComponentManager().getInstance(Parser.class, sourceSyntaxId); BlockRenderer blockRenderer = getComponentManager().getInstance(BlockRenderer.class, targetSyntaxId); result = convert(source, parser, blockRenderer); } } finally { ((MutableRenderingContext) renderingContext).pop(); Execution execution = componentManager.getInstance(Execution.class); execution.removeContext(); } return result; }
protected void transform(Block block, TransformationContext transformationContext) throws TransformationException { if (isAsyncAllowed() || isCacheAllowed()) { this.transformationManager.performTransformations(block, transformationContext); } else { ((MutableRenderingContext) this.renderingContext).transformInContext(this.macroTransformation, transformationContext, block); } } }
((MutableRenderingContext) renderingContext).push(renderingContext.getTransformation(), renderingContext.getXDOM(), streamParser.getSyntax(), renderingContext.getTransformationId(), renderingContext.isRestricted(), getRendererSyntax()); ((MutableRenderingContext) renderingContext).pop(); Execution execution = componentManager.getInstance(Execution.class); execution.removeContext();
TransformationContext transformationContext = new TransformationContext(transformedXDOM, syntax); transformationContext.setId(method.getClass().getName() + "#" + method.getName()); ((MutableRenderingContext) renderingContext).transformInContext(macroTransformation, transformationContext, transformedXDOM); } catch (TransformationException e) {
((MutableRenderingContext) this.renderingContext).transformInContext(transformation, context.getTransformationContext(), htmlMacroMarker); } finally {