Atlassian Confluence:访问页面时将显示弹出窗口的宏类型插件

问题描述 投票:0回答:2

非常基本的想法,我想在有人访问页面时显示一个弹出窗口。我写了一个示例代码。 实际上我想做的是创建一个宏类型插件,它有一个主体,这样我们就可以向其中添加文本、链接和不同的元素,它会在弹出窗口中显示它们。

这是我能够在访问页面时显示弹出窗口的代码,但当我选择“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();
    }
}
java jquery macros confluence atlassian-plugin-sdk
2个回答
2
投票

我认为您需要

hasBody='true'
bodyType='raw'
bodyType='rendered'
,以及
outputType='html'
outputType='wiki'

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


0
投票

嗨@mohsin Javed Cheema,

您能帮忙分享一下这个宏的 atlassian-plugin.xml 文件内容吗?我正在尝试开发类似的宏。

© www.soinside.com 2019 - 2024. All rights reserved.