/** * {@inheritDoc} * * @see org.xwiki.rendering.listener.Listener#endGroup(java.util.Map) */ public void endGroup(Map<String, String> parameters) { this.stack.push(new GroupBlock(generateListFromStack(), parameters)); }
GroupBlock contentGroup = new GroupBlock(); contentGroup.setParameter(CLASS, "gadget-content"); contentGroup.addChildren(gadget.getContent()); GroupBlock gadgetBlock = new GroupBlock(); String idPrefix = "gadget"; gadgetBlock.setParameter(CLASS, idPrefix); gadgetBlock.setParameter(ID, idPrefix + "_" + gadget.getId()); gadgetBlock.addChild(titleBlock); gadgetBlock.addChild(contentGroup);
GroupBlock metadataBlock = new GroupBlock(); metadataBlock.setParameter(CLASS, METADATA); GroupBlock isMacroBlock = new GroupBlock(); isMacroBlock.setParameter(CLASS, "isMacro"); isMacroBlock.addChild(new WordBlock(Boolean.toString(isMacro))); metadataBlock.addChild(isMacroBlock); GroupBlock renderedContentBlock = new GroupBlock(); renderedContentBlock.setParameter(CLASS, "content"); WikiPrinter printer = new DefaultWikiPrinter(); BlockRenderer gadgetContentRenderer = getGadgetContentRenderer(); gadgetContentRenderer.render(gadget.getContent(), printer); RawBlock rawBlock = new RawBlock(printer.toString(), getRawBlockSyntax(gadgetContentRenderer)); renderedContentBlock.addChild(rawBlock); GroupBlock gadgetTitleBlock = new GroupBlock(); gadgetTitleBlock.setParameter(CLASS, "title"); gadgetTitleBlock.addChild(new WordBlock(gadget.getTitleSource())); metadataBlock.addChild(renderedContentBlock); metadataBlock.addChild(gadgetTitleBlock);
String oldClass = column.getParameter(CLASS_ATTRIBUTE); column.setParameter(CLASS_ATTRIBUTE, (StringUtils.isEmpty(oldClass) ? classValue : oldClass + " " + classValue)); String newClass = "container-columns container-columns-" + count; container.setParameter(CLASS_ATTRIBUTE, StringUtils.isEmpty(oldClass) ? newClass : oldClass + " " + newClass); container.addChild(new GroupBlock(clearFloatsParams));
@Override public List<Block> execute(P parameters, String content, MacroTransformationContext context) throws MacroExecutionException { // TODO: include here container CSS. FTM the only rule, the one about justified text, is in the columns.css, in // which case the justification makes the most sense. // transform the container in a group, with appropriate parameters Map<String, String> containerParameters = new HashMap<String, String>(); if (parameters.isJustify()) { containerParameters.put(CLASS_ATTRIBUTE, "container-justified"); } // create the root block for the container macro, as a group block, and add all the blocks resulted from parsing // its content GroupBlock containerRoot = new GroupBlock(containerParameters); containerRoot.addChildren(getContent(parameters, content, context)); // grab the layout manager to layout this container LayoutManager layoutManager = getLayoutManager(parameters.getLayoutStyle()); // if a suitable layout manager was found, layout this container if (layoutManager != null) { layoutManager.layoutContainer(containerRoot); } // add the css class, if any, to the container root if (StringUtils.isNotEmpty(parameters.getCssClass())) { containerRoot.setParameter(CLASS_ATTRIBUTE, parameters.getCssClass()); } // and finally return the styled container root return Collections.<Block> singletonList(containerRoot); }
GroupBlock gContainer = new GroupBlock(); gContainer.setParameter(CLASS, DashboardMacro.GADGET_CONTAINER); gContainer.setParameter(ID, DashboardMacro.GADGET_CONTAINER_PREFIX + (i + 1)); gadgetContainers.add(gContainer);
GroupBlock topLevel = new GroupBlock(); topLevel.addChildren(this.gadgetSource.getDashboardSourceMetadata(parameters.getSource(), context)); topLevel.addChildren(layoutedResult); topLevel.setParameter("class", MACRO_NAME + (StringUtils.isEmpty(parameters.getStyle()) ? "" : " " + parameters.getStyle()));
GroupBlock metadataContainer = new GroupBlock(); metadataContainer.setParameter(classParameterName, DashboardMacro.METADATA); new LinkBlock(Collections.<Block> emptyList(), new ResourceReference(editURL, ResourceType.URL), false); editURLBlock.setParameter(classParameterName, DashboardMacro.EDIT_URL); metadataContainer.addChild(editURLBlock); String removeURL = xContext.getWiki().getURL(sourceDoc, "objectremove", "", "", xContext); LinkBlock removeURLBlock = new LinkBlock(Collections.<Block> emptyList(), new ResourceReference(removeURL, ResourceType.URL), false); removeURLBlock.setParameter(classParameterName, DashboardMacro.REMOVE_URL); metadataContainer.addChild(removeURLBlock); String addURL = xContext.getWiki().getURL(sourceDoc, "objectadd", "", "", xContext); LinkBlock addURLBlock = new LinkBlock(Collections.<Block> emptyList(), new ResourceReference(addURL, ResourceType.URL), false); addURLBlock.setParameter(classParameterName, DashboardMacro.ADD_URL); metadataContainer.addChild(addURLBlock); GroupBlock sourcePageBlock = new GroupBlock(); sourcePageBlock.addChild(new WordBlock(sourceDoc.getName())); sourcePageBlock.setParameter(classParameterName, DashboardMacro.SOURCE_PAGE); metadataContainer.addChild(sourcePageBlock); GroupBlock sourceSpaceBlock = new GroupBlock(); sourceSpaceBlock.addChild(new WordBlock( this.localReferenceSerializer.serialize(sourceDoc.getLastSpaceReference()))); sourceSpaceBlock.setParameter(classParameterName, DashboardMacro.SOURCE_SPACE); metadataContainer.addChild(sourceSpaceBlock); GroupBlock sourceWikiBlock = new GroupBlock(); sourceWikiBlock.addChild(new WordBlock(sourceDoc.getWikiReference().getName()));
public void endDocument(WikiParameters params) { // Close sections int sectionLevel = this.currentSectionLevel.peek(); for (; sectionLevel > 0; --sectionLevel) { this.stack.push(new SectionBlock(generateListFromStack())); } --this.documentLevel; this.currentSectionLevel.pop(); if (this.documentLevel > 0) { this.stack.push(new GroupBlock(generateListFromStack(), convertParameters(params))); } }
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); }
@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; }
Block galleryBlock = new GroupBlock(groupParameters);
@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; } }
boxBlock = spanBlock; } else { boxBlock = new GroupBlock(boxParameters);
return context.isInline() ? result : Collections.singletonList(new GroupBlock(result));
blocks = Arrays.<Block> asList(new GroupBlock(blocks));