Re: [xwiki-devs] [xwiki-notifications] r27562 - in platform/core/trunk: xwiki-core/src/main/java/com/xpn/xwiki/internal xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge
Hi Asiri, Don't we have any tests for wiki macros? I don't see any test providing that it works. Since wiki macros are something introduced recently I'm surprised we don't have tests for it (or do we?). Also could you explain the need for default parameter values in wiki macro parameter descriptor? Since the macro content is available in the content field, isn't it easy to use a default value there? So is this just for convenience or is there something I don't see? Thanks -Vincent On Mar 10, 2010, at 7:43 AM, asiri (SVN) wrote:
Author: asiri Date: 2010-03-10 07:43:01 +0100 (Wed, 10 Mar 2010) New Revision: 27562
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java Log: XWIKI-4944: Add support for Default Values for XWiki Wiki Macros.
* Applied anamaria's patch without changes.
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -191,7 +191,8 @@ String parameterDescription = macroParameter.getStringValue(PARAMETER_DESCRIPTION_PROPERTY); boolean parameterMandatory = (macroParameter.getIntValue(PARAMETER_MANDATORY_PROPERTY) == 0) ? false : true; - + String parameterDefaultValue = macroParameter.getStringValue(PARAMETER_DEFAULT_VALUE_PROPERTY); + // Verify parameter name. if (StringUtils.isEmpty(parameterName)) { throw new WikiMacroException(String.format( @@ -203,10 +204,15 @@ String errorMessage = "Incomplete macro definition in [%s], macro parameter description is empty"; getLogger().debug(String.format(errorMessage, documentReference)); } + + // If field empty, assume no default value was provided. + if (StringUtils.isEmpty(parameterDefaultValue)) { + parameterDefaultValue = null; + }
// Create the parameter descriptor. parameterDescriptors.add(new WikiMacroParameterDescriptor(parameterName, parameterDescription, - parameterMandatory)); + parameterMandatory, parameterDefaultValue)); } }
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -235,6 +235,7 @@ needsUpdate |= bclass.addTextField(PARAMETER_NAME_PROPERTY, "Parameter name", 30); needsUpdate |= bclass.addTextAreaField(PARAMETER_DESCRIPTION_PROPERTY, "Parameter description", 40, 5); needsUpdate |= bclass.addBooleanField(PARAMETER_MANDATORY_PROPERTY, "Parameter mandatory", "yesno"); + needsUpdate |= bclass.addTextField(PARAMETER_DEFAULT_VALUE_PROPERTY, "Parameter default value", 30);
if (needsUpdate) { update(doc);
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -111,4 +111,10 @@ * Constant for representing parameter mandatory property. */ String PARAMETER_MANDATORY_PROPERTY = "mandatory"; + + /** + * Constant for representing parameter defaultValue property. + * @since 2.3M1 + */ + String PARAMETER_DEFAULT_VALUE_PROPERTY = "defaultValue"; }
Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java =================================================================== --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -54,6 +54,11 @@ private boolean mandatory;
/** + * Default value of the parameter. + */ + private Object defaultValue; + + /** * Creates a new {@link WikiMacroParameterDescriptor} instance. * * @param id parameter identifier. @@ -68,6 +73,23 @@ }
/** + * Creates a new {@link WikiMacroParameterDescriptor} instance. + * + * @param id parameter identifier. + * @param description parameter description. + * @param mandatory if the parameter is mandatory. + * @param defaultValue parameter default value. + * @since 2.3M1 + */ + public WikiMacroParameterDescriptor(String id, String description, boolean mandatory, Object defaultValue) + { + this.id = id; + this.description = description; + this.mandatory = mandatory; + this.defaultValue = defaultValue; + } + + /** * {@inheritDoc} */ public String getId() @@ -106,7 +128,7 @@ */ public Object getDefaultValue() { - return null; + return this.defaultValue; }
/**
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications
Vincent Massol wrote:
Hi Asiri,
Don't we have any tests for wiki macros? I don't see any test providing that it works. Since wiki macros are something introduced recently I'm surprised we don't have tests for it (or do we?).
Also could you explain the need for default parameter values in wiki macro parameter descriptor? Since the macro content is available in the content field, isn't it easy to use a default value there?
So is this just for convenience or is there something I don't see?
The WYSIWYG editor can't extract the default values from the wiki macro content. If a macro parameter has a default value then the WYSIWYG user should see it. Marius
Thanks -Vincent
On Mar 10, 2010, at 7:43 AM, asiri (SVN) wrote:
Author: asiri Date: 2010-03-10 07:43:01 +0100 (Wed, 10 Mar 2010) New Revision: 27562
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java Log: XWIKI-4944: Add support for Default Values for XWiki Wiki Macros.
* Applied anamaria's patch without changes.
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -191,7 +191,8 @@ String parameterDescription = macroParameter.getStringValue(PARAMETER_DESCRIPTION_PROPERTY); boolean parameterMandatory = (macroParameter.getIntValue(PARAMETER_MANDATORY_PROPERTY) == 0) ? false : true; - + String parameterDefaultValue = macroParameter.getStringValue(PARAMETER_DEFAULT_VALUE_PROPERTY); + // Verify parameter name. if (StringUtils.isEmpty(parameterName)) { throw new WikiMacroException(String.format( @@ -203,10 +204,15 @@ String errorMessage = "Incomplete macro definition in [%s], macro parameter description is empty"; getLogger().debug(String.format(errorMessage, documentReference)); } + + // If field empty, assume no default value was provided. + if (StringUtils.isEmpty(parameterDefaultValue)) { + parameterDefaultValue = null; + }
// Create the parameter descriptor. parameterDescriptors.add(new WikiMacroParameterDescriptor(parameterName, parameterDescription, - parameterMandatory)); + parameterMandatory, parameterDefaultValue)); } }
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -235,6 +235,7 @@ needsUpdate |= bclass.addTextField(PARAMETER_NAME_PROPERTY, "Parameter name", 30); needsUpdate |= bclass.addTextAreaField(PARAMETER_DESCRIPTION_PROPERTY, "Parameter description", 40, 5); needsUpdate |= bclass.addBooleanField(PARAMETER_MANDATORY_PROPERTY, "Parameter mandatory", "yesno"); + needsUpdate |= bclass.addTextField(PARAMETER_DEFAULT_VALUE_PROPERTY, "Parameter default value", 30);
if (needsUpdate) { update(doc);
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -111,4 +111,10 @@ * Constant for representing parameter mandatory property. */ String PARAMETER_MANDATORY_PROPERTY = "mandatory"; + + /** + * Constant for representing parameter defaultValue property. + * @since 2.3M1 + */ + String PARAMETER_DEFAULT_VALUE_PROPERTY = "defaultValue"; }
Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java =================================================================== --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -54,6 +54,11 @@ private boolean mandatory;
/** + * Default value of the parameter. + */ + private Object defaultValue; + + /** * Creates a new {@link WikiMacroParameterDescriptor} instance. * * @param id parameter identifier. @@ -68,6 +73,23 @@ }
/** + * Creates a new {@link WikiMacroParameterDescriptor} instance. + * + * @param id parameter identifier. + * @param description parameter description. + * @param mandatory if the parameter is mandatory. + * @param defaultValue parameter default value. + * @since 2.3M1 + */ + public WikiMacroParameterDescriptor(String id, String description, boolean mandatory, Object defaultValue) + { + this.id = id; + this.description = description; + this.mandatory = mandatory; + this.defaultValue = defaultValue; + } + + /** * {@inheritDoc} */ public String getId() @@ -106,7 +128,7 @@ */ public Object getDefaultValue() { - return null; + return this.defaultValue; }
/**
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Mar 10, 2010, at 8:33 AM, Marius Dumitru Florea wrote:
Vincent Massol wrote:
Hi Asiri,
Don't we have any tests for wiki macros? I don't see any test providing that it works. Since wiki macros are something introduced recently I'm surprised we don't have tests for it (or do we?).
Also could you explain the need for default parameter values in wiki macro parameter descriptor? Since the macro content is available in the content field, isn't it easy to use a default value there?
So is this just for convenience or is there something I don't see?
The WYSIWYG editor can't extract the default values from the wiki macro content. If a macro parameter has a default value then the WYSIWYG user should see it.
Ok I see. How do you get default param values for java macros? For example for the velocity macro I see that the default value for the "filter" parameter is in execute(). Thanks -Vincent
Marius
Thanks -Vincent
On Mar 10, 2010, at 7:43 AM, asiri (SVN) wrote:
Author: asiri Date: 2010-03-10 07:43:01 +0100 (Wed, 10 Mar 2010) New Revision: 27562
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java Log: XWIKI-4944: Add support for Default Values for XWiki Wiki Macros.
* Applied anamaria's patch without changes.
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -191,7 +191,8 @@ String parameterDescription = macroParameter.getStringValue(PARAMETER_DESCRIPTION_PROPERTY); boolean parameterMandatory = (macroParameter.getIntValue(PARAMETER_MANDATORY_PROPERTY) == 0) ? false : true; - + String parameterDefaultValue = macroParameter.getStringValue(PARAMETER_DEFAULT_VALUE_PROPERTY); + // Verify parameter name. if (StringUtils.isEmpty(parameterName)) { throw new WikiMacroException(String.format( @@ -203,10 +204,15 @@ String errorMessage = "Incomplete macro definition in [%s], macro parameter description is empty"; getLogger().debug(String.format(errorMessage, documentReference)); } + + // If field empty, assume no default value was provided. + if (StringUtils.isEmpty(parameterDefaultValue)) { + parameterDefaultValue = null; + }
// Create the parameter descriptor. parameterDescriptors.add(new WikiMacroParameterDescriptor(parameterName, parameterDescription, - parameterMandatory)); + parameterMandatory, parameterDefaultValue)); } }
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -235,6 +235,7 @@ needsUpdate |= bclass.addTextField(PARAMETER_NAME_PROPERTY, "Parameter name", 30); needsUpdate |= bclass.addTextAreaField(PARAMETER_DESCRIPTION_PROPERTY, "Parameter description", 40, 5); needsUpdate |= bclass.addBooleanField(PARAMETER_MANDATORY_PROPERTY, "Parameter mandatory", "yesno"); + needsUpdate |= bclass.addTextField(PARAMETER_DEFAULT_VALUE_PROPERTY, "Parameter default value", 30);
if (needsUpdate) { update(doc);
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -111,4 +111,10 @@ * Constant for representing parameter mandatory property. */ String PARAMETER_MANDATORY_PROPERTY = "mandatory"; + + /** + * Constant for representing parameter defaultValue property. + * @since 2.3M1 + */ + String PARAMETER_DEFAULT_VALUE_PROPERTY = "defaultValue"; }
Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java =================================================================== --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -54,6 +54,11 @@ private boolean mandatory;
/** + * Default value of the parameter. + */ + private Object defaultValue; + + /** * Creates a new {@link WikiMacroParameterDescriptor} instance. * * @param id parameter identifier. @@ -68,6 +73,23 @@ }
/** + * Creates a new {@link WikiMacroParameterDescriptor} instance. + * + * @param id parameter identifier. + * @param description parameter description. + * @param mandatory if the parameter is mandatory. + * @param defaultValue parameter default value. + * @since 2.3M1 + */ + public WikiMacroParameterDescriptor(String id, String description, boolean mandatory, Object defaultValue) + { + this.id = id; + this.description = description; + this.mandatory = mandatory; + this.defaultValue = defaultValue; + } + + /** * {@inheritDoc} */ public String getId() @@ -106,7 +128,7 @@ */ public Object getDefaultValue() { - return null; + return this.defaultValue; }
/**
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Vincent Massol wrote:
On Mar 10, 2010, at 8:33 AM, Marius Dumitru Florea wrote:
Vincent Massol wrote:
Hi Asiri,
Don't we have any tests for wiki macros? I don't see any test providing that it works. Since wiki macros are something introduced recently I'm surprised we don't have tests for it (or do we?).
Also could you explain the need for default parameter values in wiki macro parameter descriptor? Since the macro content is available in the content field, isn't it easy to use a default value there?
So is this just for convenience or is there something I don't see? The WYSIWYG editor can't extract the default values from the wiki macro content. If a macro parameter has a default value then the WYSIWYG user should see it.
Ok I see.
How do you get default param values for java macros? For example for the velocity macro I see that the default value for the "filter" parameter is in execute().
I don't know exactly how default parameter values for Java macros are extracted (Thomas should know), the editor just takes them from the macro parameter descriptor. I just tested and there's no default value displayed for the "filter" parameter of the velocity macro. If this parameter has a default value then it should be specified in its descriptor. Other velocity macro parameters like "output" or "wiki" have a default value specified in the descriptor. Note that the editor doesn't include default values in its output (unless the parameter is required) so the generated wiki syntax is not affected if you specify the default value in the parameter descriptor. Thanks, Marius
Thanks -Vincent
Marius
Thanks -Vincent
On Mar 10, 2010, at 7:43 AM, asiri (SVN) wrote:
Author: asiri Date: 2010-03-10 07:43:01 +0100 (Wed, 10 Mar 2010) New Revision: 27562
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java Log: XWIKI-4944: Add support for Default Values for XWiki Wiki Macros.
* Applied anamaria's patch without changes.
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -191,7 +191,8 @@ String parameterDescription = macroParameter.getStringValue(PARAMETER_DESCRIPTION_PROPERTY); boolean parameterMandatory = (macroParameter.getIntValue(PARAMETER_MANDATORY_PROPERTY) == 0) ? false : true; - + String parameterDefaultValue = macroParameter.getStringValue(PARAMETER_DEFAULT_VALUE_PROPERTY); + // Verify parameter name. if (StringUtils.isEmpty(parameterName)) { throw new WikiMacroException(String.format( @@ -203,10 +204,15 @@ String errorMessage = "Incomplete macro definition in [%s], macro parameter description is empty"; getLogger().debug(String.format(errorMessage, documentReference)); } + + // If field empty, assume no default value was provided. + if (StringUtils.isEmpty(parameterDefaultValue)) { + parameterDefaultValue = null; + }
// Create the parameter descriptor. parameterDescriptors.add(new WikiMacroParameterDescriptor(parameterName, parameterDescription, - parameterMandatory)); + parameterMandatory, parameterDefaultValue)); } }
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -235,6 +235,7 @@ needsUpdate |= bclass.addTextField(PARAMETER_NAME_PROPERTY, "Parameter name", 30); needsUpdate |= bclass.addTextAreaField(PARAMETER_DESCRIPTION_PROPERTY, "Parameter description", 40, 5); needsUpdate |= bclass.addBooleanField(PARAMETER_MANDATORY_PROPERTY, "Parameter mandatory", "yesno"); + needsUpdate |= bclass.addTextField(PARAMETER_DEFAULT_VALUE_PROPERTY, "Parameter default value", 30);
if (needsUpdate) { update(doc);
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -111,4 +111,10 @@ * Constant for representing parameter mandatory property. */ String PARAMETER_MANDATORY_PROPERTY = "mandatory"; + + /** + * Constant for representing parameter defaultValue property. + * @since 2.3M1 + */ + String PARAMETER_DEFAULT_VALUE_PROPERTY = "defaultValue"; }
Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java =================================================================== --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -54,6 +54,11 @@ private boolean mandatory;
/** + * Default value of the parameter. + */ + private Object defaultValue; + + /** * Creates a new {@link WikiMacroParameterDescriptor} instance. * * @param id parameter identifier. @@ -68,6 +73,23 @@ }
/** + * Creates a new {@link WikiMacroParameterDescriptor} instance. + * + * @param id parameter identifier. + * @param description parameter description. + * @param mandatory if the parameter is mandatory. + * @param defaultValue parameter default value. + * @since 2.3M1 + */ + public WikiMacroParameterDescriptor(String id, String description, boolean mandatory, Object defaultValue) + { + this.id = id; + this.description = description; + this.mandatory = mandatory; + this.defaultValue = defaultValue; + } + + /** * {@inheritDoc} */ public String getId() @@ -106,7 +128,7 @@ */ public Object getDefaultValue() { - return null; + return this.defaultValue; }
/**
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications
devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Mar 10, 2010, at 9:20 AM, Marius Dumitru Florea wrote:
Vincent Massol wrote:
On Mar 10, 2010, at 8:33 AM, Marius Dumitru Florea wrote:
Vincent Massol wrote:
Hi Asiri,
Don't we have any tests for wiki macros? I don't see any test providing that it works. Since wiki macros are something introduced recently I'm surprised we don't have tests for it (or do we?).
Also could you explain the need for default parameter values in wiki macro parameter descriptor? Since the macro content is available in the content field, isn't it easy to use a default value there?
So is this just for convenience or is there something I don't see? The WYSIWYG editor can't extract the default values from the wiki macro content. If a macro parameter has a default value then the WYSIWYG user should see it.
Ok I see.
How do you get default param values for java macros? For example for the velocity macro I see that the default value for the "filter" parameter is in execute().
I don't know exactly how default parameter values for Java macros are extracted (Thomas should know), the editor just takes them from the macro parameter descriptor. I just tested and there's no default value displayed for the "filter" parameter of the velocity macro. If this parameter has a default value then it should be specified in its descriptor. Other velocity macro parameters like "output" or "wiki" have a default value specified in the descriptor. Note that the editor doesn't include default values in its output (unless the parameter is required) so the generated wiki syntax is not affected if you specify the default value in the parameter descriptor.
ok, thanks for the explanations! -Vincent
Thanks, Marius
Thanks -Vincent
Marius
Thanks -Vincent
On Mar 10, 2010, at 7:43 AM, asiri (SVN) wrote:
Author: asiri Date: 2010-03-10 07:43:01 +0100 (Wed, 10 Mar 2010) New Revision: 27562
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java Log: XWIKI-4944: Add support for Default Values for XWiki Wiki Macros.
* Applied anamaria's patch without changes.
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -191,7 +191,8 @@ String parameterDescription = macroParameter.getStringValue(PARAMETER_DESCRIPTION_PROPERTY); boolean parameterMandatory = (macroParameter.getIntValue(PARAMETER_MANDATORY_PROPERTY) == 0) ? false : true; - + String parameterDefaultValue = macroParameter.getStringValue(PARAMETER_DEFAULT_VALUE_PROPERTY); + // Verify parameter name. if (StringUtils.isEmpty(parameterName)) { throw new WikiMacroException(String.format( @@ -203,10 +204,15 @@ String errorMessage = "Incomplete macro definition in [%s], macro parameter description is empty"; getLogger().debug(String.format(errorMessage, documentReference)); } + + // If field empty, assume no default value was provided. + if (StringUtils.isEmpty(parameterDefaultValue)) { + parameterDefaultValue = null; + }
// Create the parameter descriptor. parameterDescriptors.add(new WikiMacroParameterDescriptor(parameterName, parameterDescription, - parameterMandatory)); + parameterMandatory, parameterDefaultValue)); } }
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -235,6 +235,7 @@ needsUpdate |= bclass.addTextField(PARAMETER_NAME_PROPERTY, "Parameter name", 30); needsUpdate |= bclass.addTextAreaField(PARAMETER_DESCRIPTION_PROPERTY, "Parameter description", 40, 5); needsUpdate |= bclass.addBooleanField(PARAMETER_MANDATORY_PROPERTY, "Parameter mandatory", "yesno"); + needsUpdate |= bclass.addTextField(PARAMETER_DEFAULT_VALUE_PROPERTY, "Parameter default value", 30);
if (needsUpdate) { update(doc);
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -111,4 +111,10 @@ * Constant for representing parameter mandatory property. */ String PARAMETER_MANDATORY_PROPERTY = "mandatory"; + + /** + * Constant for representing parameter defaultValue property. + * @since 2.3M1 + */ + String PARAMETER_DEFAULT_VALUE_PROPERTY = "defaultValue"; }
Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java =================================================================== --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -54,6 +54,11 @@ private boolean mandatory;
/** + * Default value of the parameter. + */ + private Object defaultValue; + + /** * Creates a new {@link WikiMacroParameterDescriptor} instance. * * @param id parameter identifier. @@ -68,6 +73,23 @@ }
/** + * Creates a new {@link WikiMacroParameterDescriptor} instance. + * + * @param id parameter identifier. + * @param description parameter description. + * @param mandatory if the parameter is mandatory. + * @param defaultValue parameter default value. + * @since 2.3M1 + */ + public WikiMacroParameterDescriptor(String id, String description, boolean mandatory, Object defaultValue) + { + this.id = id; + this.description = description; + this.mandatory = mandatory; + this.defaultValue = defaultValue; + } + + /** * {@inheritDoc} */ public String getId() @@ -106,7 +128,7 @@ */ public Object getDefaultValue() { - return null; + return this.defaultValue; }
/**
On Wed, Mar 10, 2010 at 08:53, Vincent Massol <[email protected]> wrote:
On Mar 10, 2010, at 8:33 AM, Marius Dumitru Florea wrote:
Vincent Massol wrote:
Hi Asiri,
Don't we have any tests for wiki macros? I don't see any test providing that it works. Since wiki macros are something introduced recently I'm surprised we don't have tests for it (or do we?).
Also could you explain the need for default parameter values in wiki macro parameter descriptor? Since the macro content is available in the content field, isn't it easy to use a default value there?
So is this just for convenience or is there something I don't see?
The WYSIWYG editor can't extract the default values from the wiki macro content. If a macro parameter has a default value then the WYSIWYG user should see it.
Ok I see.
How do you get default param values for java macros? For example for the velocity macro I see that the default value for the "filter" parameter is in execute().
To get default value an instance of the macro parameters bean is used, the value returned by each parameter of a newly created bean is seen as the default value. See org.xwiki.properties.internal.DefaultBeanDescriptor on how PropertyDescriptor (which is used to fill a macros parameters descriptors) is generated. For example when you create a new IncludeMacroParameters and call getContext() you have IncludeMacroParameters.Context.CURRENT so IncludeMacroParameters.Context.CURRENT is the default value in the parameter descriptor. Because that's exactly what the macro will do. Now it's possible that some macro did not provided default value in their bean for some reasons or simply did it the wrong way. The default value of the "filter" parameter of the velocity macro comes form a configuration which is why it's not in the bean (it could change and the bean descriptor is generated once at startup). Note that support dynamic possible values is what is covered by http://dev.xwiki.org/xwiki/bin/view/Design/Propertiesdisplayers (among other things).
Thanks -Vincent
Marius
Thanks -Vincent
On Mar 10, 2010, at 7:43 AM, asiri (SVN) wrote:
Author: asiri Date: 2010-03-10 07:43:01 +0100 (Wed, 10 Mar 2010) New Revision: 27562
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java Log: XWIKI-4944: Add support for Default Values for XWiki Wiki Macros.
* Applied anamaria's patch without changes.
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -191,7 +191,8 @@ String parameterDescription = macroParameter.getStringValue(PARAMETER_DESCRIPTION_PROPERTY); boolean parameterMandatory = (macroParameter.getIntValue(PARAMETER_MANDATORY_PROPERTY) == 0) ? false : true; - + String parameterDefaultValue = macroParameter.getStringValue(PARAMETER_DEFAULT_VALUE_PROPERTY); + // Verify parameter name. if (StringUtils.isEmpty(parameterName)) { throw new WikiMacroException(String.format( @@ -203,10 +204,15 @@ String errorMessage = "Incomplete macro definition in [%s], macro parameter description is empty"; getLogger().debug(String.format(errorMessage, documentReference)); } + + // If field empty, assume no default value was provided. + if (StringUtils.isEmpty(parameterDefaultValue)) { + parameterDefaultValue = null; + }
// Create the parameter descriptor. parameterDescriptors.add(new WikiMacroParameterDescriptor(parameterName, parameterDescription, - parameterMandatory)); + parameterMandatory, parameterDefaultValue)); } }
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -235,6 +235,7 @@ needsUpdate |= bclass.addTextField(PARAMETER_NAME_PROPERTY, "Parameter name", 30); needsUpdate |= bclass.addTextAreaField(PARAMETER_DESCRIPTION_PROPERTY, "Parameter description", 40, 5); needsUpdate |= bclass.addBooleanField(PARAMETER_MANDATORY_PROPERTY, "Parameter mandatory", "yesno"); + needsUpdate |= bclass.addTextField(PARAMETER_DEFAULT_VALUE_PROPERTY, "Parameter default value", 30);
if (needsUpdate) { update(doc);
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -111,4 +111,10 @@ * Constant for representing parameter mandatory property. */ String PARAMETER_MANDATORY_PROPERTY = "mandatory"; + + /** + * Constant for representing parameter defaultValue property. + * @since 2.3M1 + */ + String PARAMETER_DEFAULT_VALUE_PROPERTY = "defaultValue"; }
Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java =================================================================== --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -54,6 +54,11 @@ private boolean mandatory;
/** + * Default value of the parameter. + */ + private Object defaultValue; + + /** * Creates a new {@link WikiMacroParameterDescriptor} instance. * * @param id parameter identifier. @@ -68,6 +73,23 @@ }
/** + * Creates a new {@link WikiMacroParameterDescriptor} instance. + * + * @param id parameter identifier. + * @param description parameter description. + * @param mandatory if the parameter is mandatory. + * @param defaultValue parameter default value. + * @since 2.3M1 + */ + public WikiMacroParameterDescriptor(String id, String description, boolean mandatory, Object defaultValue) + { + this.id = id; + this.description = description; + this.mandatory = mandatory; + this.defaultValue = defaultValue; + } + + /** * {@inheritDoc} */ public String getId() @@ -106,7 +128,7 @@ */ public Object getDefaultValue() { - return null; + return this.defaultValue; }
/**
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
Hi Vincent, On Wed, Mar 10, 2010 at 12:55 PM, Vincent Massol <[email protected]> wrote:
Hi Asiri,
Don't we have any tests for wiki macros? I don't see any test providing that it works. Since wiki macros are something introduced recently I'm surprised we don't have tests for it (or do we?).
There are tests for wiki macros. See http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... and http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... If you are referring to this specific new feature or integration tests, No there are none. Thanks. - Asiri
Also could you explain the need for default parameter values in wiki macro parameter descriptor? Since the macro content is available in the content field, isn't it easy to use a default value there?
So is this just for convenience or is there something I don't see?
Thanks -Vincent
On Mar 10, 2010, at 7:43 AM, asiri (SVN) wrote:
Author: asiri Date: 2010-03-10 07:43:01 +0100 (Wed, 10 Mar 2010) New Revision: 27562
Modified:
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java
Log: XWIKI-4944: Add support for Default Values for XWiki Wiki Macros.
* Applied anamaria's patch without changes.
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -191,7 +191,8 @@ String parameterDescription = macroParameter.getStringValue(PARAMETER_DESCRIPTION_PROPERTY); boolean parameterMandatory =
(macroParameter.getIntValue(PARAMETER_MANDATORY_PROPERTY) == 0) ? false : true;
- + String parameterDefaultValue = macroParameter.getStringValue(PARAMETER_DEFAULT_VALUE_PROPERTY); + // Verify parameter name. if (StringUtils.isEmpty(parameterName)) { throw new WikiMacroException(String.format( @@ -203,10 +204,15 @@ String errorMessage = "Incomplete macro definition in [%s], macro parameter description is empty"; getLogger().debug(String.format(errorMessage, documentReference)); } + + // If field empty, assume no default value was provided. + if (StringUtils.isEmpty(parameterDefaultValue)) { + parameterDefaultValue = null; + }
// Create the parameter descriptor. parameterDescriptors.add(new WikiMacroParameterDescriptor(parameterName, parameterDescription, - parameterMandatory)); + parameterMandatory, parameterDefaultValue)); } }
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -235,6 +235,7 @@ needsUpdate |= bclass.addTextField(PARAMETER_NAME_PROPERTY, "Parameter name", 30); needsUpdate |= bclass.addTextAreaField(PARAMETER_DESCRIPTION_PROPERTY, "Parameter description", 40, 5); needsUpdate |= bclass.addBooleanField(PARAMETER_MANDATORY_PROPERTY, "Parameter mandatory", "yesno"); + needsUpdate |= bclass.addTextField(PARAMETER_DEFAULT_VALUE_PROPERTY, "Parameter default value", 30);
if (needsUpdate) { update(doc);
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -111,4 +111,10 @@ * Constant for representing parameter mandatory property. */ String PARAMETER_MANDATORY_PROPERTY = "mandatory"; + + /** + * Constant for representing parameter defaultValue property. + * @since 2.3M1 + */ + String PARAMETER_DEFAULT_VALUE_PROPERTY = "defaultValue"; }
Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java =================================================================== --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -54,6 +54,11 @@ private boolean mandatory;
/** + * Default value of the parameter. + */ + private Object defaultValue; + + /** * Creates a new {@link WikiMacroParameterDescriptor} instance. * * @param id parameter identifier. @@ -68,6 +73,23 @@ }
/** + * Creates a new {@link WikiMacroParameterDescriptor} instance. + * + * @param id parameter identifier. + * @param description parameter description. + * @param mandatory if the parameter is mandatory. + * @param defaultValue parameter default value. + * @since 2.3M1 + */ + public WikiMacroParameterDescriptor(String id, String description, boolean mandatory, Object defaultValue) + { + this.id = id; + this.description = description; + this.mandatory = mandatory; + this.defaultValue = defaultValue; + } + + /** * {@inheritDoc} */ public String getId() @@ -106,7 +128,7 @@ */ public Object getDefaultValue() { - return null; + return this.defaultValue; }
/**
_______________________________________________ notifications mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/notifications
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Mar 10, 2010, at 8:48 AM, Asiri Rathnayake wrote:
Hi Vincent,
On Wed, Mar 10, 2010 at 12:55 PM, Vincent Massol <[email protected]> wrote:
Hi Asiri,
Don't we have any tests for wiki macros? I don't see any test providing that it works. Since wiki macros are something introduced recently I'm surprised we don't have tests for it (or do we?).
There are tests for wiki macros. See http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
and
http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
If you are referring to this specific new feature or integration tests, No there are none.
Yes that's my question, why are there none? We shouldn't apply or accept patches that don't have tests to prove they work (unless when it's about some old code modifications and writing tests is just too hard). Could you add some tests to prove this new feature? Thanks -Vincent
Thanks.
- Asiri
Also could you explain the need for default parameter values in wiki macro parameter descriptor? Since the macro content is available in the content field, isn't it easy to use a default value there?
So is this just for convenience or is there something I don't see?
Thanks -Vincent
On Mar 10, 2010, at 7:43 AM, asiri (SVN) wrote:
Author: asiri Date: 2010-03-10 07:43:01 +0100 (Wed, 10 Mar 2010) New Revision: 27562
Modified:
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java
platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java
platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java
Log: XWIKI-4944: Add support for Default Values for XWiki Wiki Macros.
* Applied anamaria's patch without changes.
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -191,7 +191,8 @@ String parameterDescription = macroParameter.getStringValue(PARAMETER_DESCRIPTION_PROPERTY); boolean parameterMandatory =
(macroParameter.getIntValue(PARAMETER_MANDATORY_PROPERTY) == 0) ? false : true;
- + String parameterDefaultValue = macroParameter.getStringValue(PARAMETER_DEFAULT_VALUE_PROPERTY); + // Verify parameter name. if (StringUtils.isEmpty(parameterName)) { throw new WikiMacroException(String.format( @@ -203,10 +204,15 @@ String errorMessage = "Incomplete macro definition in [%s], macro parameter description is empty"; getLogger().debug(String.format(errorMessage, documentReference)); } + + // If field empty, assume no default value was provided. + if (StringUtils.isEmpty(parameterDefaultValue)) { + parameterDefaultValue = null; + }
// Create the parameter descriptor. parameterDescriptors.add(new WikiMacroParameterDescriptor(parameterName, parameterDescription, - parameterMandatory)); + parameterMandatory, parameterDefaultValue)); } }
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -235,6 +235,7 @@ needsUpdate |= bclass.addTextField(PARAMETER_NAME_PROPERTY, "Parameter name", 30); needsUpdate |= bclass.addTextAreaField(PARAMETER_DESCRIPTION_PROPERTY, "Parameter description", 40, 5); needsUpdate |= bclass.addBooleanField(PARAMETER_MANDATORY_PROPERTY, "Parameter mandatory", "yesno"); + needsUpdate |= bclass.addTextField(PARAMETER_DEFAULT_VALUE_PROPERTY, "Parameter default value", 30);
if (needsUpdate) { update(doc);
Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java =================================================================== --- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/WikiMacroConstants.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -111,4 +111,10 @@ * Constant for representing parameter mandatory property. */ String PARAMETER_MANDATORY_PROPERTY = "mandatory"; + + /** + * Constant for representing parameter defaultValue property. + * @since 2.3M1 + */ + String PARAMETER_DEFAULT_VALUE_PROPERTY = "defaultValue"; }
Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java =================================================================== --- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 05:11:59 UTC (rev 27561) +++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroParameterDescriptor.java 2010-03-10 06:43:01 UTC (rev 27562) @@ -54,6 +54,11 @@ private boolean mandatory;
/** + * Default value of the parameter. + */ + private Object defaultValue; + + /** * Creates a new {@link WikiMacroParameterDescriptor} instance. * * @param id parameter identifier. @@ -68,6 +73,23 @@ }
/** + * Creates a new {@link WikiMacroParameterDescriptor} instance. + * + * @param id parameter identifier. + * @param description parameter description. + * @param mandatory if the parameter is mandatory. + * @param defaultValue parameter default value. + * @since 2.3M1 + */ + public WikiMacroParameterDescriptor(String id, String description, boolean mandatory, Object defaultValue) + { + this.id = id; + this.description = description; + this.mandatory = mandatory; + this.defaultValue = defaultValue; + } + + /** * {@inheritDoc} */ public String getId() @@ -106,7 +128,7 @@ */ public Object getDefaultValue() { - return null; + return this.defaultValue; }
/**
Hi Vincent,
If you are referring to this specific new feature or integration tests, No there are none.
Yes that's my question, why are there none? We shouldn't apply or accept patches that don't have tests to prove they work (unless when it's about some old code modifications and writing tests is just too hard).
Could you add some tests to prove this new feature?
ParameterDescriptor interface have the method getDefaultValue() which returns an object. WikiMacroParameterDescriptor class used to return null and what anamaria has done is to make it return a user specified (via a new constructor) default value object. I do not think this needs any test. - Asiri
On Mar 10, 2010, at 9:11 AM, Asiri Rathnayake wrote:
Hi Vincent,
If you are referring to this specific new feature or integration tests, No there are none.
Yes that's my question, why are there none? We shouldn't apply or accept patches that don't have tests to prove they work (unless when it's about some old code modifications and writing tests is just too hard).
Could you add some tests to prove this new feature?
ParameterDescriptor interface have the method getDefaultValue() which returns an object. WikiMacroParameterDescriptor class used to return null and what anamaria has done is to make it return a user specified (via a new constructor) default value object. I do not think this needs any test.
Yes you're right in term of unit test, there isn't much point in adding one. Now I can think of some functional tests to prove it works: * Verify that a macro can be written and that when calling $context.macro.params.myparam you get the default value if not specified * Verify that in the wysiwyg the default value is correctly displayed when a default value is specified wdyt? would these make sense? Thanks -Vincent
Hi Vincent, Now I can think of some functional tests to prove it works:
* Verify that a macro can be written and that when calling $context.macro.params.myparam you get the default value if not specified * Verify that in the wysiwyg the default value is correctly displayed when a default value is specified
wdyt? would these make sense?
+1 First usecase didn't work for me while the second one worked fine (manual testing). However, I think the first usecase can be dealt in a unit test (not sure). I will ask anamaria to add appropriate tests (I'm bit occupied), or else i will have to do it bit later. Thanks. - Asiri
Thanks -Vincent
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Vincent Massol wrote:
On Mar 10, 2010, at 9:11 AM, Asiri Rathnayake wrote:
Hi Vincent,
If you are referring to this specific new feature or integration tests, No there are none. Yes that's my question, why are there none? We shouldn't apply or accept patches that don't have tests to prove they work (unless when it's about some old code modifications and writing tests is just too hard).
Could you add some tests to prove this new feature?
ParameterDescriptor interface have the method getDefaultValue() which returns an object. WikiMacroParameterDescriptor class used to return null and what anamaria has done is to make it return a user specified (via a new constructor) default value object. I do not think this needs any test.
Yes you're right in term of unit test, there isn't much point in adding one.
Now I can think of some functional tests to prove it works:
* Verify that a macro can be written and that when calling $context.macro.params.myparam you get the default value if not specified
* Verify that in the wysiwyg the default value is correctly displayed when a default value is specified
I can write this one. I have to write a functional test for http://jira.xwiki.org/jira/browse/XWIKI-4946 anyway. Thanks, Marius
wdyt? would these make sense?
Thanks -Vincent
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (4)
-
Asiri Rathnayake -
Marius Dumitru Florea -
Thomas Mortagne -
Vincent Massol