[xwiki-devs] [Proposal] Add getID and getCategory methods to MacroDescriptor
Hi devs, I'm proposing we add to org.xwiki.rendering.macro.descriptor.MacroDescriptor [0] the following methods: 1/ MacroId getId(); 2/ String getCategory(); // Note: Actually it should allow multiple categories for one macro, not just one, because usually this is the case There is a method called getDefaultCategory() in MacroDescriptor: String getDefaultCategory(); , but it is not the final category, as it can overridden by the wiki Admin. (see method comment in api) So, right now, if you have a list of MacroDescriptors, there is no way of telling which is the ID or the real category of each macro. Also, there is no "getRealMacroCategory by macroId"-like method neither in MacroCategorymManager [1], nor in MacroManager [2]. We should either have a getCategory() or getCategories() method in MacroDescriptor, or a getMacroCategory(MacroId macroId)/getMacroCategories(MacroId macroId) in MacroManager/MacroCategoryManager. Right now, whenever someone needs to add id or category to the macro descriptor, ends up creating their own MacroDescriptor class, which is the case of org.xwiki.gwt.wysiwyg.client.plugin.macro.MacroDescriptor [3] or in my case. More about why I need the macroId in the MacroDescriptor: - I need a component that returns the list of all macros (both XWiki Java Macros and XWiki Wiki Macros) in Velocity. The list needs to be sorted by the Macro Name, and not by the Macro ID. - Once I get the list, I need to display the info for each of them, plus a link to their wiki page (nonexistent at this point). Wiki Macros do have wiki pages (the ones with a XWiki.WikiMacroClass object attached), but the Java Macros don't. For the Java Macros, we could use the MacroId in the URL to identify the macro. Note: I cannot use org.xwiki.gwt.wysiwyg.client.plugin.macro.MacroDescriptor, because my component would depend on the gwt.wysiwyg module, and has nothing to do with it. Related Questions: 1/ How can I tell of which type is a macro (Wiki or Java), if I have its macro descriptor/id? 2/ How can I get the wiki page with the XWiki.WikiMacroClass for a given Wiki Macro, if I have its descriptor/id? So far, I couldn't think of anything better than doing a HQL for the document with a XWiki.WikiMacroClass object with the property macroId set to the one I'm looking for. Code snippet follows: #set($macros = $gadgets.getMacroDefinitions()) #foreach($m in $macros) #set($hql = "select doc.fullName from XWikiDocument doc, BaseObject obj, StringProperty prop where doc.fullName=obj.name and obj.className='XWiki.WikiMacroClass' and prop.id.id=obj.id and prop.name='id' and prop.value='${m.getMacroId().id}'") #set($results = $xwiki.search($hql)) #if($results.size() > 0) #set($macroDoc = $results.get(0)) ... Thanks, Anamaria [0] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [1] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [2] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki... [3] http://svn.xwiki.org/svnroot/xwiki/platform/web/trunk/xwiki-gwt-wysiwyg-clie...
On 02/11/2010 01:22 PM, Anamaria Stoica wrote:
Hi devs,
I'm proposing we add to org.xwiki.rendering.macro.descriptor.MacroDescriptor [0] the following methods:
1/ MacroId getId();
+1
2/ String getCategory(); // Note: Actually it should allow multiple categories for one macro, not just one, because usually this is the case
+0 +1 for the idea, but we must decide if we want a list or a single value (I'd prefer a list), and if we want a String or something more specific, like a MacroCategory object (I'd prefer the object).
There is a method called getDefaultCategory() in MacroDescriptor: String getDefaultCategory(); , but it is not the final category, as it can overridden by the wiki Admin. (see method comment in api)
So, right now, if you have a list of MacroDescriptors, there is no way of telling which is the ID or the real category of each macro.
Also, there is no "getRealMacroCategory by macroId"-like method neither in MacroCategorymManager [1], nor in MacroManager [2].
We should either have a getCategory() or getCategories() method in MacroDescriptor, or a getMacroCategory(MacroId macroId)/getMacroCategories(MacroId macroId) in MacroManager/MacroCategoryManager.
Right now, whenever someone needs to add id or category to the macro descriptor, ends up creating their own MacroDescriptor class, which is the case of org.xwiki.gwt.wysiwyg.client.plugin.macro.MacroDescriptor [3] or in my case.
More about why I need the macroId in the MacroDescriptor: - I need a component that returns the list of all macros (both XWiki Java Macros and XWiki Wiki Macros) in Velocity. The list needs to be sorted by the Macro Name, and not by the Macro ID. - Once I get the list, I need to display the info for each of them, plus a link to their wiki page (nonexistent at this point). Wiki Macros do have wiki pages (the ones with a XWiki.WikiMacroClass object attached), but the Java Macros don't. For the Java Macros, we could use the MacroId in the URL to identify the macro.
Note: I cannot use org.xwiki.gwt.wysiwyg.client.plugin.macro.MacroDescriptor, because my component would depend on the gwt.wysiwyg module, and has nothing to do with it.
Related Questions: 1/ How can I tell of which type is a macro (Wiki or Java), if I have its macro descriptor/id? 2/ How can I get the wiki page with the XWiki.WikiMacroClass for a given Wiki Macro, if I have its descriptor/id? So far, I couldn't think of anything better than doing a HQL for the document with a XWiki.WikiMacroClass object with the property macroId set to the one I'm looking for. Code snippet follows:
#set($macros = $gadgets.getMacroDefinitions()) #foreach($m in $macros) #set($hql = "select doc.fullName from XWikiDocument doc, BaseObject obj, StringProperty prop where doc.fullName=obj.name and obj.className='XWiki.WikiMacroClass' and prop.id.id=obj.id and prop.name='id' and prop.value='${m.getMacroId().id}'") #set($results = $xwiki.search($hql))
#if($results.size()> 0) #set($macroDoc = $results.get(0)) ...
Thanks, Anamaria
[0] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[1] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[2] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[3] http://svn.xwiki.org/svnroot/xwiki/platform/web/trunk/xwiki-gwt-wysiwyg-clie...
-- Sergiu Dumitriu http://purl.org/net/sergiu/
On Thu, Feb 11, 2010 at 13:22, Anamaria Stoica <[email protected]> wrote:
Hi devs,
I'm proposing we add to org.xwiki.rendering.macro.descriptor.MacroDescriptor [0] the following methods:
1/ MacroId getId();
+1, since macro are component each instance can only refer to one role hint so it's ok to provide it in the descriptor. Note that a macro has no way to know its id so it will have to be set explicitly in all macros initialization code (that's why it was not already provided by the macro interface), and it also mean it will be possible to make mistake since we will have the same technical information in two different places.
2/ String getCategory(); // Note: Actually it should allow multiple categories for one macro, not just one, because usually this is the case
-1, we already talked about that when we implemented macros categories and it's not MacroDescriptor job to get the final category. If you do that: * you make all macros depends on configuration module for something that is not really part of the macro itself * the main reason was that a macro should not be able to return the final category it wants. If you overwrite a category for a macro in the configuration the only way to make sure you will really get the proper final category is by not letting the macro return it and getting it yourself. We could add a MacroCategoryManager#getMacroCategory(String macroId)
There is a method called getDefaultCategory() in MacroDescriptor: String getDefaultCategory(); , but it is not the final category, as it can overridden by the wiki Admin. (see method comment in api)
So, right now, if you have a list of MacroDescriptors, there is no way of telling which is the ID or the real category of each macro.
Also, there is no "getRealMacroCategory by macroId"-like method neither in MacroCategorymManager [1], nor in MacroManager [2].
We should either have a getCategory() or getCategories() method in MacroDescriptor, or a getMacroCategory(MacroId macroId)/getMacroCategories(MacroId macroId) in MacroManager/MacroCategoryManager.
Right now, whenever someone needs to add id or category to the macro descriptor, ends up creating their own MacroDescriptor class, which is the case of org.xwiki.gwt.wysiwyg.client.plugin.macro.MacroDescriptor [3] or in my case.
More about why I need the macroId in the MacroDescriptor: - I need a component that returns the list of all macros (both XWiki Java Macros and XWiki Wiki Macros) in Velocity. The list needs to be sorted by the Macro Name, and not by the Macro ID. - Once I get the list, I need to display the info for each of them, plus a link to their wiki page (nonexistent at this point). Wiki Macros do have wiki pages (the ones with a XWiki.WikiMacroClass object attached), but the Java Macros don't. For the Java Macros, we could use the MacroId in the URL to identify the macro.
Note: I cannot use org.xwiki.gwt.wysiwyg.client.plugin.macro.MacroDescriptor, because my component would depend on the gwt.wysiwyg module, and has nothing to do with it.
Related Questions: 1/ How can I tell of which type is a macro (Wiki or Java), if I have its macro descriptor/id? 2/ How can I get the wiki page with the XWiki.WikiMacroClass for a given Wiki Macro, if I have its descriptor/id? So far, I couldn't think of anything better than doing a HQL for the document with a XWiki.WikiMacroClass object with the property macroId set to the one I'm looking for. Code snippet follows:
#set($macros = $gadgets.getMacroDefinitions()) #foreach($m in $macros) #set($hql = "select doc.fullName from XWikiDocument doc, BaseObject obj, StringProperty prop where doc.fullName=obj.name and obj.className='XWiki.WikiMacroClass' and prop.id.id=obj.id and prop.name='id' and prop.value='${m.getMacroId().id}'") #set($results = $xwiki.search($hql))
#if($results.size() > 0) #set($macroDoc = $results.get(0)) ...
Thanks, Anamaria
[0] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[1] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[2] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[3] http://svn.xwiki.org/svnroot/xwiki/platform/web/trunk/xwiki-gwt-wysiwyg-clie... _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
Thomas Mortagne wrote:
On Thu, Feb 11, 2010 at 13:22, Anamaria Stoica <[email protected]> wrote:
Hi devs,
I'm proposing we add to org.xwiki.rendering.macro.descriptor.MacroDescriptor [0] the following methods:
1/ MacroId getId();
+1, since macro are component each instance can only refer to one role hint so it's ok to provide it in the descriptor. Note that a macro has no way to know its id so it will have to be set explicitly in all macros initialization code (that's why it was not already provided by the macro interface), and it also mean it will be possible to make mistake since we will have the same technical information in two different places.
+1
2/ String getCategory(); // Note: Actually it should allow multiple categories for one macro, not just one, because usually this is the case
-1, we already talked about that when we implemented macros categories and it's not MacroDescriptor job to get the final category. If you do that: * you make all macros depends on configuration module for something that is not really part of the macro itself * the main reason was that a macro should not be able to return the final category it wants. If you overwrite a category for a macro in the configuration the only way to make sure you will really get the proper final category is by not letting the macro return it and getting it yourself.
We could add a MacroCategoryManager#getMacroCategory(String macroId)
+1 Thanks, Marius
There is a method called getDefaultCategory() in MacroDescriptor: String getDefaultCategory(); , but it is not the final category, as it can overridden by the wiki Admin. (see method comment in api)
So, right now, if you have a list of MacroDescriptors, there is no way of telling which is the ID or the real category of each macro.
Also, there is no "getRealMacroCategory by macroId"-like method neither in MacroCategorymManager [1], nor in MacroManager [2].
We should either have a getCategory() or getCategories() method in MacroDescriptor, or a getMacroCategory(MacroId macroId)/getMacroCategories(MacroId macroId) in MacroManager/MacroCategoryManager.
Right now, whenever someone needs to add id or category to the macro descriptor, ends up creating their own MacroDescriptor class, which is the case of org.xwiki.gwt.wysiwyg.client.plugin.macro.MacroDescriptor [3] or in my case.
More about why I need the macroId in the MacroDescriptor: - I need a component that returns the list of all macros (both XWiki Java Macros and XWiki Wiki Macros) in Velocity. The list needs to be sorted by the Macro Name, and not by the Macro ID. - Once I get the list, I need to display the info for each of them, plus a link to their wiki page (nonexistent at this point). Wiki Macros do have wiki pages (the ones with a XWiki.WikiMacroClass object attached), but the Java Macros don't. For the Java Macros, we could use the MacroId in the URL to identify the macro.
Note: I cannot use org.xwiki.gwt.wysiwyg.client.plugin.macro.MacroDescriptor, because my component would depend on the gwt.wysiwyg module, and has nothing to do with it.
Related Questions: 1/ How can I tell of which type is a macro (Wiki or Java), if I have its macro descriptor/id? 2/ How can I get the wiki page with the XWiki.WikiMacroClass for a given Wiki Macro, if I have its descriptor/id? So far, I couldn't think of anything better than doing a HQL for the document with a XWiki.WikiMacroClass object with the property macroId set to the one I'm looking for. Code snippet follows:
#set($macros = $gadgets.getMacroDefinitions()) #foreach($m in $macros) #set($hql = "select doc.fullName from XWikiDocument doc, BaseObject obj, StringProperty prop where doc.fullName=obj.name and obj.className='XWiki.WikiMacroClass' and prop.id.id=obj.id and prop.name='id' and prop.value='${m.getMacroId().id}'") #set($results = $xwiki.search($hql))
#if($results.size() > 0) #set($macroDoc = $results.get(0)) ...
Thanks, Anamaria
[0] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[1] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[2] http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwiki...
[3] http://svn.xwiki.org/svnroot/xwiki/platform/web/trunk/xwiki-gwt-wysiwyg-clie... _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (4)
-
Anamaria Stoica -
Marius Dumitru Florea -
Sergiu Dumitriu -
Thomas Mortagne