很基本的想法,当有人访问该页面时,我想显示一个弹出窗口。我已经编写了示例代码。
实际上,我想做的是创建一个具有主体的Macro-type插件,以便我们可以在其中添加文本,链接和其他元素,并在弹出窗口中显示它们。

这是我访问页面但选择“ PLAIN_TEXT”作为“ getBodyType()”时能够显示弹出窗口的代码。它显示未格式化的文本,当我选择“ RICH_TEXT”时,它什么也没有显示。请帮忙!

package com.elixir;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.content.render.xhtml.XhtmlException;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.confluence.xhtml.api.MacroDefinition;
import com.atlassian.confluence.xhtml.api.MacroDefinitionHandler;
import com.atlassian.confluence.xhtml.api.XhtmlContent;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MyMacro implements Macro
{
    private final XhtmlContent xhtmlUtils;

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

    @Override
    public BodyType getBodyType()
    {
        return BodyType.RICH_TEXT;
    }

    @Override
    public OutputType getOutputType()
    {
        return OutputType.BLOCK;
    }

    @Override
    public String execute(Map<String, String> parameters, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException
    {
        String body = conversionContext.getEntity().getBodyAsString();

        final List<MacroDefinition> macros = new ArrayList<MacroDefinition>();

        try
        {
            xhtmlUtils.handleMacroDefinitions(body, conversionContext, new MacroDefinitionHandler()
            {
                @Override
                public void handle(MacroDefinition macroDefinition)
                {
                    macros.add(macroDefinition);
                }
            });
        }
        catch (XhtmlException e)
        {
            throw new MacroExecutionException(e);
        }

        StringBuilder builder = new StringBuilder();
        if (!macros.isEmpty())
        {
            for (MacroDefinition defn : macros) {
                builder.append("<script>AJS.$(document).ready(function() {var popup2 = AJS.popup({width:400, height:200, id:'my-popup2', closeOnOutsideClick: true});");
                builder.append("$('#my-popup2').css({padding:4});$('#my-popup2').html(\"").append(defn.getBody()).append("\");");
                builder.append("popup2.show();});</script>");

            }
        }
        else
        {
            builder.append("Body not defined");
        }

        return builder.toString();
    }
}

最佳答案

我认为您需要hasBody='true'bodyType='raw'bodyType='rendered',以及outputType='html'outputType='wiki'

这是如何实施此解决方案的示例:
https://answers.atlassian.com/questions/93630/user-macro-module-body-parameter

10-07 19:23
查看更多