On Sun, Aug 9, 2009 at 9:37 PM, Vincent Massol<[email protected]> wrote: > > On Aug 9, 2009, at 9:12 PM, asiri (SVN) wrote: > >> Author: asiri >> Date: 2009-08-09 21:12:30 +0200 (Sun, 09 Aug 2009) >> New Revision: 22449 >> >> Modified: >> >> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/macro/DefaultMacroCategoriesManager.java >> >> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/test/java/org/xwiki/rendering/internal/macro/DefaultMacroCategoriesManagerTest.java >> Log: >> XWIKI-4131: Add support for organizing macros by category >> >> * getMacroNames() should return only macro names, not macro hints. >> * Fixed a NPE possibility. >> * Added one more test case. >> >> Modified: >> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/macro/DefaultMacroCategoriesManager.java >> =================================================================== >> --- >> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/macro/DefaultMacroCategoriesManager.java >> 2009-08-09 14:04:29 UTC (rev 22448) >> +++ >> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/macro/DefaultMacroCategoriesManager.java >> 2009-08-09 19:12:30 UTC (rev 22449) >> @@ -19,25 +19,25 @@ >> */ >> package org.xwiki.rendering.internal.macro; >> >> +import java.util.Collections; >> +import java.util.HashMap; >> +import java.util.HashSet; >> +import java.util.Map; >> +import java.util.Properties; >> +import java.util.Set; >> + >> import org.xwiki.component.annotation.Component; >> import org.xwiki.component.annotation.Requirement; >> import org.xwiki.component.logging.AbstractLogEnabled; >> import org.xwiki.component.manager.ComponentLookupException; >> import org.xwiki.component.manager.ComponentManager; >> +import org.xwiki.rendering.configuration.RenderingConfiguration; >> import org.xwiki.rendering.macro.Macro; >> import org.xwiki.rendering.macro.MacroCategoriesManager; >> import org.xwiki.rendering.macro.MacroLookupException; >> import org.xwiki.rendering.macro.MacroManager; >> import org.xwiki.rendering.parser.Syntax; >> -import org.xwiki.rendering.configuration.RenderingConfiguration; >> >> -import java.util.Set; >> -import java.util.Collections; >> -import java.util.Map; >> -import java.util.HashMap; >> -import java.util.Properties; >> -import java.util.HashSet; >> - >> /** >> * Default implementation of {...@link MacroCategoriesManager}. >> * >> @@ -115,7 +115,7 @@ >> return true; >> } >> }).get(category); >> - return Collections.unmodifiableSet(macros); >> + return (null != macros) ? Collections.unmodifiableSet(macros) : >> Collections.<String>emptySet(); >> } >> >> /** >> @@ -131,7 +131,7 @@ >> return macroManager.exists(macroName, syntax); >> } >> }).get(category); >> - return Collections.unmodifiableSet(macros); >> + return (null != macros) ? Collections.unmodifiableSet(macros) : >> Collections.<String>emptySet(); >> } >> >> /** >> @@ -152,8 +152,21 @@ >> >> // Loop through all the macros and categorize them. >> Properties categories = this.configuration.getMacroCategories(); >> - for (Map.Entry<String, Macro> entry : allMacros.entrySet()) { >> - if (matcher.match(entry.getKey())) { >> + for (Map.Entry<String, Macro> entry : allMacros.entrySet()) { >> + // Extract macro name. >> + String [] hintParts = entry.getKey().split("/"); >> + String macroName = null; >> + if (hintParts.length > 0) { >> + macroName = hintParts[0]; >> + } else { >> + // Question: Will we ever reach this code? >> + getLogger().warn("Invalid macro hint : [" + >> entry.getKey() + "]"); >> + // Skip this macro. >> + continue; >> + } > > This can be improved by sharing code with the MacroManager, by creating some > kind of macro syntax parser or factory.
I'm doing this with a new MacroId and MacroIdFactory as part of http://jira.xwiki.org/jira/browse/XWIKI-4142 -Vincent > Another solution is to rethink they way we register a macro for a given > syntax. > > [snip] > > Thanks > -Vincent > > _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

