现在我们开始通过插件开发一个宏
1、首先我们打开atlassian-plugin.xml文件,添加下面这段代码
<xhtml-macro name="helloworld" class="com.atlassian.tutorial.macro.helloworld" key='helloworld-macro'>
<description key="helloworld.macro.desc"/>
<category name="formatting"/>
<parameter name="Color" type="enum">
<value name="red"/>
<value name="green"/>
<value name="blue"/>
</parameter>
</xhtml-macro>
2、打开/src/main/resources/myPlugin.properties文件添加下面代码
helloworld.macro.desc=Hello World
3、打开src/main/resources/css/myPlugin.css添加下面代码
.blue h1 { color: blue; }
.red h1 { color: red; }
.green h1 { color: green; }
4、新建Java类
package com.atlassian.tutorial.macro;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import java.util.Map;
public class helloworld implements Macro {
public String execute(Map<String, String> map, String s, ConversionContext conversionContext) throws MacroExecutionException {
String output = "<div class =\"helloworld\">";
output = output + "<div class = \"" + map.get("Color") + "\">";
if (map.get("Name") != null) {
output = output + ("<h1>Hello " + map.get("Name") + "!</h1>");
} else {
output = output + "<h1>Hello World!<h1>";
}
output = output + "</div>" + "</div>";
return output;
}
public BodyType getBodyType() { return BodyType.NONE; }
public OutputType getOutputType() { return OutputType.BLOCK; }
}
4、项目打包生成插件安装包,安装插件