Confluence 插件开发入门 <二>

现在我们开始通过插件开发一个宏

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、项目打包生成插件安装包,安装插件

57a6f7daf6d88593fdad84764023f37bdda.jpg

e8b27ee42b7e965bf7aca85f7207566a113.jpg

插件项目地址 https://gitee.com/dushougudu/myPlugin

转载于:https://my.oschina.net/dushougudu/blog/1835393

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值