gpt4 book ai didi

java - Atlassian 合流 : Macro type plugin that will display a popup window when the page is accessed

转载 作者:行者123 更新时间:2023-11-30 09:26:22 24 4
gpt4 key购买 nike

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

这是我能够在访问页面时显示弹出窗口的代码,但是当我选择“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

关于java - Atlassian 合流 : Macro type plugin that will display a popup window when the page is accessed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14952232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com