From Confluence 5.3 onwards it's not possible any more to add macro parameters programmatically via
try { final ContentEntityObject ceo = conversionContext.getEntity(); String body = xhtmlContent.updateMacroDefinitions(ceo.getBodyAsString(), conversionContext, new MacroDefinitionUpdater(){ @Override public MacroDefinition update(MacroDefinition macroDefinition) { if (macroDefinition.getName().equals("macro-test")){ macroDefinition.getParameters().put("visited", new Date().toString()); } return macroDefinition; } }); ceo.setBodyAsString(body); final DefaultSaveContext saveContext = new DefaultSaveContext(true, false, true); pageManager.saveContentEntity(ceo, saveContext); } catch (XhtmlException e) { ... }
within MyMacro.execute(Map<String, String> stringStringMap, String s, ConversionContext conversionContext)
This problem appears as soon as the macro has a parameter defined like
<xhtml-macro name="macro-test" class="test.TestMacro" key="macroTest"> <parameters> <parameter name="name" type="string" required="true"/> ....
Even if I add a placeholder in the macro definition for parameter 'visited' it is not added. Works in Confluence 4.3 thru 5.2
Community moderators have prevented the ability to post new answers.
The short answer is the MacroDefinition.parameters map is no longer canonical for what Confluence will save - you need to modify the MacroDefinition.typedParameters map instead, or create a new instance with the updated parameter and value you want to store.
If the macro you're trying to modify was loaded and running last time Confluence saved it, it's been written to storage format as a ac:structured-macro. When this is parsed, Confluence will set the MacroDefinition.storageVersion to 2, populate the MacroDefinition.typedParameters property with the up to date values (using objects where it can parse the parameter into a structured type), and generate the MacroDefinition.parameters string values from these.
When saving a macro, Confluence decides how to save it based on whether it can load its metadata, and it saves its parameters by serializing its typedParameters map. If that map is empty or null, only then will Confluence attempt to save from the values in the parameters map (converting these to match the types in their macro metadata from the xhtml-macro module definition).
As of this date (approaching 5.5), the typeParameters map values can contain Strings, various types of ResourceIdentifiers, or Links containing ResourceIdentifiers. If the parameter isMultiple, then it will contain an Iterator of one of these. The set of types parsed is managed via MacroParameterTypeParserImpl.
I'd like to include structure parameter support for Dates, booleans and integers in the future, but that much wasn't necessary to get content and user rename support working, so was left out of the change that shipped in 5.3. This followup work is not currently scheduled, however, so you're unlikely to see further churn in this area for some months yet.
the code in the repo above shows the problem, J. D. Please have a look at my answer below \/ \/ \/ \/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ulrich Kuhnhardt [Comalatech] , did the code from your repo work for you? Beacause it doesnt work for me. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the sample code. https://github.com/ukuhnhardt/confluence-macro-param-plugin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.