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
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.