本文整理了Java中org.xwiki.rendering.block.Block.getChildren()
方法的一些代码示例,展示了Block.getChildren()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.getChildren()
方法的具体详情如下:
包路径:org.xwiki.rendering.block.Block
类名称:Block
方法名:getChildren
[英]Gets all children blocks.
[中]获取所有子块。
代码示例来源:origin: org.xwiki.platform/xwiki-platform-dashboard-macro
private boolean isMacroMarkerBlockAndEmpty(Block block)
{
return block instanceof MacroMarkerBlock && block.getChildren().isEmpty();
}
}
代码示例来源: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-api
/**
* Removes any top level paragraph since for example for the following use case we don't want an extra paragraph
* block: <code>= hello {{velocity}}world{{/velocity}}</code>.
*
* @param blocks the blocks to check and convert
*/
public void removeTopLevelParagraph(List<Block> blocks)
{
// Remove any top level paragraph so that the result of a macro can be used inline for example.
// We only remove the paragraph if there's only one top level element and if it's a paragraph.
if ((blocks.size() == 1) && blocks.get(0) instanceof ParagraphBlock) {
Block paragraphBlock = blocks.remove(0);
blocks.addAll(0, paragraphBlock.getChildren());
}
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-wikimacro-store
/**
* Removes any top level paragraph since for example for the following use case we don't want an extra paragraph
* block: <code>= hello {{velocity}}world{{/velocity}}</code>.
*
* @param blocks the blocks to check and convert
*/
private Block removeTopLevelParagraph(Block block)
{
List<Block> blocks = block.getChildren();
// Remove any top level paragraph so that the result of a macro can be used inline for example.
// We only remove the paragraph if there's only one top level element and if it's a paragraph.
if ((block.getChildren().size() == 1) && block.getChildren().get(0) instanceof ParagraphBlock) {
Block paragraphBlock = blocks.remove(0);
blocks.addAll(0, paragraphBlock.getChildren());
return new CompositeBlock(blocks);
}
return block;
}
代码示例来源:origin: org.xwiki.rendering/xwiki-rendering-macro-toc
/**
* @param headerBlock the section title.
* @return the filtered label to use in toc anchor link.
*/
public List<Block> generateLabel(HeaderBlock headerBlock)
{
return headerBlock.clone(this).getChildren();
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-api
/**
* @param block the block to filter out
* @param blockClass the type of Blocks to look for
* @param recurse if true also search recursively children
* @param <T> the class of the Blocks to return
* @return the filtered blocks matching the passed Block class
*/
public <T extends Block> List<T> getChildrenByType(Block block, Class<T> blockClass, boolean recurse)
{
List<T> typedBlocks = new ArrayList<T>();
for (Block child : filter(block.getChildren())) {
if (blockClass.isAssignableFrom(child.getClass())) {
typedBlocks.add(blockClass.cast(child));
}
if (recurse && !child.getChildren().isEmpty()) {
typedBlocks.addAll(getChildrenByType(child, blockClass, true));
}
}
return typedBlocks;
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-officeimporter
/**
* Utility method for recursively traversing the XDOM and extracting a title.
*
* @param parent parent block.
* @return a title if found or null.
*/
private String getTitle(Block parent)
{
for (Block block : parent.getChildren()) {
if (block instanceof HeaderBlock) {
String title = renderTitle((HeaderBlock) block);
if (!StringUtils.isBlank(title)) {
return title;
}
} else if (block instanceof SectionBlock) {
return getTitle(block);
}
}
return null;
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-refactoring-api
Block firstBlock = block.getChildren().get(0);
if (firstBlock instanceof HeaderBlock) {
DocumentResourceReference reference = new DocumentResourceReference(target);
return new LinkBlock(clonedHeaderBlock.getChildren(), reference, false);
} else if (firstBlock instanceof SectionBlock) {
return createLink(firstBlock, target);
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-api
} else if (block.getClass() == LinkBlock.class && block.getChildren().size() == 0) {
ResourceReference reference = ((LinkBlock) block).getReference();
return this.plainTextParser.parse(new StringReader(label)).getChildren().get(0).getChildren();
} catch (ParseException e) {
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-macro-code
@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);
}
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-api
/**
* {@inheritDoc}
*
* @see org.xwiki.rendering.block.Block#getPreviousBlockByType(java.lang.Class, boolean)
*/
public <T extends Block> T getPreviousBlockByType(Class<T> blockClass, boolean recurse)
{
if (getParent() == null) {
return null;
}
int index = indexOfBlock(this, getParent().getChildren());
// test previous brothers
List<Block> blocks = getParent().getChildren();
for (int i = index - 1; i >= 0; --i) {
Block previousBlock = blocks.get(i);
if (blockClass.isAssignableFrom(previousBlock.getClass())) {
return blockClass.cast(previousBlock);
}
}
// test parent
if (blockClass.isAssignableFrom(getParent().getClass())) {
return blockClass.cast(getParent());
}
// recurse
return recurse ? getParent().getPreviousBlockByType(blockClass, true) : null;
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-wikimacro-store
private Block extractResult(Block block, Map<String, Object> macroContext, boolean async)
{
Object resultObject = macroContext.get(MACRO_RESULT_KEY);
Block result;
if (resultObject instanceof List) {
result = new CompositeBlock((List<Block>) resultObject);
} else if (resultObject instanceof Block) {
result = (Block) resultObject;
} else {
if (!async) {
// If synchronized the top level block is a temporary macro marker so we need to get rid of it
result = new CompositeBlock(block.getChildren());
} else {
result = block;
}
// If in inline mode remove any top level paragraph.
if (this.inline) {
result = removeTopLevelParagraph(result);
}
}
return result;
}
代码示例来源:origin: org.xwiki.platform/xwiki-core-rendering-api
filteredBlocks = clonedChildBlocks.getChildren();
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-macro-code
@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;
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-macro-code
blocks = listener.getBlocks();
} else {
blocks = this.plainTextParser.parse(new StringReader(code)).getChildren().get(0).getChildren();
代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core
int sectionLevel = header.getLevel().getAsInt();
for (int level = 1; level < sectionLevel && blocks.size() == 1 && blocks.get(0) instanceof SectionBlock; ++level) {
blocks = blocks.get(0).getChildren();
代码示例来源:origin: com.xpn.xwiki.platform/xwiki-core
public String extractTitle()
{
String title = "";
try {
if (is10Syntax()) {
title = extractTitle10();
} else {
List<HeaderBlock> blocks = getXDOM().getChildrenByType(HeaderBlock.class, true);
if (blocks.size() > 0) {
HeaderBlock header = blocks.get(0);
if (header.getLevel().compareTo(HeaderLevel.LEVEL2) <= 0) {
XDOM headerXDOM = new XDOM(Collections.<Block> singletonList(header));
// transform
TransformationContext context = new TransformationContext(headerXDOM, getSyntax());
Utils.getComponent(TransformationManager.class).performTransformations(headerXDOM, context);
// render
Block headerBlock = headerXDOM.getChildren().get(0);
if (headerBlock instanceof HeaderBlock) {
title = renderXDOM(new XDOM(headerBlock.getChildren()), Syntax.XHTML_1_0);
}
}
}
}
} catch (Exception e) {
// Don't stop when there's a problem rendering the title.
}
return title;
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-async-api
private Block tranform(XDOM xdom, Block block) throws RenderingException
{
TransformationContext transformationContext =
new TransformationContext(xdom, this.configuration.getDefaultSyntax(), false);
transformationContext.setTargetSyntax(this.configuration.getTargetSyntax());
transformationContext.setId(this.configuration.getTransformationId());
transform(block, transformationContext);
// The result is often inserted in a bigger content so we remove the XDOM around it
if (block instanceof XDOM) {
return new MetaDataBlock(block.getChildren(), ((XDOM) block).getMetaData());
}
return block;
}
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-rendering-wikimacro-store
@Override
public List<Block> execute(WikiMacroParameters parameters, String macroContent, MacroTransformationContext context)
throws MacroExecutionException
{
validate(parameters, macroContent);
// Create renderer
DefaultWikiMacroRenderer renderer;
try {
renderer = this.componentManager.getInstance(DefaultWikiMacroRenderer.class);
} catch (ComponentLookupException e) {
throw new MacroExecutionException("Failed to create wiki macro rendeder", e);
}
// Initialize the renderer
renderer.initialize(this, parameters, macroContent, context);
AsyncRendererConfiguration configuration = new AsyncRendererConfiguration();
configuration.setSecureReference(getDocumentReference(), getAuthorReference());
configuration.setContextEntries(this.contextEntries);
// Execute the renderer
Block result;
try {
result = this.executor.execute(renderer, configuration);
} catch (Exception e) {
throw new MacroExecutionException("Failed to execute wiki macro", e);
}
return result instanceof CompositeBlock ? result.getChildren() : Arrays.asList(result);
}
代码示例来源:origin: org.xwiki.platform/xwiki-platform-localization-macro
blocks = block.getChildren();
} else {
blocks = Arrays.asList(block);
内容来源于网络,如有侵权,请联系作者删除!