We built a very simple Confluence structured macro and we are trying to add a unique id that is persistent on reloads as well as on edits of the page, for that we have the following example below. For that we are creating a UUID, if it does not exist. We expect this new UUID to become part of the macro storage format so that it gets picked up on reload.
Also, the body is printing the <ac:parameter> tag as part of the body.
I'm have no idea what could be wrong as so that the <ac:parameter> is not being picked up as part of the meta data. Any help would be very much appreciated.
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.webresource.api.assembler.PageBuilderService;
import org.springframework.beans.factory.annotation.Autowired;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import java.util.Map;
public class radar implements Macro {
private PageBuilderService pageBuilderService;
Autowired
public radar(
ComponentImport PageBuilderService pageBuilderService
) {
this.pageBuilderService = pageBuilderService;
}
Override
public String execute(Map<String, String> map, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException {
pageBuilderService.assembler().resources().requireWebResource("<package>:package-resources");
String macroId = map.get("macroId");
if (StringUtils.isBlank(macroId)) {
macroId = UUID.randomUUID().toString();
map.put("macroId", macroId);
}
return String.format("<p>Your custom macro output</p><ac:parameter ac:name=\"macroId\">%s</ac:parameter>", macroId);
}
public BodyType getBodyType() { return BodyType.NONE; }
public OutputType getOutputType() { return OutputType.BLOCK; }
}
```java
THE XML file is:
<xhtml-macro name="radar" class="private-class-name" key="radar.macro.name" icon="/download/resources/${project.groupId}.${project.artifactId}/images/pluginIcon.png">
<description key="Add this macro to view, edit and create new queries and graphs"/>
<category name="external-content"/>
<parameters>
<parameter name="ProblemClient" type="enum" required="true">
<value name="chirp"/>
<value name="clack"/>
</parameter>
<parameter name="Tool" type="enum" required="true">
<value name="chart"/>
<value name="table"/>
</parameter>
<parameter name="macroId" type="string" hidden="true"/>
</parameters>
<parameters/>
</xhtml-macro>