Confluence Macro Plugin显示为已安装,但Macro不起作用

时间:2015-12-10 10:32:07

标签: java confluence

我正在尝试使用Confluence为我的公司编程插件,我使用了本教程:https://developer.atlassian.com/confdev/tutorials/macro-tutorials-for-confluence/creating-a-new-confluence-macro并完成了教程告诉我的所有内容,但宏不起作用,它显示为未知的宏在Confluence中,当我尝试使用它时。但插件本身显示为已安装并已激活。

我在Eclipse Luna上编程并使用Confluence 5.9..2在Atlas运行选项上本地运行。

这是我的源代码:

主档案:

package com.company.confluence.plugin;
import java.util.ArrayList;
import java.util.List;
import com.atlassian.confluence.content.render.xhtml.XhtmlException;
import com.atlassian.confluence.xhtml.api.MacroDefinition;
import com.atlassian.confluence.xhtml.api.MacroDefinitionHandler;
import java.util.Map;
import com.atlassian.confluence.xhtml.api.XhtmlContent;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
public class MyConfluenceMacro implements Macro {
private final XhtmlContent xhtmlUtils;
public MyConfluenceMacro(XhtmlContent xhtmlUtils)
{
    this.xhtmlUtils = xhtmlUtils;   
}
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>();
    System.out.println("===============================================");
    System.out.println("Part 1");
    System.out.println("===============================================");
    try {
        xhtmlUtils.handleMacroDefinitions(body, conversionContext,
                new MacroDefinitionHandler() {
                    @Override
                    public void handle(MacroDefinition macroDefinition) {
                        macros.add(macroDefinition);
                        System.out.println("===============================================");
                        System.out.println("Part 2");
                        System.out.println("===============================================");
                    }
                });
    } catch (XhtmlException e) {
        throw new MacroExecutionException(e);
    }
    StringBuilder builder = new StringBuilder();
    builder.append("<p>");
    if (!macros.isEmpty()) {
        builder.append("<table width=\"50%\">");
        builder.append("<tr><th>Macro Name</th><th>Has Body?</th></tr>");
        for (MacroDefinition defn : macros) {
            System.out.println("===============================================");
            System.out.println("Part 3");
            System.out.println("===============================================");
            builder.append("<tr>");
            builder.append("<td>").append(defn.getName())
                    .append("</td><td>").append(defn.hasBody())
                    .append("</td>");
            builder.append("</tr>");
        }
        builder.append("</table>");
    }
    else
    {
        builder.append("you´ve done building yourself a macro! Nice Worku! Work Work!");
        System.out.println("===============================================");
        System.out.println("Part 4");
        System.out.println("===============================================");
    }
    builder.append("</p>");
    return builder.toString();
}
@Override
public BodyType getBodyType() {
    return BodyType.NONE;
}
@Override
public OutputType getOutputType() {
    return OutputType.BLOCK;
}
}

和atlassian-plugin.xml:

<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}" />
</plugin-info>
<xhtml-macro name="company-confluence-macro" class="com.company.confluence.plugin.MyConfluenceMacro" key="my-macro">
    <parameters/>
</xhtml-macro>
<!-- add our i18n resource -->
<resource type="i18n" name="i18n" location="company-confluence-macro"/>
</atlassian-plugin>

1 个答案:

答案 0 :(得分:0)

如果有人在创建confluence宏时出现问题,则不推荐使用教程:

  

-Atlas创建汇合宏

     

-delete test 文件夹

     

-atlas-mvn eclispe:eclipse

     

- 进入日食工作区的项目

     

- 在教程中创建宏类。(这应该是你在这个阶段唯一的类,删除其他类)

     

- 将此添加到 i18n resource 行后面的atlassian-plugin.xml。

     

(修改项目的“class =”变量)

<xhtml-macro name="PLUGIN" class="com.project.xxx.mymacro" key="mymacro" icon="/download/resources/${project.groupId}.${project.artifactId}/images/pluginIcon.png">
    <category name="external-content"/> 
    <parameters>
        <parameter name="link" type="string" required="true"/>
    </parameters>
    <description>Inserts a calendar for the week into the current page</description>
    </xhtml-macro>
  

-Atlas封装

     

-Atlas运行

     

-Atlas安装-插件

这对atlas-6.2.6有用,我知道这个问题已经很老了,但仍有问题。而且很多白痴都不清楚或已被弃用......