文章目录
https://my.oschina.net/u/1864677/blog/4333480 https://developer.atlassian.com/server/framework/atlassian-sdk/create-a-confluence-hello-world-macro/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| package com.example.plugin;
import com.atlassian.confluence.content.render.xhtml.ConversionContext; import com.atlassian.confluence.macro.Macro; import com.atlassian.confluence.macro.MacroExecutionException; import com.atlassian.plugin.spring.scanner.annotation.component.ConfluenceComponent; import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport; import com.atlassian.webresource.api.assembler.PageBuilderService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired;
import java.util.Map;
@ConfluenceComponent public class Helloworld implements Macro { private PageBuilderService pageBuilderService;
@Autowired public Helloworld(@ComponentImport PageBuilderService pageBuilderService) { this.pageBuilderService = pageBuilderService; }
@Override public String execute(Map<String, String> map, String s, ConversionContext conversionContext) throws MacroExecutionException { pageBuilderService.assembler().resources().requireWebResource("com.example.plugin.hello-demo:hello-demo-resources");
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>";
if(s!=null && s.length()>0){ output = "<div id='myCanvas'></div>"; output +="<script type=\"text/javascript\">"; output +="var c=document.getElementById('myCanvas');"; output +="var umlText = \"" + parse(s) + "\";"; output +="\nvar uml = new NutUml(c);"; output +="uml.drawUml(umlText);"; output +="</script>"; }
return output;
}
private String parse(String s) { s= StringUtils.replace(s,"\"","\\\""); s= StringUtils.replace(s,"\r","\\r"); s= StringUtils.replace(s,"\n","\\n"); return s; }
@Override public BodyType getBodyType() { return BodyType.PLAIN_TEXT; }
@Override public OutputType getOutputType() { return OutputType.BLOCK; } }
|
xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <atlassian-plugin key="${atlassian.plugin.key}" name="${project.name}" plugins-version="2"> <plugin-info> <description>${project.description}</description> <version>${project.version}</version> <vendor name="${project.organization.name}" url="${project.organization.url}" /> <param name="plugin-icon">images/pluginIcon.png</param> <param name="plugin-logo">images/pluginLogo.png</param> </plugin-info>
<!-- add our i18n resource --> <resource type="i18n" name="i18n" location="hello-demo"/>
<!-- add our web resources --> <web-resource key="hello-demo-resources" name="hello-demo Web Resources"> <dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="download" name="hello-demo.css" location="/css/hello-demo.css"/> <resource type="download" name="hello-demo.js" location="/js/hello-demo.js"/> <resource type="download" name="images/" location="/images"/>
<context>hello-demo</context> </web-resource> <xhtml-macro name="helloworld" class="com.example.plugin.Helloworld" key='helloworld-macro'> <description key="helloworld.macro.desc"/> <category name="formatting"/> <parameters> <parameter name="Name" type="string" /> <parameter name="Color" type="enum"> <value name="red"/> <value name="green"/> <value name="blue"/> </parameter> </parameters> </xhtml-macro> </atlassian-plugin>
|