org.xwiki.rendering.block.Block.getChildrenByType()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中org.xwiki.rendering.block.Block.getChildrenByType()方法的一些代码示例,展示了Block.getChildrenByType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getChildrenByType()方法的具体详情如下:
包路径:org.xwiki.rendering.block.Block
类名称:Block
方法名:getChildrenByType

Block.getChildrenByType介绍

[英]Gets all the Blocks in the tree which are of the passed Block class.
[中]获取树中属于传递的块类的所有块。

代码示例

代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-api

/**
 * {@inheritDoc}
 *
 * @see org.xwiki.rendering.block.Block#getChildrenByType(java.lang.Class, boolean)
 */
public <T extends Block> List<T> getChildrenByType(Class<T> blockClass, boolean recurse)
{
  List<T> typedBlocks = new ArrayList<T>();
  for (Block block : getChildren()) {
    if (blockClass.isAssignableFrom(block.getClass())) {
      typedBlocks.add(blockClass.cast(block));
    }
    if (recurse && !block.getChildren().isEmpty()) {
      typedBlocks.addAll(block.getChildrenByType(blockClass, true));
    }
  }
  return typedBlocks;
}

代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-transformation-macro

/**
 * {@inheritDoc}
 * 
 * @see org.xwiki.rendering.transformation.Transformation#transform(org.xwiki.rendering.block.Block,
 *      org.xwiki.rendering.transformation.TransformationContext)
 */
public void transform(Block rootBlock, TransformationContext context) throws TransformationException
{
  // Create a macro execution context with all the information required for macros.
  MacroTransformationContext macroContext = new MacroTransformationContext(context);
  macroContext.setTransformation(this);
  // Counter to prevent infinite recursion if a macro generates the same macro for example.
  int executions = 0;
  List<MacroBlock> macroBlocks = rootBlock.getChildrenByType(MacroBlock.class, true);
  while (!macroBlocks.isEmpty() && executions < this.maxMacroExecutions) {
    transformOnce(rootBlock, macroContext, context.getSyntax());
    // TODO: Make this less inefficient by caching the blocks list.
    macroBlocks = rootBlock.getChildrenByType(MacroBlock.class, true);
    executions++;
  }
}

代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-transformation-macro

/**
 * @return the macro with the highest priority for the passed syntax or null if no macro is found
 */
private MacroHolder getHighestPriorityMacro(Block rootBlock, Syntax syntax)
{
  List<MacroHolder> macroHolders = new ArrayList<MacroHolder>();
  // 1) Sort the macros by priority to find the highest priority macro to execute
  for (MacroBlock macroBlock : rootBlock.getChildrenByType(MacroBlock.class, true)) {
    try {
      Macro< ? > macro = this.macroManager.getMacro(new MacroId(macroBlock.getId(), syntax));
      macroHolders.add(new MacroHolder(macro, macroBlock));
    } catch (MacroLookupException e) {
      // Macro cannot be found. Generate an error message instead of the macro execution result.
      // TODO: make it internationalized
      generateError(macroBlock, "Unknown macro: " + macroBlock.getId(), "The \"" + macroBlock.getId()
        + "\" macro is not in the list of registered macros. Verify the "
        + "spelling or contact your administrator.");
      getLogger().debug("Failed to locate the [" + macroBlock.getId() + "] macro. Ignoring it.");
    }
  }
  // Sort the Macros by priority
  Collections.sort(macroHolders);
  return macroHolders.size() > 0 ? macroHolders.get(0) : null;
}

相关文章