Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to develop a macro that can contain other arbitrary macros

Al Johnson May 10, 2018

Hi,

 

Can anyone give any pointers or code sample on how to render from the execute() method my macro body which can contain other macros?

I've tried:

XhtmlContent.convertMacroDefinitionToView()

MacroDefinition.getTransformedBodyStream()

and they, understandably, just skip over the embedded/nested macros in the body of my macro.

 

I have the v6.6.3 Confluence source code so any pointers as to what classes to look at would be greatly appreciated.

 

Thanks,

Al

1 answer

0 votes
Al Johnson May 10, 2018
Well, it wasn't too bad:



String convertStorageToView = null;
String body = "";
try {
final AtomicReference<MacroDefinition> atomicMacroDefinition = new AtomicReference<>();
xhtmlUtils.handleMacroDefinitions(page.getBodyAsString(), conversionContext, new MacroDefinitionHandler()
{
public void handle(MacroDefinition macroDefinition)
{
if(excerptName.equals(macroDefinition.getParameter("ss-name"))) {
atomicMacroDefinition.set(macroDefinition);
}
}
});
MacroDefinition foundMacro = atomicMacroDefinition.get();
if(foundMacro != null) {
// Note: foundMacro.getBodyText() returns transformed text, not storage format
String macroStorageFormatBody = Streamables.writeToString(foundMacro.getStorageBodyStream());
System.out.println("\n\nTRACE macroStorageFormatBody: " + macroStorageFormatBody + "\n\n");
convertStorageToView = xhtmlUtils.convertStorageToView(macroStorageFormatBody, conversionContext);
System.out.println("\n\nxhtmlUtils.convertStorageToView(): " + convertStorageToView + "\n\n");
body = convertStorageToView;
} else {
body = "Specified Single Source Include macro not found";
}
} catch (Exception e) {
e.printStackTrace();
body = e.getMessage();
}

System.out.println("TRACE body: " + body);
contextMap.put("body", body);
return VelocityUtils.getRenderedTemplate(TEMPLATE, contextMap);






 

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events