/** * {@inheritDoc} * * @see org.xwiki.rendering.listener.Listener#endFormat(org.xwiki.rendering.listener.Format, java.util.Map) */ public void endFormat(Format format, Map<String, String> parameters) { this.stack.push(new FormatBlock(generateListFromStack(), format, parameters)); }
/** * {@inheritDoc} * * @see org.xwiki.rendering.block.AbstractFatherBlock#before(org.xwiki.rendering.listener.Listener) */ public void before(Listener listener) { listener.beginFormat(getFormat(), getParameters()); }
block = new FormatBlock(generateListFromStack(), convertFormat(styles.get(styles.size() - 1))); } else { block = new FormatBlock(generateListFromStack(), Format.NONE); ListIterator<WikiStyle> it = styles.listIterator(styles.size() - 1); while (it.hasPrevious()) { block = new FormatBlock(Arrays.asList((Block) block), convertFormat(it.previous())); block.setParameters(convertParameters(new WikiParameters(format.getParams()))); && (((FormatBlock) previous).getFormat() == block.getFormat()) && (((FormatBlock) previous).getParameters().equals(block.getParameters()))) { previous.addChildren(block.getChildren()); } else { this.stack.push(block);
@Override public void format(String tokenType, String value, Map<String, Object> style) { List<Block> blockList; if (StringUtils.isNotEmpty(value)) { try { blockList = this.plainTextParser.parse(new StringReader(value)).getChildren().get(0).getChildren(); } catch (ParseException e) { // This shouldn't happen since the parser cannot throw an exception since the source is a memory // String. throw new RuntimeException("Failed to parse [" + value + "] as plain text.", e); } String styleParameter = formatStyle(style); FormatBlock formatBlock = null; if (styleParameter.length() > 0) { formatBlock = new FormatBlock(blockList, Format.NONE); formatBlock.setParameter("style", styleParameter); this.blocks.add(formatBlock); } else { this.blocks.addAll(blockList); } } }
if (context.isInline()) { List<Block> contentBlocks = parseContent(parameters, content, context); FormatBlock spanBlock = new FormatBlock(contentBlocks, Format.NONE); spanBlock.setParameters(boxParameters); boxBlock = spanBlock; } else {
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); }
/** * {@inheritDoc} * * @see org.xwiki.rendering.block.AbstractFatherBlock#after(org.xwiki.rendering.listener.Listener) */ public void after(Listener listener) { listener.endFormat(getFormat(), getParameters()); } }
@Override protected List<Block> parseContent(CodeMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { List<Block> result; try { if (LANGUAGE_NONE.equalsIgnoreCase(parameters.getLanguage())) { if (StringUtils.isEmpty(content)) { result = Collections.emptyList(); } else { result = this.plainTextParser.parse(new StringReader(content)).getChildren().get(0).getChildren(); } } else { result = highlight(parameters, content); } } catch (Exception e) { throw new MacroExecutionException("Failed to highlight content", e); } Map<String, String> formatParameters = new LinkedHashMap<String, String>(); formatParameters.put("class", "code"); if (context.isInline()) { result = Arrays.<Block> asList(new FormatBlock(result, Format.NONE, formatParameters)); } else { result = Arrays.<Block> asList(new GroupBlock(result, formatParameters)); } return result; }
/** * Generate the footnote reference (link) that should be inserted at the location of the macro, and should point to * the actual footnote at the end of the document. * * @param counter the current footnote counter * @return the generated reference element, displayed as {@code (superscript(link(footnote index)))} */ private Block createFootnoteReferenceBlock(int counter) { Block result = new WordBlock(String.valueOf(counter)); DocumentResourceReference reference = new DocumentResourceReference(null); reference.setAnchor(FOOTNOTE_ID_PREFIX + counter); result = new LinkBlock(Collections.singletonList(result), reference, false); result = new FormatBlock(Collections.singletonList(result), Format.SUPERSCRIPT); result.setParameter(ID_ATTRIBUTE_NAME, FOOTNOTE_REFERENCE_ID_PREFIX + counter); result.setParameter(CLASS_ATTRIBUTE_NAME, "footnoteRef"); return result; }
@Override public Block execute(BlockAsyncRenderer renderer, AsyncRendererConfiguration configuration) throws JobException, RenderingException { // Start renderer execution if there is none already running/available AsyncRendererExecutorResponse response = this.executor.render(renderer, configuration); // Get result BlockAsyncRendererResult result = (BlockAsyncRendererResult) response.getStatus().getResult(); if (result != null) { return result.getBlock(); } // Return a placeholder waiting for the result Block placeholder; if (renderer.isInline()) { placeholder = new FormatBlock(); } else { placeholder = new GroupBlock(); } placeholder.setParameter("class", "xwiki-async"); // Provide it directly as it's going to be used in the client side (the URL fragment to use in the ajax request) placeholder.setParameter("data-xwiki-async-id", response.getJobIdHTTPPath()); placeholder.setParameter("data-xwiki-async-client-id", response.getAsyncClientId().toString()); return placeholder; } }