On Wed, Mar 10, 2010 at 7:43 AM, asiri <platform-notifications(a)xwiki.org> 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");
Shouldn't this be "Mandatory parameter" instead?
+ needsUpdate |=
bclass.addTextField(PARAMETER_DEFAULT_VALUE_PROPERTY, "Parameter default value",
30);
This should be instead:
"Default parameter value"
Thanks
-Vincent
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
notifications(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications