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
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to