如何在汇合宏中呈现页面的所有子内容

问题描述 投票:1回答:1

我正在尝试构建一个简单的confluence宏,它呈现当前父级的所有子页面。基本上是现有宏之间的交叉:子显示和包含页面。我确实看了一下这些宏的source code,但由于这是我第一次在汇合中进行开发,所以它更令人困惑而不是有用。

现在我正在研究执行方法,因为我是汇合开发的新手,所以我不确定100%究竟需要去那里。

我已经阅读了Atlassian's Guide to Making a new Confluence Macro,但似乎他们只是使用html来包装现有宏的属性列表。

所以我决定看看API,特别是Page我能够非常接近,问题是,当我复制页面的身体时,我没有得到他们页面中的孩子的宏和样式。

    @Override
    public String execute(Map<String, String> parameters, String body,
            ConversionContext context) throws MacroExecutionException {
        //loop through each child page and get its content
        StringBuilder sb = new StringBuilder();
        ContentEntityObject ceo = context.getPageContext().getEntity();
        Page parent =(Page) ceo ;
        List<Page> children = parent.getChildren();

        for(Page child:children)

        {
          sb.append(child.getBodyAsString());
        }

        return sb.toString();
    }

我如何获得所有这些不仅仅是文本?

我也用java标记这个,因为这是插件的编写内容。

java confluence atlassian-plugin-sdk
1个回答
5
投票

我们去了,我想通了。

我需要将它从存储格式转换为视图格式,以便渲染宏。

{

  String converted = xhtmlUtils.convertStorageToView(child.getBodyAsString(), context);
  sb.append(converted);

}

如果您正在学习本教程,则会在构造函数中初始化xhtmlUtils

private final XhtmlContent xhtmlUtils;

public ExampleMacro(XhtmlContent xhtmlUtils) 
{
    this.xhtmlUtils = xhtmlUtils;   
}

我还根据Atlassian answers的建议添加了注释

@RequiresFormat(Format.Storage)
public String execute(Map<String, String> params, String body, ConversionContext conversionContext) throws MacroExecutionException {

其中Format和RequiresFormat是这些类/注释

import com.atlassian.confluence.content.render.xhtml.macro.annotation.Format;
import com.atlassian.confluence.content.render.xhtml.macro.annotation.RequiresFormat
© www.soinside.com 2019 - 2024. All rights reserved.