Search in sources :

Example 1 with Type

use of org.xwiki.formula.FormulaRenderer.Type in project xwiki-platform by xwiki.

the class FormulaMacro method execute.

@Override
public List<Block> execute(FormulaMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
    if (StringUtils.isEmpty(content)) {
        throw new MacroExecutionException(CONTENT_MISSING_ERROR);
    }
    String rendererHint = this.configuration.getRenderer();
    FontSize size = parameters.getFontSize();
    Type type = parameters.getImageType();
    Block result;
    try {
        result = render(content, context.isInline(), size, type, rendererHint);
    } catch (MacroExecutionException ex) {
        this.logger.debug("Failed to render content with the [{}] renderer. Falling back to the safe renderer.", rendererHint, ex);
        try {
            result = render(content, context.isInline(), size, type, this.configuration.getSafeRenderer());
        } catch (IllegalArgumentException ex2) {
            throw new MacroExecutionException(WRONG_CONTENT_ERROR);
        }
    } catch (IllegalArgumentException ex) {
        throw new MacroExecutionException(WRONG_CONTENT_ERROR);
    }
    // If no image was generated, just return the original text
    if (result == null) {
        result = new WordBlock(content);
    }
    // Block level formulae should be wrapped in a paragraph element
    if (!context.isInline()) {
        result = new ParagraphBlock(Collections.<Block>singletonList(result));
    }
    return Collections.singletonList(result);
}
Also used : Type(org.xwiki.formula.FormulaRenderer.Type) ResourceType(org.xwiki.rendering.listener.reference.ResourceType) FontSize(org.xwiki.formula.FormulaRenderer.FontSize) WordBlock(org.xwiki.rendering.block.WordBlock) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) Block(org.xwiki.rendering.block.Block) ImageBlock(org.xwiki.rendering.block.ImageBlock) WordBlock(org.xwiki.rendering.block.WordBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock)

Aggregations

FontSize (org.xwiki.formula.FormulaRenderer.FontSize)1 Type (org.xwiki.formula.FormulaRenderer.Type)1 Block (org.xwiki.rendering.block.Block)1 ImageBlock (org.xwiki.rendering.block.ImageBlock)1 ParagraphBlock (org.xwiki.rendering.block.ParagraphBlock)1 WordBlock (org.xwiki.rendering.block.WordBlock)1 ResourceType (org.xwiki.rendering.listener.reference.ResourceType)1 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)1