### Eclipse Workspace Patch 1.0 #P xwiki-core-parent Index: xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/descriptor/DefaultMacroDescriptor.java =================================================================== --- xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/descriptor/DefaultMacroDescriptor.java (revision 27222) +++ xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/descriptor/DefaultMacroDescriptor.java (working copy) @@ -20,6 +20,7 @@ package org.xwiki.rendering.macro.descriptor; import org.xwiki.properties.BeanDescriptor; +import org.xwiki.rendering.macro.MacroId; /** * Describe a macro with no parameters. @@ -30,30 +31,69 @@ public class DefaultMacroDescriptor extends AbstractMacroDescriptor { /** + * @param id the id of the macro + * @param name the name of the macro (eg "Table Of Contents" for the TOC macro) + * @since 2.3M1 + */ + public DefaultMacroDescriptor(MacroId id, String name) + { + this(id, name, null); + } + + /** * @param name the name of the macro (eg "Table Of Contents" for the TOC macro) * @since 2.0M3 + * @deprecated since 2.3M1 use {@link #DefaultMacroDescriptor(MacroId, String)} instead */ + @Deprecated public DefaultMacroDescriptor(String name) { this(name, null); } /** + * @param id the id of the macro + * @param name the name of the macro (eg "Table Of Contents" for the TOC macro) + * @param description the description of the macro. + * @since 2.3M1 + */ + public DefaultMacroDescriptor(MacroId id, String name, String description) + { + super(id, name, description, new DefaultContentDescriptor(), null); + } + + /** * @param name the name of the macro (eg "Table Of Contents" for the TOC macro) * @param description the description of the macro. * @since 2.0M3 + * @deprecated since 2.3M1 use {@link #DefaultMacroDescriptor(MacroId, String, String)} instead */ + @Deprecated public DefaultMacroDescriptor(String name, String description) { - super(name, description, new DefaultContentDescriptor(), null); + super(name, description, new DefaultContentDescriptor(), null); + } + + /** + * @param id the id of the macro + * @param name the name of the macro (eg "Table Of Contents" for the TOC macro) + * @param description the description of the macro. + * @param contentDescriptor description of the macro content. + * @since 2.3M1 + */ + public DefaultMacroDescriptor(MacroId id, String name, String description, ContentDescriptor contentDescriptor) + { + super(id, name, description, contentDescriptor, null); } - + /** * @param name the name of the macro (eg "Table Of Contents" for the TOC macro) * @param description the description of the macro. * @param contentDescriptor description of the macro content. * @since 2.0M3 + * @deprecated since 2.3M1 use {@link #DefaultMacroDescriptor(MacroId, String, String, ContentDescriptor)} instead */ + @Deprecated public DefaultMacroDescriptor(String name, String description, ContentDescriptor contentDescriptor) { super(name, description, contentDescriptor, null); @@ -65,12 +105,31 @@ * @param contentDescriptor the description of the macro content. null indicate macro does not support content. * @param parametersBeanDescriptor the description of the parameters bean. * @since 2.0M3 + * @deprecated since 2.3M1 use + * {@link #DefaultMacroDescriptor(MacroId, String, String, ContentDescriptor, BeanDescriptor)} instead */ + @Deprecated public DefaultMacroDescriptor(String name, String description, ContentDescriptor contentDescriptor, BeanDescriptor parametersBeanDescriptor) { super(name, description, contentDescriptor, parametersBeanDescriptor); - + + extractParameterDescriptorMap(); + } + + /** + * @param id the id of the macro + * @param name the name of the macro (eg "Table Of Contents" for the TOC macro) + * @param description the description of the macro. + * @param contentDescriptor the description of the macro content. null indicate macro does not support content. + * @param parametersBeanDescriptor the description of the parameters bean. + * @since 2.3M1 + */ + public DefaultMacroDescriptor(MacroId id, String name, String description, ContentDescriptor contentDescriptor, + BeanDescriptor parametersBeanDescriptor) + { + super(id, name, description, contentDescriptor, parametersBeanDescriptor); + extractParameterDescriptorMap(); - } + } } Index: xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java (revision 27222) +++ xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroFactory.java (working copy) @@ -33,6 +33,7 @@ import org.xwiki.context.Execution; import org.xwiki.model.reference.EntityReferenceSerializer; import org.xwiki.rendering.internal.macro.wikibridge.DefaultWikiMacro; +import org.xwiki.rendering.macro.MacroId; import org.xwiki.rendering.macro.descriptor.ContentDescriptor; import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor; import org.xwiki.rendering.macro.descriptor.MacroDescriptor; @@ -217,7 +218,8 @@ } // Create macro descriptor. - MacroDescriptor macroDescriptor = new WikiMacroDescriptor(macroName, macroDescription, macroDefaultCategory, + MacroId id = new MacroId(macroId, doc.getSyntax()); + MacroDescriptor macroDescriptor = new WikiMacroDescriptor(id, macroName, macroDescription, macroDefaultCategory, macroVisibility, contentDescriptor, parameterDescriptors); // Create & return the macro. Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacro.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacro.java (revision 27222) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacro.java (working copy) @@ -31,6 +31,8 @@ { /** * @return the id under which this macro is registered with the component manager + * @deprecated since 2.3M1 */ + @Deprecated String getId(); } Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroDescriptor.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroDescriptor.java (revision 27222) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroDescriptor.java (working copy) @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; +import org.xwiki.rendering.macro.MacroId; import org.xwiki.rendering.macro.descriptor.ContentDescriptor; import org.xwiki.rendering.macro.descriptor.MacroDescriptor; import org.xwiki.rendering.macro.descriptor.ParameterDescriptor; @@ -36,6 +37,11 @@ public class WikiMacroDescriptor implements MacroDescriptor { /** + * Macro id. + */ + private MacroId id; + + /** * Macro name. */ private String name; @@ -44,7 +50,7 @@ * Macro description. */ private String description; - + /** * Default category under which this macro should be listed. */ @@ -54,7 +60,7 @@ * Whether the macro is visible in the current wiki, for the current user or global. */ private WikiMacroVisibility visibility; - + /** * Macro content description. */ @@ -67,15 +73,43 @@ /** * Creates a new {@link WikiMacroDescriptor} instance. - * - * @param name the macro name + * + * @param id the macro id + * @param name the macro name + * @param description macro description + * @param defaultCategory default category under which this macro should be listed. + * @param visibility the macro visibility (only visible in the current wiki, for the current user or global) + * @param contentDescriptor macro content description. + * @param parameterDescriptors parameter descriptors. + * @since 2.3M1 + */ + public WikiMacroDescriptor(MacroId id, String name, String description, String defaultCategory, + WikiMacroVisibility visibility, ContentDescriptor contentDescriptor, + List parameterDescriptors) + { + this.id = id; + this.name = name; + this.description = description; + this.contentDescriptor = contentDescriptor; + this.parameterDescriptors = parameterDescriptors; + this.defaultCategory = defaultCategory; + this.visibility = visibility; + } + + /** + * Creates a new {@link WikiMacroDescriptor} instance. + * + * @param name the macro name * @param description macro description * @param defaultCategory default category under which this macro should be listed. * @param visibility the macro visibility (only visible in the current wiki, for the current user or global) * @param contentDescriptor macro content description. * @param parameterDescriptors parameter descriptors. * @since 2.2M1 + * @deprecated since 2.3M1 use {@link WikiMacroDescriptor(MacroId, String, String, String, WikiMacroVisibility, + * ContentDescriptor, List)} instead */ + @Deprecated public WikiMacroDescriptor(String name, String description, String defaultCategory, WikiMacroVisibility visibility, ContentDescriptor contentDescriptor, List parameterDescriptors) { @@ -90,6 +124,14 @@ /** * {@inheritDoc} */ + public MacroId getId() + { + return this.id; + } + + /** + * {@inheritDoc} + */ public String getName() { return this.name; @@ -145,8 +187,8 @@ } /** - * @return the visibility of the macro (ie whether the macro is visible in the current wiki, for the current user - * or global) + * @return the visibility of the macro (ie whether the macro is visible in the current wiki, for the current user or + * global) * @since 2.2M1 */ public WikiMacroVisibility getVisibility() Index: xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/AbstractMacro.java =================================================================== --- xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/AbstractMacro.java (revision 27222) +++ xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/AbstractMacro.java (working copy) @@ -19,6 +19,7 @@ */ package org.xwiki.rendering.macro; +import org.xwiki.component.annotation.Component; import org.xwiki.component.annotation.Requirement; import org.xwiki.component.logging.AbstractLogEnabled; import org.xwiki.component.phase.Initializable; @@ -40,22 +41,22 @@ * "Formatting" default macro category. */ public static final String DEFAULT_CATEGORY_FORMATTING = "Formatting"; - + /** * "Development" default macro category. */ public static final String DEFAULT_CATEGORY_DEVELOPMENT = "Development"; - + /** * "Content" default macro category. */ public static final String DEFAULT_CATEGORY_CONTENT = "Content"; - + /** * "Navigation" default macro category. */ public static final String DEFAULT_CATEGORY_NAVIGATION = "Navigation"; - + /** * The {@link BeanManager} component. */ @@ -169,8 +170,15 @@ */ public void initialize() throws InitializationException { + MacroId macroId = null; + // Try to get macro id from component hint - only possible for XWiki Java Macros + Component annotation = this.getClass().getAnnotation(Component.class); + if (annotation != null && !"".equals(annotation)) { + macroId = new MacroId(annotation.value()); + } + DefaultMacroDescriptor descriptor = - new DefaultMacroDescriptor(this.name, this.description, this.contentDescriptor, this.beanManager + new DefaultMacroDescriptor(macroId, this.name, this.description, this.contentDescriptor, this.beanManager .getBeanDescriptor(this.parametersBeanClass)); descriptor.setDefaultCategory(this.defaultCategory); setDescriptor(descriptor); Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroManagerTest.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroManagerTest.java (revision 27222) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroManagerTest.java (working copy) @@ -208,9 +208,9 @@ { DocumentReference wikiMacroDocReference = new DocumentReference("xwiki", "Main", "TestWikiMacro"); - WikiMacroDescriptor descriptor = new WikiMacroDescriptor("Test Wiki Macro", "Description", "Test", - visibility, new DefaultContentDescriptor(), new ArrayList()); - DefaultWikiMacro wikiMacro = new DefaultWikiMacro(wikiMacroDocReference, "testwikimacro", true, descriptor, + WikiMacroDescriptor descriptor = new WikiMacroDescriptor(new MacroId("testwikimacro"), "Test Wiki Macro", "Description", + "Test", visibility, new DefaultContentDescriptor(), new ArrayList()); + DefaultWikiMacro wikiMacro = new DefaultWikiMacro(wikiMacroDocReference, true, descriptor, "== Test ==", "xwiki/2.0", getComponentManager()); return wikiMacro; Index: xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/descriptor/AbstractMacroDescriptor.java =================================================================== --- xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/descriptor/AbstractMacroDescriptor.java (revision 27222) +++ xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/descriptor/AbstractMacroDescriptor.java (working copy) @@ -25,6 +25,7 @@ import org.xwiki.properties.BeanDescriptor; import org.xwiki.properties.PropertyDescriptor; +import org.xwiki.rendering.macro.MacroId; /** * Describe a macro. @@ -35,6 +36,11 @@ public abstract class AbstractMacroDescriptor implements MacroDescriptor { /** + * @see #getId() + */ + private MacroId id; + + /** * @see #getName() */ private String name; @@ -68,13 +74,35 @@ private Map parameterDescriptorMap = new LinkedHashMap(); /** + * @param id the id of the macro + * @param name the name of the macro (eg "Table Of Contents" for the TOC macro) + * @param description the description of the macro. + * @param contentDescriptor the description of the macro content. null indicate macro does not support content. + * @param parametersBeanDescriptor the description of the parameters bean or null if there are no parameters for + * this macro. + * @since 2.3M1 + */ + public AbstractMacroDescriptor(MacroId id, String name, String description, ContentDescriptor contentDescriptor, + BeanDescriptor parametersBeanDescriptor) + { + this.id = id; + this.name = name; + this.description = description; + this.contentDescriptor = contentDescriptor; + this.parametersBeanDescriptor = parametersBeanDescriptor; + } + + /** * @param name the name of the macro (eg "Table Of Contents" for the TOC macro) * @param description the description of the macro. * @param contentDescriptor the description of the macro content. null indicate macro does not support content. * @param parametersBeanDescriptor the description of the parameters bean or null if there are no parameters for * this macro. * @since 2.0M3 + * @deprecated since 2.3M1 use + * {@link #AbstractMacroDescriptor(MacroId, String, String, ContentDescriptor, BeanDescriptor)} instead */ + @Deprecated public AbstractMacroDescriptor(String name, String description, ContentDescriptor contentDescriptor, BeanDescriptor parametersBeanDescriptor) { @@ -101,6 +129,17 @@ /** * {@inheritDoc} * + * @see MacroDescriptor#getId() + * @since 2.3M1 + */ + public MacroId getId() + { + return this.id; + } + + /** + * {@inheritDoc} + * * @see MacroDescriptor#getName() * @since 2.0M3 */ Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacro.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacro.java (revision 27222) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacro.java (working copy) @@ -97,11 +97,6 @@ private DocumentReference macroDocumentReference; /** - * Id under which this macro is registered with component manager. - */ - private String macroId; - - /** * Whether this macro supports inline mode or not. */ private boolean supportsInlineMode; @@ -135,13 +130,38 @@ * @param macroContent macro content to be evaluated. * @param syntaxId syntax of the macroContent. * @param componentManager {@link ComponentManager} component used to look up for other components. + * @since 2.3M1 + */ + public DefaultWikiMacro(DocumentReference macroDocumentReference, boolean supportsInlineMode, + MacroDescriptor descriptor, String macroContent, String syntaxId, ComponentManager componentManager) + { + this.macroDocumentReference = macroDocumentReference; + this.supportsInlineMode = supportsInlineMode; + this.descriptor = descriptor; + this.content = macroContent; + this.syntaxId = syntaxId; + this.parserUtils = new ParserUtils(); + this.componentManager = componentManager; + } + + /** + * Constructs a new {@link DefaultWikiMacro}. + * + * @param macroDocumentReference the name of the document which contains the definition of this macro + * @param macroId id under which this macro is registered with component manager. + * @param descriptor the {@link MacroDescriptor} describing this macro. + * @param macroContent macro content to be evaluated. + * @param syntaxId syntax of the macroContent. + * @param componentManager {@link ComponentManager} component used to look up for other components. * @since 2.2M1 + * @deprecated since 2.3M1 use {@link DefaultWikiMacro(DocumentReference, boolean, MacroDescriptor, String, String, + * ComponentManager)} instead */ + @Deprecated public DefaultWikiMacro(DocumentReference macroDocumentReference, String macroId, boolean supportsInlineMode, MacroDescriptor descriptor, String macroContent, String syntaxId, ComponentManager componentManager) { this.macroDocumentReference = macroDocumentReference; - this.macroId = macroId; this.supportsInlineMode = supportsInlineMode; this.descriptor = descriptor; this.content = macroContent; @@ -274,7 +294,7 @@ */ public String getId() { - return this.macroId; + return this.descriptor.getId().getId(); } /** Index: xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/descriptor/MacroDescriptor.java =================================================================== --- xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/descriptor/MacroDescriptor.java (revision 27222) +++ xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/macro/descriptor/MacroDescriptor.java (working copy) @@ -21,6 +21,8 @@ import java.util.Map; +import org.xwiki.rendering.macro.MacroId; + /** * Describe a Macro (macro description and macro parameters description). * @@ -30,6 +32,12 @@ public interface MacroDescriptor { /** + * @return the id of the macro + * @since 2.3M1 + */ + MacroId getId(); + + /** * @return the human-readable name of the macro (eg "Table Of Contents" for the TOC macro). * @since 2.0M3 */ Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroTest.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroTest.java (revision 27222) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroTest.java (working copy) @@ -27,6 +27,7 @@ import org.xwiki.component.descriptor.DefaultComponentDescriptor; import org.xwiki.context.Execution; import org.xwiki.rendering.converter.Converter; +import org.xwiki.rendering.macro.MacroId; import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor; import org.xwiki.rendering.macro.wikibridge.WikiMacroDescriptor; import org.xwiki.rendering.macro.wikibridge.WikiMacroManager; @@ -133,10 +134,10 @@ List parameterDescriptors = Arrays.asList( new WikiMacroParameterDescriptor("param1", "This is param1", true), new WikiMacroParameterDescriptor("param2", "This is param2", true)); - WikiMacroDescriptor descriptor = new WikiMacroDescriptor("Wiki Macro", "Description", "Test", + WikiMacroDescriptor descriptor = new WikiMacroDescriptor(new MacroId(macroId), "Wiki Macro", "Description", "Test", WikiMacroVisibility.GLOBAL, new DefaultContentDescriptor(false), parameterDescriptors); - DefaultWikiMacro wikiMacro = new DefaultWikiMacro(wikiMacroDocumentReference, macroId, true, descriptor, + DefaultWikiMacro wikiMacro = new DefaultWikiMacro(wikiMacroDocumentReference, true, descriptor, macroContent, "xwiki/2.0", getComponentManager()); wikiMacroManager.registerWikiMacro(wikiMacroDocumentReference, wikiMacro); Index: xwiki-rendering/xwiki-rendering-api/pom.xml =================================================================== --- xwiki-rendering/xwiki-rendering-api/pom.xml (revision 27222) +++ xwiki-rendering/xwiki-rendering-api/pom.xml (working copy) @@ -198,6 +198,7 @@ **/internal/** + org/xwiki/rendering/macro/descriptor/MacroDescriptor org/xwiki/rendering/syntax/SyntaxFactory org/xwiki/rendering/internal/parser/DefaultSyntaxFactory org/xwiki/rendering/syntax/Syntax