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/xwik…
[1]
http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwik…
[2]
http://svn.xwiki.org/svnroot/xwiki/platform/core/trunk/xwiki-rendering/xwik…
[3]
http://svn.xwiki.org/svnroot/xwiki/platform/web/trunk/xwiki-gwt-wysiwyg-cli…
--
Sergiu Dumitriu
http://purl.org/net/sergiu/