@Override protected TableBlock getTableBlock(String macroContent, MacroTransformationContext context) throws MacroExecutionException { XDOM xdom = computeXDOM(context); // Find the correct table block. List<TableBlock> tableBlocks = xdom.getBlocks(new ClassBlockMatcher(TableBlock.class), Block.Axes.DESCENDANT); TableBlock result = null; this.logger.debug("Table id is [{}], there are [{}] tables in the document [{}]", new Object[]{this.tableId, tableBlocks.size(), this.documentReference}); if (null != tableId) { for (TableBlock tableBlock : tableBlocks) { String id = tableBlock.getParameter("id"); if (null != id && id.equals(this.tableId)) { result = tableBlock; break; } } } else { result = (tableBlocks.size() > 0) ? tableBlocks.get(0) : null; } if (null == result) { throw new MacroExecutionException("Unable to find a matching data table."); } return result; }
@Override protected TableBlock getTableBlock(String macroContent, MacroTransformationContext context) throws MacroExecutionException { // Since we are using an inline source the macro content cannot be empty/null. if (StringUtils.isEmpty(macroContent)) { throw new MacroExecutionException("A Chart Macro using an inline source must have a data table defined in " + "its content."); } // Parse the macro content into an XDOM. XDOM xdom = this.macroContentParser.parse(macroContent, context, true, false); // Take the first TableBlock found in the macro content. List<TableBlock> tableBlocks = xdom.getBlocks(new ClassBlockMatcher(TableBlock.class), Block.Axes.DESCENDANT); if (tableBlocks.size() == 0) { throw new MacroExecutionException("Unable to locate a suitable data table."); } return tableBlocks.get(0); } }
/** * Looks for document fragments in the given documents. A document fragment is identified by an {@link IdBlock} for * instance. * * @param documents the list of documents whose fragments to collect * @return the collection of document fragments mapped to the document that contains them */ private Map<String, String> collectDocumentFragments(List<WikiDocument> documents) { Map<String, String> fragments = new HashMap<String, String>(); for (WikiDocument document : documents) { for (IdBlock idBlock : document.getXdom().<IdBlock> getBlocks(new ClassBlockMatcher(IdBlock.class), Axes.DESCENDANT)) { fragments.put(idBlock.getName(), document.getFullName()); } } return fragments; } }
/** * @param xdom the XDOM on which to check if there's a macro error * @return true if the passed XDOM contains a macro error or false otherwise */ public boolean containsError(XDOM xdom) { boolean foundError = false; List<Block> groupAndFormatBlocks = xdom.getBlocks( new OrBlockMatcher( new ClassBlockMatcher(GroupBlock.class), new ClassBlockMatcher(FormatBlock.class)), Block.Axes.DESCENDANT); for (Block block : groupAndFormatBlocks) { String classParameter = block.getParameters().get(ErrorBlockGenerator.CLASS_ATTRIBUTE_NAME); if (classParameter != null && classParameter.contains(ErrorBlockGenerator.CLASS_ATTRIBUTE_MESSAGE_VALUE)) { foundError = true; break; } } return foundError; }
List<ImageBlock> imgBlocks = xdom.getBlocks(new ClassBlockMatcher(ImageBlock.class), Block.Axes.DESCENDANT); for (ImageBlock imgBlock : imgBlocks) { String imageReference = imgBlock.getReference().getReference();
/** * @param document the document whose anchors to update * @param fragments see {@link #collectDocumentFragments(List)} */ private void updateAnchors(WikiDocument document, Map<String, String> fragments) { for (LinkBlock linkBlock : document.getXdom().<LinkBlock> getBlocks(new ClassBlockMatcher(LinkBlock.class), Axes.DESCENDANT)) { ResourceReference reference = linkBlock.getReference(); ResourceType resoureceType = reference.getType(); String fragment = null; if (isDocument(resoureceType) && StringUtils.isEmpty(reference.getReference())) { fragment = reference.getParameter(ANCHOR_PARAMETER); } else if (StringUtils.startsWith(reference.getReference(), "#") && (ResourceType.PATH.equals(resoureceType) || ResourceType.URL.equals(resoureceType))) { fragment = reference.getReference().substring(1); } String targetDocument = fragments.get(fragment); if (targetDocument != null && !targetDocument.equals(document.getFullName())) { // The fragment has been moved so we need to update the link. reference.setType(ResourceType.DOCUMENT); reference.setReference(targetDocument); reference.setParameter(ANCHOR_PARAMETER, fragment); } } }
document.getXDOM().getBlocks(new ClassBlockMatcher(HeaderBlock.class), Block.Axes.DESCENDANT); if (!blocks.isEmpty()) { HeaderBlock heading = blocks.get(0);
List<MacroBlock> macros = xdom.getBlocks(MACROBLOCKMATCHER, Axes.DESCENDANT); for (MacroBlock macro : macros) { if ("html".equals(macro.getId())) {