Hi
I think I am close having finished the Blog Upgrade to 2.0 Syntax. The only major issue I have is that if i have WYSIWYG as the default editor I cannot switch the editor because in the 2.0 WYSIWYG toolbar there is no SWITCH EDITOR icon.
This seems to be the default behavior in 2.0 which is fine for regular pages but in the Blog this is not working out because there is no way the user can switch between the editors because there is no 'Choose editor' panel.
Any way to reintroduce that SWITCH EDITOR icon onto the 2.0 Toolbar?
Cheers
Andreas Schaefer
CEO of Madplanet.com Inc.
EMail: andreas.schaefer(a)madplanet.com
schaefera(a)me.com
Twitter: andy_mpc
AIM: schaefera(a)me.com
Here is a first review try (pretty difficult to review all that). My
first replies was rejected by the mailing list because it was too
long...
[snip]
>Modified: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki=
.java
>--- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java =
2009-07-15 17:48:48 UTC (rev 21966)
>+++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/XWiki.java =
2009-07-15 18:57:45 UTC (rev 21967)
>@@ -91,6 +91,7 @@
> import org.xwiki.observation.event.DocumentSaveEvent;
> import org.xwiki.observation.event.DocumentUpdateEvent;
> import org.xwiki.query.QueryException;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroInitializer;
>
> import com.xpn.xwiki.api.Api;
> import com.xpn.xwiki.api.Document;
>@@ -775,6 +776,14 @@
> // Save the configured syntaxes
> String syntaxes =3D Param("xwiki.rendering.syntaxes", "xwiki/1.0")=
;
> this.configuredSyntaxes =3D Arrays.asList(StringUtils.split(syntax=
es, " ,"));
>+
>+ // Initialize all wiki macros
You should add a more consistent TODO here since it's a temporary hack
>+ try {
>+ WikiMacroInitializer wikiMacroInitializer =3D Utils.getCompon=
entManager().lookup(WikiMacroInitializer.class);
>+ wikiMacroInitializer.init();
>+ } catch (ComponentLookupException ex) {
>+ LOG.error("Error while initializing wiki macros", ex);
>+ }
> }
>
> public XWikiStoreInterface getNotCacheStore()
>
>Added: platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal=
/DefaultWikiMacroBuilder.java
>--- platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/De=
faultWikiMacroBuilder.java (rev 0)
>+++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/De=
faultWikiMacroBuilder.java 2009-07-15 18:57:45 UTC (rev 21967)
>@@ -0,0 +1,170 @@
>+/*
>+ * See the NOTICE file distributed with this work for additional
>+ * information regarding copyright ownership.
>+ *
>+ * This is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU Lesser General Public License as
>+ * published by the Free Software Foundation; either version 2.1 of
>+ * the License, or (at your option) any later version.
>+ *
>+ * This software is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this software; if not, write to the Free
>+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>+ */
>+
>+package com.xpn.xwiki.internal;
>+
>+import java.util.ArrayList;
>+import java.util.List;
>+import java.util.Vector;
>+
>+import org.apache.commons.lang.StringUtils;
>+import org.xwiki.component.annotation.Component;
>+import org.xwiki.component.annotation.Requirement;
>+import org.xwiki.component.logging.AbstractLogEnabled;
>+import org.xwiki.component.manager.ComponentManager;
>+import org.xwiki.context.Execution;
>+import org.xwiki.rendering.macro.descriptor.MacroDescriptor;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacro;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroBuilder;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroBuilderException;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroDescriptor;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroParameterDescriptor;
>+
>+import com.xpn.xwiki.XWikiContext;
>+import com.xpn.xwiki.XWikiException;
>+import com.xpn.xwiki.doc.XWikiDocument;
>+import com.xpn.xwiki.objects.BaseObject;
>+
>+/**
>+ * The default implementation of {@link WikiMacroBuilder}.
>+ *
>+ * @version $Id$
Looks like your svn client is not properly configured.
>+ * @since 2.0M2
>+ */
>+@Component
>+public class DefaultWikiMacroBuilder extends AbstractLogEnabled implement=
s WikiMacroBuilder
>+{
>+ /**
>+ * The {@link ComponentManager} component.
>+ */
>+ @Requirement
>+ private ComponentManager componentManager;
>+
>+ /**
>+ * The {@link Execution} component used for accessing XWikiContext.
>+ */
>+ @Requirement
>+ private Execution execution;
>+
>+ /**
>+ * Utility method for accessing XWikiContext.
>+ *
>+ * @return the XWikiContext.
>+ */
>+ private XWikiContext getContext()
>+ {
>+ return (XWikiContext) this.execution.getContext().getProperty("xw=
ikicontext");
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public WikiMacro buildMacro(String documentName) throws WikiMacroBuil=
derException
>+ {
>+ XWikiDocument doc =3D null;
>+ try {
>+ doc =3D getContext().getWiki().getDocument(documentName, getC=
ontext());
>+ } catch (XWikiException ex) {
>+ throw new WikiMacroBuilderException(String.format(
>+ "Could not build macro from : [%s], unable to load docume=
nt", documentName), ex);
>+ }
>+ return buildMacro(doc);
>+ }
>+
>+ /**
>+ * Creates a {@link WikiMacro} from an {@link XWikiDocument} which co=
ntains a macro definition.
>+ *
>+ * @param doc the {@link XWikiDocument} to look for a macro definitio=
n.
>+ * @return a {@link WikiMacro} found inside the document.
>+ * @throws WikiMacroBuilderException invalid macro definition / no ma=
cro definition found.
>+ */
>+ private WikiMacro buildMacro(XWikiDocument doc) throws WikiMacroBuild=
erException
>+ {
>+ // Check whether this document contains a macro definition.
>+ BaseObject macroDefinition =3D doc.getObject(WIKI_MACRO_CLASS);
>+ if (null =3D=3D macroDefinition) {
>+ throw new WikiMacroBuilderException(String.format("No macro d=
efinition found in document : [%s]", doc
>+ .getFullName()));
>+ }
>+
>+ // Extract macro definition.
>+ String macroName =3D macroDefinition.getStringValue(MACRO_NAME_PR=
OPERTY);
>+ String macroDescription =3D macroDefinition.getStringValue(MACRO_=
DESCRIPTION_PROPERTY);
>+ String macroContent =3D macroDefinition.getStringValue(MACRO_CONT=
ENT_PROPERTY);
>+
>+ // Verify macro name.
>+ if (StringUtils.isEmpty(macroName)) {
>+ throw new WikiMacroBuilderException(String.format(
>+ "Incomplete macro definition in [%s], macro name is empty=
", doc.getFullName()));
>+ }
>+
>+ // Verify macro description.
>+ if (StringUtils.isEmpty(macroDescription)) {
>+ getLogger().warn(
>+ String.format("Incomplete macro definition in [%s], macro=
description is empty", doc.getFullName()));
>+ }
>+
>+ // Verify macro content.
>+ if (StringUtils.isEmpty(macroContent)) {
>+ throw new WikiMacroBuilderException(String.format(
>+ "Incomplete macro definition in [%s], macro content is em=
pty", doc.getFullName()));
>+ }
>+
>+ // Extract macro parameters.
>+ List<WikiMacroParameterDescriptor> parameterDescriptors =3D new A=
rrayList<WikiMacroParameterDescriptor>();
>+ Vector<BaseObject> macroParameters =3D doc.getObjects(WIKI_MACRO_=
PARAMETER_CLASS);
>+ if (null !=3D macroParameters) {
>+ for (BaseObject macroParameter : macroParameters) {
>+ // Vectors can contain null values
>+ if (null =3D=3D macroParameter) {
>+ continue;
>+ }
>+
>+ // Extract parameter definition.
>+ String parameterName =3D macroParameter.getStringValue(PA=
RAMETER_NAME_PROPERTY);
>+ String parameterDescription =3D macroParameter.getStringV=
alue(PARAMETER_DESCRIPTION_PROPERTY);
>+ boolean parameterMandatory =3D
>+ (macroParameter.getIntValue(PARAMETER_MANDATORY_PROPE=
RTY) =3D=3D 0) ? false : true;
>+
>+ // Verify parameter name.
>+ if (StringUtils.isEmpty(parameterName)) {
>+ throw new WikiMacroBuilderException(String.format(
>+ "Incomplete macro definition in [%s], macro param=
eter name is empty", doc.getFullName()));
>+ }
>+
>+ // Verify parameter description.
>+ if (StringUtils.isEmpty(parameterDescription)) {
>+ String errorMessage =3D "Incomplete macro definition =
in [%s], macro parameter description is empty";
>+ getLogger().warn(String.format(errorMessage, doc.getF=
ullName()));
>+ }
>+
>+ // Create the parameter descriptor.
>+ parameterDescriptors.add(new WikiMacroParameterDescriptor=
(parameterName, parameterDescription,
>+ parameterMandatory));
>+ }
>+ }
>+
>+ // Create the macro descriptor.
>+ MacroDescriptor macroDescriptor =3D new WikiMacroDescriptor(macro=
Description, parameterDescriptors);
>+
>+ // Create & return the macro.
>+ return new WikiMacro(macroName, macroDescriptor, macroContent, do=
c.getSyntaxId(), componentManager);
>+ }
>+}
>
>Added: 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/De=
faultWikiMacroInitializer.java (rev 0)
>+++ platform/core/trunk/xwiki-core/src/main/java/com/xpn/xwiki/internal/De=
faultWikiMacroInitializer.java 2009-07-15 18:57:45 UTC (rev 21967)
>@@ -0,0 +1,122 @@
>+/*
>+ * See the NOTICE file distributed with this work for additional
>+ * information regarding copyright ownership.
>+ *
>+ * This is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU Lesser General Public License as
>+ * published by the Free Software Foundation; either version 2.1 of
>+ * the License, or (at your option) any later version.
>+ *
>+ * This software is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this software; if not, write to the Free
>+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>+ */
>+package com.xpn.xwiki.internal;
>+
>+import java.util.Arrays;
>+import java.util.HashMap;
>+import java.util.List;
>+import java.util.Map;
>+
>+import org.xwiki.component.annotation.Component;
>+import org.xwiki.component.annotation.Requirement;
>+import org.xwiki.component.logging.AbstractLogEnabled;
>+import org.xwiki.context.Execution;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroInitializer;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacro;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroBuilder;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroBuilderException;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroManager;
>+
>+import com.xpn.xwiki.XWikiContext;
>+import com.xpn.xwiki.XWikiException;
>+
>+/**
>+ * A {@link DefaultWikiMacroInitializer} providing wiki macros.
>+ *
>+ * @version $Id$
>+ * @since 2.0M2
>+ */
>+@Component
>+public class DefaultWikiMacroInitializer extends AbstractLogEnabled imple=
ments WikiMacroInitializer
>+{
>+ /**
>+ * Main wiki identifier.
>+ */
>+ private static final String MAIN_WIKI =3D "xwiki";
>+
>+ /**
>+ * The {@link WikiMacroBuilder} component.
>+ */
>+ @Requirement
>+ private WikiMacroBuilder wikiMacroBuilder;
>+
>+ /**
>+ * The {@link WikiMacroManager} component.
>+ */
>+ @Requirement
>+ private WikiMacroManager wikiMacroManager;
>+
>+ /**
>+ * The {@link Execution} component used for accessing XWikiContext.
>+ */
>+ @Requirement
>+ private Execution execution;
>+
>+ /**
>+ * Utility method for accessing XWikiContext.
>+ *
>+ * @return the XWikiContext.
>+ */
>+ private XWikiContext getContext()
>+ {
>+ return (XWikiContext) this.execution.getContext().getProperty("xw=
ikicontext");
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public void init()
>+ {
>+ XWikiContext xcontext =3D getContext();
>+
>+ // Only consider the main wiki.
>+ xcontext.setDatabase(MAIN_WIKI);
>+
>+ // Search for all those documents with macro definitions.
>+ String sql =3D
>+ "select doc.fullName from XWikiDocument doc, BaseObject obj w=
here doc.fullName=3Dobj.name and obj.className=3D?";
>+ List<Object> wikiMacroDocs =3D null;
>+ try {
>+ wikiMacroDocs =3D
>+ xcontext.getWiki().getStore().search(sql, 0, 0, Arrays.as=
List("XWiki.WikiMacroClass"), xcontext);
>+ } catch (XWikiException ex) {
>+ getLogger().error("Error while searching for macro documents"=
, ex);
>+ return;
>+ }
>+
>+ // Build macros.
>+ Map<String, WikiMacro> wikiMacros =3D new HashMap<String, WikiMac=
ro>();
>+ for (Object obj : wikiMacroDocs) {
>+ String wikiMacroDoc =3D (String) obj;
>+ try {
>+ WikiMacro macro =3D wikiMacroBuilder.buildMacro(wikiMacro=
Doc);
>+ wikiMacros.put(wikiMacroDoc, macro);
>+ } catch (WikiMacroBuilderException ex) {
>+ // Just log the exception and skip to the next.
>+ getLogger().error(ex.getMessage(), ex);
>+ }
>+ }
>+
>+ // Register the wiki macros against WikiMacroManager.
>+ for (String documentName : wikiMacros.keySet()) {
>+ wikiMacroManager.registerWikiMacro(MAIN_WIKI + ":" + document=
Name, wikiMacros.get(documentName));
>+ }
>+ }
>+}
>
[snip]
>Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main=
/java/org/xwiki/rendering/block/AbstractBlock.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/block/AbstractBlock.java 2009-07-15 17:48:48 UTC (rev =
21966)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/block/AbstractBlock.java 2009-07-15 18:57:45 UTC (rev =
21967)
>@@ -26,7 +26,6 @@
> import java.util.List;
> import java.util.Map;
>
>-import org.apache.commons.beanutils.ConvertUtils;
> import org.apache.commons.lang.builder.EqualsBuilder;
> import org.apache.commons.lang.builder.HashCodeBuilder;
>
>@@ -240,24 +239,6 @@
> }
>
> /**
>- * Set a parameter on the current block. A parameter is any semantic =
data associated with a block. It can be used
>- * for various purposes and provide additional information to the ren=
derers/listeners. For example you can pass
>- * style information such as <code>style=3D"color:red"</code> (in tha=
t example the name would be <code>style</code>
>- * and the value <code>"color:red"</code>) to indicate that the curre=
nt block should be displayed in red.
>- * <p>
>- * Note that there are currently no well-defined known parameter name=
s and you'll need to check what the different
>- * renderers/listeners support to know what to use.
>- * </p>
>- *
>- * @param name the parameter's name
>- * @param value the parameter's value
>- */
>- public void setParameter(String name, Object value)
>- {
>- setParameter(name, ConvertUtils.convert(value));
>- }
>-
>- /**
> * Set several parameters at once.
> *
> * @param parameters the parameters to set
>
>Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main=
/java/org/xwiki/rendering/internal/macro/DefaultMacroManager.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/internal/macro/DefaultMacroManager.java 2009-07-15 17=
:48:48 UTC (rev 21966)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/internal/macro/DefaultMacroManager.java 2009-07-15 18=
:57:45 UTC (rev 21967)
>@@ -19,7 +19,6 @@
> */
> package org.xwiki.rendering.internal.macro;
>
>-import java.util.HashMap;
> import java.util.Map;
> import java.util.Set;
> import java.util.TreeSet;
>@@ -29,8 +28,6 @@
> import org.xwiki.component.logging.AbstractLogEnabled;
> import org.xwiki.component.manager.ComponentLookupException;
> import org.xwiki.component.manager.ComponentManager;
>-import org.xwiki.component.phase.Initializable;
>-import org.xwiki.component.phase.InitializationException;
> import org.xwiki.rendering.macro.Macro;
> import org.xwiki.rendering.macro.MacroLookupException;
> import org.xwiki.rendering.macro.MacroManager;
>@@ -46,26 +43,14 @@
> * @since 1.9M1
> */
> @Component
>-public class DefaultMacroManager extends AbstractLogEnabled implements Ma=
croManager, Initializable
>+public class DefaultMacroManager extends AbstractLogEnabled implements Ma=
croManager
> {
> /**
>- * Cache of macros for syntax-specific macros. Index is the syntax an=
d value is a Map with an index being the macro
>- * name the value the Macro.
>- */
>- protected Map<Syntax, Map<String, Macro< ? >>> syntaxSpecificMacros;
>-
>- /**
>- * Cache of macros for macros registered for all syntaxes. Index is t=
he syntax and value is a Map with an index
>- * being the macro name the value the Macro.
>- */
>- protected Map<String, Macro< ? >> allSyntaxesMacros;
>-
>- /**
> * Allows transforming a syntax specified as text into a {@link Syntax=
} object. Injected by the component manager
> * subsystem.
> */
> @Requirement
>- protected SyntaxFactory syntaxFactory;
>+ private SyntaxFactory syntaxFactory;
>
> /**
> * The component manager we use to lookup macro implementations regist=
ered as components.
>@@ -74,51 +59,44 @@
> private ComponentManager componentManager;
>
> /**
>- * Creates a new {@link DefaultMacroManager} instance.
>- */
>- public DefaultMacroManager()
>- {
>- // Create macro caches.
>- this.syntaxSpecificMacros =3D new HashMap<Syntax, Map<String, Mac=
ro< ? >>>();
>- this.allSyntaxesMacros =3D new HashMap<String, Macro< ? >>();
>- }
>-
>- /**
> * {@inheritDoc}
> *
>- * @see Initializable#initialize()
>+ * @see org.xwiki.rendering.macro.MacroManager#getMacroNames(Syntax)
> */
> @SuppressWarnings("unchecked")
>- public void initialize() throws InitializationException
>+ public Set<String> getMacroNames(Syntax syntax) throws MacroLookupExc=
eption
> {
>- // Find all registered macros
>+ Set<String> result =3D new TreeSet<String>();
>+
>+ // Lookup all registered macros
> Map<String, Macro> allMacros;
> try {
> allMacros =3D this.componentManager.lookupMap(Macro.class);
> } catch (ComponentLookupException e) {
>- throw new InitializationException("Failed to lookup Macros", =
e);
>+ throw new MacroLookupException("Failed to lookup Macros", e);
> }
>
>- // Now sort through the ones that are registered for a given synt=
ax and those registered for all syntaxes.
>+ // Loop through all the macros and filter those macros that will =
work with the given syntax.
> for (Map.Entry<String, Macro> entry : allMacros.entrySet()) {
>-
> // Verify if we have a syntax specified.
> String[] hintParts =3D entry.getKey().split("/");
> if (hintParts.length =3D=3D 3) {
> // We've found a macro registered for a given syntax
> String syntaxAsString =3D hintParts[1] + "/" + hintParts[2=
];
> String macroName =3D hintParts[0];
>- Syntax syntax;
>+ Syntax macroSyntax;
> try {
>- syntax =3D this.syntaxFactory.createSyntaxFromIdStrin=
g(syntaxAsString);
>+ macroSyntax =3D this.syntaxFactory.createSyntaxFromId=
String(syntaxAsString);
> } catch (ParseException e) {
>- throw new InitializationException("Failed to initiali=
ze Macro [" + macroName
>+ throw new MacroLookupException("Failed to initialize =
Macro [" + macroName
> + "] due to an invalid Syntax [" + syntaxAsString =
+ "]", e);
> }
>- registerMacroForSyntax(macroName, syntax, entry.getValue(=
));
>+ if (macroSyntax.equals(syntax)) {
>+ result.add(macroName);
>+ }
> } else if (hintParts.length =3D=3D 1) {
> // We've found a macro registered for all syntaxes
>- registerMacroForAllSyntaxes(hintParts[0], entry.getValue(=
));
>+ result.add(hintParts[0]);
> } else {
> // We ignore invalid macro descriptors but log it as warni=
ng.
> getLogger()
>@@ -131,55 +109,7 @@
> + "This macro will not be available in the sys=
tem.");
> }
> }
>- }
>
>- /**
>- * Register a macro for a specific syntax.
>- *
>- * @param macroName the name of the macro to register.
>- * @param syntax the syntax for which to register the macro. If null =
the macro is registered for all syntaxes.
>- * @param macro the macro to register
>- */
>- protected void registerMacroForSyntax(String macroName, Syntax syntax=
, Macro< ? > macro)
>- {
>- Map<String, Macro< ? >> macrosForSyntax =3D this.syntaxSpecificMa=
cros.get(syntax);
>- if (macrosForSyntax =3D=3D null) {
>- macrosForSyntax =3D new HashMap<String, Macro< ? >>();
>- this.syntaxSpecificMacros.put(syntax, macrosForSyntax);
>- }
>-
>- macrosForSyntax.put(macroName, macro);
>- }
>-
>- /**
>- * Register a macro for all syntaxes.
>- *
>- * @param macroName the name of the macro to register.
>- * @param macro the macro to register
>- */
>- protected void registerMacroForAllSyntaxes(String macroName, Macro< ?=
> macro)
>- {
>- this.allSyntaxesMacros.put(macroName, macro);
>- }
>-
>- /**
>- * {@inheritDoc}
>- *
>- * @see org.xwiki.rendering.macro.MacroManager#getMacroNames(Syntax)
>- */
>- public Set<String> getMacroNames(Syntax syntax)
>- {
>- Set<String> result =3D new TreeSet<String>();
>-
>- // first we put the macros that are not specific to any syntax.
>- result.addAll(this.allSyntaxesMacros.keySet());
>-
>- // then we add macros for this syntax in particular if any.
>- // if macro with same name is defined for both, the one specific =
to the desired syntax wins.
>- if (this.syntaxSpecificMacros.containsKey(syntax)) {
>- result.addAll(this.syntaxSpecificMacros.get(syntax).keySet())=
;
>- }
>-
> return result;
> }
>
>@@ -190,14 +120,19 @@
> */
> public Macro< ? > getMacro(String macroName, Syntax syntax) throws Mac=
roLookupException
> {
>- // First check in macros registered for all syntaxes
>- Map<String, Macro< ? >> macrosForSyntax =3D this.syntaxSpecificMa=
cros.get(syntax);
>- if (macrosForSyntax !=3D null && macrosForSyntax.containsKey(macr=
oName)) {
>- return macrosForSyntax.get(macroName);
>+ // First search for a macro registered for the given syntax.
>+ String macroHint =3D macroName + "/" + syntax.toIdString();
>+ try {
>+ return componentManager.lookup(Macro.class, macroHint);
>+ } catch (ComponentLookupException ex1) {
>+ // Now search for a macro registered for all syntaxes.
>+ try {
>+ return componentManager.lookup(Macro.class, macroName);
>+ } catch (ComponentLookupException ex2) {
>+ throw new MacroLookupException(String.format("No macro na=
med [%s] is available for syntax [%s].",
>+ macroName, syntax.toIdString()));
>+ }
> }
>-
>- // If not found, check in macros for all syntaxes
>- return this.getMacro(macroName);
> }
>
> /**
>@@ -207,11 +142,11 @@
> */
> public Macro< ? > getMacro(String macroName) throws MacroLookupExcepti=
on
> {
>- if (this.allSyntaxesMacros.containsKey(macroName)) {
>- return this.allSyntaxesMacros.get(macroName);
>+ try {
>+ return componentManager.lookup(Macro.class, macroName);
>+ } catch (ComponentLookupException ex) {
>+ throw new MacroLookupException(String.format("No macro named =
[%s] can be found.", macroName));
> }
>-
>- throw new MacroLookupException("No [" + macroName + "] could be f=
ound");
> }
>
> /**
>@@ -221,9 +156,14 @@
> */
> public boolean exists(String macroName, Syntax syntax)
> {
>- return this.syntaxSpecificMacros.get(syntax) !=3D null
>- && this.syntaxSpecificMacros.get(syntax).get(macroName) !=3D =
null;
>-
>+ String macroHint =3D macroName + "/" + syntax.toIdString();
>+ boolean hasMacro =3D true;
>+ try {
>+ componentManager.lookup(Macro.class, macroHint);
>+ } catch (ComponentLookupException ex) {
>+ hasMacro =3D false;
>+ }
>+ return hasMacro;
> }
>
> /**
>@@ -233,6 +173,12 @@
> */
> public boolean exists(String macroName)
> {
>- return this.allSyntaxesMacros.get(macroName) !=3D null;
>+ boolean hasMacro =3D true;
>+ try {
>+ componentManager.lookup(Macro.class, macroName);
>+ } catch (ComponentLookupException ex) {
>+ hasMacro =3D false;
>+ }
>+ return hasMacro;
> }
> }
>
[snip]
>Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main=
/java/org/xwiki/rendering/macro/AbstractMacro.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/AbstractMacro.java 2009-07-15 17:48:48 UTC (rev =
21966)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/AbstractMacro.java 2009-07-15 18:57:45 UTC (rev =
21967)
>@@ -19,9 +19,14 @@
> */
> package org.xwiki.rendering.macro;
>
>-import org.apache.commons.beanutils.ConvertUtils;
>-import org.apache.commons.beanutils.Converter;
>+import org.xwiki.component.annotation.Requirement;
> import org.xwiki.component.logging.AbstractLogEnabled;
>+import org.xwiki.component.phase.Initializable;
>+import org.xwiki.component.phase.InitializationException;
>+import org.xwiki.properties.BeanManager;
>+import org.xwiki.rendering.macro.descriptor.ContentDescriptor;
>+import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor;
>+import org.xwiki.rendering.macro.descriptor.DefaultMacroDescriptor;
> import org.xwiki.rendering.macro.descriptor.MacroDescriptor;
>
> /**
>@@ -29,9 +34,30 @@
> * @version $Id$
> * @since 1.5M2
> */
>-public abstract class AbstractMacro<P> extends AbstractLogEnabled impleme=
nts Macro<P>
>+public abstract class AbstractMacro<P> extends AbstractLogEnabled impleme=
nts Macro<P>, Initializable
> {
> /**
>+ * The {@link BeanManager} component.
>+ */
>+ @Requirement
>+ protected BeanManager beanManager;
>+
>+ /**
>+ * Macro description used to generate the macro descriptor.
>+ */
>+ private String description;
>+
>+ /**
>+ * Content descriptor used to generate the macro descriptor.
>+ */
>+ private ContentDescriptor contentDescriptor;
>+
>+ /**
>+ * Parameter bean class used to generate the macro descriptor.
>+ */
>+ private Class< ? > parametersBeanClass;
>+
>+ /**
> * The descriptor of the macro.
> */
> private MacroDescriptor macroDescriptor;
>@@ -42,28 +68,65 @@
> private int priority =3D 1000;
>
> /**
>- * @param macroDescriptor the {@link MacroDescriptor}.
>+ * Creates a new {@link Macro} instance.
>+ *
>+ * @param description a string describing this macro.
> */
>- public AbstractMacro(MacroDescriptor macroDescriptor)
>+ public AbstractMacro(String description)
> {
>- setDescriptor(macroDescriptor);
>+ this.description =3D description;
>+ this.contentDescriptor =3D new DefaultContentDescriptor();
>+ this.parametersBeanClass =3D Object.class;
> }
>+
>+ /**
>+ * Creates a new {@link Macro} instance.
>+ *
>+ * @param description a string describing this macro.
>+ * @param contentDescriptor {@link ContentDescriptor} for this macro.
>+ */
>+ public AbstractMacro(String description, ContentDescriptor contentDes=
criptor)
>+ {
>+ this(description);
>+ this.contentDescriptor =3D contentDescriptor;
>+ }
>+
>+ /**
>+ * Creates a new {@link Macro} instance.
>+ *
>+ * @param description a string describing this macro.
>+ * @param parametersBeanClass class of the parameters bean of this ma=
cro.
>+ */
>+ public AbstractMacro(String description, Class< ? > parametersBeanCl=
ass)
>+ {
>+ this(description);
>+ this.parametersBeanClass =3D parametersBeanClass;
>+ }
>
> /**
>- * Register a converter for a specific type used by the macro paramet=
ers bean.
>- * <p>
>- * Note: each enum type used has to be registered because BeanUtil do=
es not support generic types.
>+ * Creates a new {@link Macro} instance.
> *
>- * @param converter the BeanUtil {@link Converter}
>- * @param clazz the class for which to assign the {@link Converter}
>+ * @param description string describing this macro.
>+ * @param contentDescriptor the {@link ContentDescriptor} describing =
the content of this macro.
>+ * @param parametersBeanClass class of the parameters bean.
> */
>- protected void registerConverter(Converter converter, Class< ? > claz=
z)
>+ public AbstractMacro(String description, ContentDescriptor contentDes=
criptor, Class< ? > parametersBeanClass)
> {
>- ConvertUtils.register(converter, clazz);
>+ this(description, contentDescriptor);
>+ this.parametersBeanClass =3D parametersBeanClass;
> }
>
> /**
> * {@inheritDoc}
>+ */
>+ public void initialize() throws InitializationException
>+ {
>+ setDescriptor(new DefaultMacroDescriptor(description, contentDesc=
riptor, beanManager
>+ .getBeanDescriptor(parametersBeanClass)));
>+ }
>+
>+ /**
>+ * {@inheritDoc}
> *
> * @see org.xwiki.rendering.macro.Macro#getPriority()
> */
>@@ -73,13 +136,13 @@
> }
>
> /**
>- * @param priority the macro priority to use (lower means execute bef=
ore others)
>+ * @param priority the macro priority to use (lower means execute bef=
ore others)
> */
> public void setPriority(int priority)
> {
> this.priority =3D priority;
> }
>-
>+
> /**
> * {@inheritDoc}
> *
>@@ -89,7 +152,7 @@
> {
> return this.macroDescriptor;
> }
>-
>+
> /**
> * {@inheritDoc}
> *
>@@ -102,10 +165,11 @@
> }
> return this.getClass().getSimpleName().compareTo(macro.getClass().=
getSimpleName());
> }
>-
>+
> /**
> * Allows macro classes extending other macro classes to override the =
macro descriptor with their own.
>- * @param descriptor the overriding descriptor to set
>+ *
>+ * @param descriptor the overriding descriptor to set
> */
> protected void setDescriptor(MacroDescriptor descriptor)
> {
>
>Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main=
/java/org/xwiki/rendering/macro/AbstractNoParameterMacro.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/AbstractNoParameterMacro.java 2009-07-15 17=
:48:48 UTC (rev 21966)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/AbstractNoParameterMacro.java 2009-07-15 18=
:57:45 UTC (rev 21967)
>@@ -19,7 +19,6 @@
> */
> package org.xwiki.rendering.macro;
>
>-import org.xwiki.rendering.macro.descriptor.DefaultMacroDescriptor;
>
> /**
> * Base class for a macro which does not support any parameter.
>@@ -36,6 +35,6 @@
> */
> public AbstractNoParameterMacro(String description)
> {
>- super(new DefaultMacroDescriptor(description));
>+ super(description);
> }
> }
>
>Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main=
/java/org/xwiki/rendering/macro/descriptor/AbstractMacroDescriptor.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/descriptor/AbstractMacroDescriptor.java 2009-=
07-15 17:48:48 UTC (rev 21966)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/descriptor/AbstractMacroDescriptor.java 2009-=
07-15 18:57:45 UTC (rev 21967)
>@@ -19,18 +19,12 @@
> */
> package org.xwiki.rendering.macro.descriptor;
>
>-import java.beans.BeanInfo;
>-import java.beans.Introspector;
>-import java.beans.PropertyDescriptor;
>-import java.lang.annotation.Annotation;
>-import java.lang.reflect.Method;
> import java.util.Collections;
> import java.util.LinkedHashMap;
> import java.util.Map;
>
>-import org.xwiki.rendering.macro.descriptor.annotation.ParameterDescripti=
on;
>-import org.xwiki.rendering.macro.descriptor.annotation.ParameterHidden;
>-import org.xwiki.rendering.macro.descriptor.annotation.ParameterMandatory=
;
>+import org.xwiki.properties.BeanDescriptor;
>+import org.xwiki.properties.PropertyDescriptor;
>
> /**
> * Describe a macro.
>@@ -51,9 +45,9 @@
> private ContentDescriptor contentDescriptor;
>
> /**
>- * The class of the JAVA bean containing macro parameters.
>+ * The description of the parameters bean.
> */
>- private Class< ? > parametersBeanClass;
>+ private BeanDescriptor parametersBeanDescriptor;
>
> /**
> * A map containing the {@link ParameterDescriptor} for each parameter=
s supported for this macro.
>@@ -66,110 +60,32 @@
> /**
> * @param description the description of the macro.
> * @param contentDescriptor the description of the macro content. null=
indicate macro does not support content.
>- * @param parametersBeanClass the class of the JAVA bean containing m=
acro parameters.
>+ * @param parametersBeanDescriptor the description of the parameters =
bean or null if there are no parameters for
>+ * this macro.
> */
> public AbstractMacroDescriptor(String description, ContentDescriptor c=
ontentDescriptor,
>- Class< ? > parametersBeanClass)
>+ BeanDescriptor parametersBeanDescriptor)
> {
> this.description =3D description;
>- this.parametersBeanClass =3D parametersBeanClass;
> this.contentDescriptor =3D contentDescriptor;
>+ this.parametersBeanDescriptor =3D parametersBeanDescriptor;
> }
>
> /**
>- * Extract parameters informations from {@link #parametersBeanClass} =
and insert it in
>+ * Extract parameters informations from {@link #parametersBeanDescrip=
tor} and insert it in
> * {@link #parameterDescriptorMap}.
> *
> * @since 1.7M2
> */
> protected void extractParameterDescriptorMap()
> {
>- try {
>- BeanInfo beanInfo =3D Introspector.getBeanInfo(this.parameter=
sBeanClass);
>- PropertyDescriptor[] propertyDescriptors =3D beanInfo.getProp=
ertyDescriptors();
>- if (propertyDescriptors !=3D null) {
>- for (PropertyDescriptor propertyDescriptor : propertyDesc=
riptors) {
>- if (propertyDescriptor !=3D null) {
>- extractParameterDescriptor(propertyDescriptor, ge=
tParametersBeanClass().newInstance());
>- }
>- }
>- }
>- } catch (Exception e) {
>- // TODO: add error log here
>+ for (PropertyDescriptor propertyDescriptor : parametersBeanDescri=
ptor.getProperties()) {
>+ DefaultParameterDescriptor desc =3D new DefaultParameterDescr=
iptor(propertyDescriptor);
>+ this.parameterDescriptorMap.put(desc.getName().toLowerCase(),=
desc);
> }
> }
>
> /**
>- * Extract provided parameters informations and insert it in {@link #=
parameterDescriptorMap}.
>- *
>- * @param propertyDescriptor the JAVA bean property descriptor.
>- * @param defaultInstance the default instance of bean class.
>- * @since 1.7M2
>- */
>- protected void extractParameterDescriptor(PropertyDescriptor property=
Descriptor, Object defaultInstance)
>- {
>- DefaultParameterDescriptor desc =3D new DefaultParameterDescripto=
r();
>- desc.setName(propertyDescriptor.getName());
>- desc.setType(propertyDescriptor.getPropertyType());
>-
>- Method writeMethod =3D propertyDescriptor.getWriteMethod();
>-
>- if (writeMethod !=3D null) {
>- Method readMethod =3D propertyDescriptor.getReadMethod();
>-
>- // is parameter hidden
>- ParameterHidden parameterHidden =3D
>- extractParameterAnnotation(writeMethod, readMethod, Param=
eterHidden.class);
>-
>- if (parameterHidden =3D=3D null) {
>- // get parameter description
>- ParameterDescription parameterDescription =3D
>- extractParameterAnnotation(writeMethod, readMethod, P=
arameterDescription.class);
>-
>- desc.setDescription(parameterDescription !=3D null ? para=
meterDescription.value() : propertyDescriptor
>- .getShortDescription());
>-
>- // is parameter mandatory
>- ParameterMandatory parameterMandatory =3D
>- extractParameterAnnotation(writeMethod, readMethod, P=
arameterMandatory.class);
>-
>- desc.setMandatory(parameterMandatory !=3D null);
>-
>- // get default value
>- try {
>- desc.setDefaultValue(readMethod.invoke(defaultInstanc=
e));
>- } catch (Exception e) {
>- // TODO add some log.
>- }
>-
>- this.parameterDescriptorMap.put(desc.getName().toLowerCas=
e(), desc);
>- }
>- }
>- }
>-
>- /**
>- * Get the parameter annotation. Try first on the setter then on the =
getter if no annotation has been found.
>- *
>- * @param <T> the Class object corresponding to the annotation type.
>- * @param writeMethod the method that should be used to write the pro=
perty value.
>- * @param readMethod the method that should be used to read the prope=
rty value.
>- * @param annotationClass the Class object corresponding to the annot=
ation type.
>- * @return this element's annotation for the specified annotation typ=
e if present on this element, else null.
>- * @since 1.7
>- */
>- protected <T extends Annotation> T extractParameterAnnotation(Method =
writeMethod, Method readMethod,
>- Class<T> annotationClass)
>- {
>- T parameterDescription =3D writeMethod.getAnnotation(annotationCl=
ass);
>-
>- if (parameterDescription =3D=3D null && readMethod !=3D null) {
>- parameterDescription =3D readMethod.getAnnotation(annotationC=
lass);
>- }
>-
>- return parameterDescription;
>- }
>-
>- /**
> * {@inheritDoc}
> *
> * @see org.xwiki.rendering.macro.descriptor.MacroDescriptor#getConten=
tDescriptor()
>@@ -196,7 +112,7 @@
> */
> public Class< ? > getParametersBeanClass()
> {
>- return this.parametersBeanClass;
>+ return (null !=3D parametersBeanDescriptor) ? this.parametersBean=
Descriptor.getBeanClass() : Object.class;
> }
>
> /**
>@@ -206,6 +122,7 @@
> */
> public Map<String, ParameterDescriptor> getParameterDescriptorMap()
> {
>- return Collections.unmodifiableMap(this.parameterDescriptorMap);
>+ return (null !=3D parametersBeanDescriptor) ? Collections.unmodif=
iableMap(this.parameterDescriptorMap)
>+ : Collections.<String, ParameterDescriptor> emptyMap();
> }
> }
>
>Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main=
/java/org/xwiki/rendering/macro/descriptor/DefaultMacroDescriptor.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/descriptor/DefaultMacroDescriptor.java 2009-=
07-15 17:48:48 UTC (rev 21966)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/descriptor/DefaultMacroDescriptor.java 2009-=
07-15 18:57:45 UTC (rev 21967)
>@@ -19,6 +19,8 @@
> */
> package org.xwiki.rendering.macro.descriptor;
>
>+import org.xwiki.properties.BeanDescriptor;
>+
> /**
> * Describe a macro with no parameters.
> *
>@@ -32,41 +34,28 @@
> */
> public DefaultMacroDescriptor(String description)
> {
>- super(description, new DefaultContentDescriptor(), Object.class);
>+ super(description, new DefaultContentDescriptor(), null);
> }
>-
>+
> /**
> * @param description the description of the macro.
>- * @param parametersBeanClass the class of the JAVA bean containing m=
acro parameters.
>+ * @param contentDescriptor description of the macro content.
> */
>- public DefaultMacroDescriptor(String description, Class< ? > paramete=
rsBeanClass)
>- {
>- super(description, new DefaultContentDescriptor(), parametersBean=
Class);
>-
>- extractParameterDescriptorMap();
>- }
>-
>- /**
>- * @param description the description of the macro.
>- * @param contentDescriptor the description of the macro content. nul=
l indicate macro does not support content.
>- */
> public DefaultMacroDescriptor(String description, ContentDescriptor co=
ntentDescriptor)
> {
>- super(description, contentDescriptor, Object.class);
>-
>- extractParameterDescriptorMap();
>+ super(description, contentDescriptor, null);
> }
>
> /**
> * @param description the description of the macro.
> * @param contentDescriptor the description of the macro content. null=
indicate macro does not support content.
>- * @param parametersBeanClass the class of the JAVA bean containing m=
acro parameters.
>+ * @param parametersBeanDescriptor the description of the parameters =
bean.
> */
> public DefaultMacroDescriptor(String description, ContentDescriptor co=
ntentDescriptor,
>- Class< ? > parametersBeanClass)
>+ BeanDescriptor parametersBeanDescriptor)
> {
>- super(description, contentDescriptor, parametersBeanClass);
>-
>+ super(description, contentDescriptor, parametersBeanDescriptor);
>+
> extractParameterDescriptorMap();
>- }
>+ }
> }
>
>Modified: platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main=
/java/org/xwiki/rendering/macro/descriptor/DefaultParameterDescriptor.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/descriptor/DefaultParameterDescriptor.java 2009-=
07-15 17:48:48 UTC (rev 21966)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/=
org/xwiki/rendering/macro/descriptor/DefaultParameterDescriptor.java 2009-=
07-15 18:57:45 UTC (rev 21967)
>@@ -19,6 +19,8 @@
> */
> package org.xwiki.rendering.macro.descriptor;
>
>+import org.xwiki.properties.PropertyDescriptor;
>+
> /**
> * The default implementation of {@link ParameterDescriptor}.
> *
>@@ -28,31 +30,19 @@
> public class DefaultParameterDescriptor implements ParameterDescriptor
> {
> /**
>- * The name of the parameter.
>- */
>- private String name;
>-
>- /**
> * The description of the parameter.
> */
>- private String description;
>+ private PropertyDescriptor propertyDescriptor;
>
> /**
>- * The type of the parameter.
>- */
>- private Class< ? > type;
>-
>- /**
>- * The default value of the parameter.
>- */
>- private Object defaultValue;
>-
>- /**
>- * Indicate if the parameter is mandatory.
>+ * Creates a new {@link DefaultParameterDescriptor} instance using th=
e given {@link PropertyDescriptor}.
> *
>- * @since 1.7
>+ * @param propertyDescriptor The {@link PropertyDescriptor} instance.
> */
>- private boolean mandatory;
>+ public DefaultParameterDescriptor(PropertyDescriptor propertyDescript=
or)
>+ {
>+ this.propertyDescriptor =3D propertyDescriptor;
>+ }
>
> /**
> * {@inheritDoc}
>@@ -61,72 +51,40 @@
> */
> public String getName()
> {
>- return this.name;
>+ return propertyDescriptor.getName();
> }
>
> /**
>- * @param name the name of the parameter.
>- */
>- public void setName(String name)
>- {
>- this.name =3D name;
>- }
>-
>- /**
> * {@inheritDoc}
> *
> * @see org.xwiki.rendering.macro.descriptor.ParameterDescriptor#getDe=
scription()
> */
> public String getDescription()
> {
>- return this.description;
>+ return propertyDescriptor.getDescription();
> }
>
> /**
>- * @param description the description of the parameter.
>- */
>- public void setDescription(String description)
>- {
>- this.description =3D description;
>- }
>-
>- /**
> * {@inheritDoc}
> *
> * @see org.xwiki.rendering.macro.descriptor.ParameterDescriptor#getTy=
pe()
> */
> public Class< ? > getType()
> {
>- return this.type;
>+ return propertyDescriptor.getPropertyClass();
> }
>
> /**
>- * @param type the type of the parameter.
>- */
>- public void setType(Class< ? > type)
>- {
>- this.type =3D type;
>- }
>-
>- /**
> * {@inheritDoc}
> *
> * @see org.xwiki.rendering.macro.descriptor.ParameterDescriptor#getDe=
faultValue()
> */
> public Object getDefaultValue()
> {
>- return this.defaultValue;
>+ return propertyDescriptor.getDefaultValue();
> }
>
> /**
>- * @param defaultValue the default value of the parameter.
>- */
>- public void setDefaultValue(Object defaultValue)
>- {
>- this.defaultValue =3D defaultValue;
>- }
>-
>- /**
> * {@inheritDoc}
> *
> * @see org.xwiki.rendering.macro.descriptor.ParameterDescriptor#isMan=
datory()
>@@ -134,15 +92,6 @@
> */
> public boolean isMandatory()
> {
>- return this.mandatory;
>+ return propertyDescriptor.isMandatory();
> }
>-
>- /**
>- * @param mandatory indicate if the parameter is mandatory.
>- * @since 1.7
>- */
>- public void setMandatory(boolean mandatory)
>- {
>- this.mandatory =3D mandatory;
>- }
> }
>
[snip]
>Added: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-re=
ndering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/w=
ikibridge/DefaultWikiMacroManager.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wiki=
bridge/DefaultWikiMacroManager.java (rev 0)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wiki=
bridge/DefaultWikiMacroManager.java 2009-07-15 18:57:45 UTC (rev 219=
67)
>@@ -0,0 +1,108 @@
>+/*
>+ * See the NOTICE file distributed with this work for additional
>+ * information regarding copyright ownership.
>+ *
>+ * This is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU Lesser General Public License as
>+ * published by the Free Software Foundation; either version 2.1 of
>+ * the License, or (at your option) any later version.
>+ *
>+ * This software is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this software; if not, write to the Free
>+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>+ */
>+
>+package org.xwiki.rendering.internal.macro.wikibridge;
>+
>+import java.util.HashMap;
>+import java.util.Map;
>+
>+import org.xwiki.component.annotation.Requirement;
>+import org.xwiki.component.descriptor.ComponentDescriptor;
>+import org.xwiki.component.descriptor.DefaultComponentDescriptor;
>+import org.xwiki.component.logging.AbstractLogEnabled;
>+import org.xwiki.component.manager.ComponentManager;
>+import org.xwiki.component.manager.ComponentRepositoryException;
>+import org.xwiki.rendering.macro.Macro;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacro;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroManager;
>+
>+/**
>+ * Default implementation of {@link WikiMacroManager}.
>+ *
>+ * @version $Id$
>+ * @since 2.0M2
>+ */
>+public class DefaultWikiMacroManager extends AbstractLogEnabled implement=
s WikiMacroManager
>+{
>+ /**
>+ * The {@link ComponentManager} component.
>+ */
>+ @Requirement
>+ private ComponentManager componentManager;
>+
>+ /**
>+ * Map of wiki macros against document names. This is used to de-regi=
ster wiki macros when corresponding documents
>+ * are deleted.
>+ */
>+ @SuppressWarnings("unchecked")
>+ private Map<String, ComponentDescriptor<Macro>> wikiMacroMap;
>+
>+ /**
>+ * Creates a new {@link WikiMacroEventListener} component.
>+ */
>+ @SuppressWarnings("unchecked")
>+ public DefaultWikiMacroManager()
>+ {
>+ wikiMacroMap =3D new HashMap<String, ComponentDescriptor<Macro>>(=
);
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public boolean hasWikiMacro(String documentName)
>+ {
>+ return (null !=3D wikiMacroMap.get(documentName));
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ @SuppressWarnings("unchecked")
>+ public void registerWikiMacro(String documentName, WikiMacro wikiMacr=
o)
>+ {
>+ DefaultComponentDescriptor<Macro> descriptor =3D new DefaultCompo=
nentDescriptor<Macro>();
>+ descriptor.setRole(Macro.class);
>+ descriptor.setRoleHint(wikiMacro.getName());
>+ try {
>+ componentManager.registerComponent(descriptor, wikiMacro);
>+ wikiMacroMap.put(documentName, descriptor);
>+ getLogger().info(
>+ String.format("Macro [%s] in [%s] successfully registered=
", wikiMacro.getName(), documentName));
>+ } catch (ComponentRepositoryException ex) {
>+ getLogger().error(
>+ String.format("Unable to register macro [%s] in [%s]", wi=
kiMacro.getName(), documentName), ex);
>+ }
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ @SuppressWarnings("unchecked")
>+ public void unregisterWikiMacro(String documentName)
>+ {
>+ ComponentDescriptor<Macro> macroDescriptor =3D wikiMacroMap.get(d=
ocumentName);
>+ componentManager.unregisterComponent(macroDescriptor.getRole(), m=
acroDescriptor.getRoleHint());
>+ wikiMacroMap.remove(documentName);
>+ getLogger()
>+ .info(
>+ String.format("Macro [%s] in [%s] successfully de-registe=
red", macroDescriptor.getRoleHint(),
>+ documentName));
>+ }
>+}
>
>Added: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-re=
ndering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/w=
ikibridge/WikiMacroEventListener.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wiki=
bridge/WikiMacroEventListener.java (rev 0)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wiki=
bridge/WikiMacroEventListener.java 2009-07-15 18:57:45 UTC (rev 21967)
>@@ -0,0 +1,141 @@
>+/*
>+ * See the NOTICE file distributed with this work for additional
>+ * information regarding copyright ownership.
>+ *
>+ * This is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU Lesser General Public License as
>+ * published by the Free Software Foundation; either version 2.1 of
>+ * the License, or (at your option) any later version.
>+ *
>+ * This software is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this software; if not, write to the Free
>+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>+ */
>+
>+package org.xwiki.rendering.internal.macro.wikibridge;
>+
>+import java.util.ArrayList;
>+import java.util.List;
>+
>+import org.xwiki.bridge.DocumentAccessBridge;
>+import org.xwiki.component.annotation.Component;
>+import org.xwiki.component.annotation.Requirement;
>+import org.xwiki.component.logging.AbstractLogEnabled;
>+import org.xwiki.observation.EventListener;
>+import org.xwiki.observation.event.AbstractDocumentEvent;
>+import org.xwiki.observation.event.DocumentDeleteEvent;
>+import org.xwiki.observation.event.DocumentSaveEvent;
>+import org.xwiki.observation.event.DocumentUpdateEvent;
>+import org.xwiki.observation.event.Event;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacro;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroBuilder;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroBuilderException;
>+import org.xwiki.rendering.macro.wikibridge.WikiMacroManager;
>+
>+/**
>+ * An {@link EventListener} responsible for dynamically registering / unr=
egistering / updating xwiki rendering macros
>+ * based on wiki macro create / delete / update actions.
>+ *
>+ * @version $Id$
>+ * @since 2.0M2
>+ */
>+@Component("wikimacrolistener")
>+public class WikiMacroEventListener extends AbstractLogEnabled implements=
EventListener
>+{
>+ /**
>+ * The {@link DocumentAccessBridge} component.
>+ */
>+ @Requirement
>+ private DocumentAccessBridge docBridge;
>+
>+ /**
>+ * The {@link WikiMacroBuilder} component.
>+ */
>+ @Requirement
>+ private WikiMacroBuilder macroBuilder;
>+
>+ /**
>+ * The {@link WikiMacroManager} component.
>+ */
>+ @Requirement
>+ private WikiMacroManager wikiMacroManager;
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public String getName()
>+ {
>+ return "wikimacrolistener";
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public List<Event> getEvents()
>+ {
>+ List<Event> events =3D new ArrayList<Event>();
>+ events.add(new DocumentSaveEvent());
>+ events.add(new DocumentUpdateEvent());
>+ events.add(new DocumentDeleteEvent());
>+ return events;
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public void onEvent(Event event, Object source, Object data)
>+ {
>+ if (event instanceof AbstractDocumentEvent) {
>+ // TODO: This approach towards extracting the document name d=
oesn't look right. But we cannot use
>+ // 'source' parameter without depending on xwiki-core. This m=
ust be fixed.
XWikiDocument implements DocumentModelBridge which mean source is also
a DocumentModelBridge, so yes you can access everything in
DocumentModelBridge api (which among other things mean the document
name)
>+ String documentName =3D ((AbstractDocumentEvent) event).getEv=
entFilter().getFilter();
>+
>+ // TODO: This needs to be discussed.
>+ if (!documentName.startsWith("xwiki:")) {
>+ getLogger().error("Wiki macro registration from virtual w=
ikis are not allowed");
>+ return;
>+ }
>+
>+ if (event instanceof DocumentSaveEvent || event instanceof Do=
cumentUpdateEvent) {
>+ // Unregister any existing macro registered under this do=
cument.
>+ if (wikiMacroManager.hasWikiMacro(documentName)) {
>+ wikiMacroManager.unregisterWikiMacro(documentName);
>+ }
>+
>+ // Check whether the given document has a wiki macro defi=
ned in it.
>+ String macroName =3D
>+ (String) docBridge.getProperty(documentName, WikiMacr=
oBuilder.WIKI_MACRO_CLASS, 0,
>+ WikiMacroBuilder.MACRO_NAME_PROPERTY);
>+
>+ if (null !=3D macroName) {
>+ // Attempt to build a wiki macro.
>+ WikiMacro wikiMacro =3D null;
>+ try {
>+ wikiMacro =3D macroBuilder.buildMacro(documentNam=
e);
>+ } catch (WikiMacroBuilderException ex) {
>+ getLogger().error(ex.getMessage());
>+ return;
>+ }
>+
>+ // Check if the user has programming rights before co=
ntinuing further.
>+ if (!docBridge.hasProgrammingRights()) {
>+ String errorMessage =3D "Unable to register macro=
[%s] due to insufficient privileges";
>+ getLogger().error(String.format(errorMessage, wik=
iMacro.getName()));
>+ return;
>+ }
>+
>+ // Register macro.
>+ wikiMacroManager.registerWikiMacro(documentName, wiki=
Macro);
>+ }
>+ } else if (event instanceof DocumentDeleteEvent && wikiMacroM=
anager.hasWikiMacro(documentName)) {
>+ wikiMacroManager.unregisterWikiMacro(documentName);
>+ }
>+ }
>+ }
>+}
>
>Added: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-re=
ndering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge=
/WikiMacro.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacro.java (rev 0)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacro.java 2009-07-15 18:57:45 UTC (rev 21967)
>@@ -0,0 +1,242 @@
>+/*
>+ * See the NOTICE file distributed with this work for additional
>+ * information regarding copyright ownership.
>+ *
>+ * This is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU Lesser General Public License as
>+ * published by the Free Software Foundation; either version 2.1 of
>+ * the License, or (at your option) any later version.
>+ *
>+ * This software is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this software; if not, write to the Free
>+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>+ */
>+
>+package org.xwiki.rendering.macro.wikibridge;
>+
>+import java.io.StringReader;
>+import java.util.HashMap;
>+import java.util.List;
>+import java.util.Map;
>+
>+import org.xwiki.component.manager.ComponentLookupException;
>+import org.xwiki.component.manager.ComponentManager;
>+import org.xwiki.context.Execution;
>+import org.xwiki.rendering.block.Block;
>+import org.xwiki.rendering.block.XDOM;
>+import org.xwiki.rendering.macro.Macro;
>+import org.xwiki.rendering.macro.MacroExecutionException;
>+import org.xwiki.rendering.macro.descriptor.MacroDescriptor;
>+import org.xwiki.rendering.macro.descriptor.ParameterDescriptor;
>+import org.xwiki.rendering.macro.parameter.MacroParameterException;
>+import org.xwiki.rendering.parser.ParseException;
>+import org.xwiki.rendering.parser.Parser;
>+import org.xwiki.rendering.parser.SyntaxFactory;
>+import org.xwiki.rendering.transformation.MacroTransformationContext;
>+import org.xwiki.rendering.transformation.Transformation;
>+import org.xwiki.rendering.util.ParserUtils;
>+
>+/**
>+ * A generic macro that parses content in a given syntax. The actual cont=
ent to be parsed is injected and the content
>+ * received when executing the macro is ignored This macro is meant to be=
registered dynamically against the component
>+ * manager, to allow its content definition outside java code itself (ret=
rieved from the Wiki for example).
>+ *
>+ * @version $Id$
>+ * @since 2.0M1
>+ */
>+public class WikiMacro implements Macro<WikiMacroParameters>
>+{
>+ /**
>+ * The key under which macro context will be available in the XwikiCo=
ntext for scripts.
>+ */
>+ private static final String MACRO_KEY =3D "macro";
>+
>+ /**
>+ * Macro hint for {@link Transformation} component.
>+ *
>+ * Same as MACRO_KEY (Check style fix)
>+ */
>+ private static final String MACRO_HINT =3D MACRO_KEY;
>+
>+ /**
>+ * The key under which macro body will be available inside macro cont=
ext.
>+ */
>+ private static final String MACRO_CONTENT_KEY =3D "content";
>+
>+ /**
>+ * The key under which macro parameters will be available inside macr=
o context.
>+ */
>+ private static final String MACRO_PARAMS_KEY =3D "params";
>+
>+ /**
>+ * The key under which macro transformation context will be available=
inside macro context.
>+ */
>+ private static final String MACRO_CONTEXT_KEY =3D "context";
>+
>+ /**
>+ * The {@link MacroDescriptor} for this macro.
>+ */
>+ private MacroDescriptor descriptor;
>+
>+ /**
>+ * Name of this macro.
>+ */
>+ private String macroName;
>+
>+ /**
>+ * Macro content.
>+ */
>+ private String content;
>+
>+ /**
>+ * Syntax id.
>+ */
>+ private String syntaxId;
>+
>+ /**
>+ * The component manager used to lookup other components.
>+ */
>+ private ComponentManager componentManager;
>+
>+ /**
>+ * Used to clean result of the parser syntax.
>+ */
>+ private ParserUtils parserUtils;
>+
>+ /**
>+ * Constructs a new {@link WikiMacro}.
>+ *
>+ * @param macroName name of the macro.
>+ * @param descriptor the {@link MacroDescriptor} describing this macr=
o.
>+ * @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.
>+ */
>+ public WikiMacro(String macroName, MacroDescriptor descriptor, String=
macroContent, String syntaxId,
>+ ComponentManager componentManager)
>+ {
>+ this.macroName =3D macroName;
>+ this.descriptor =3D descriptor;
>+ this.content =3D macroContent;
>+ this.syntaxId =3D syntaxId;
>+ this.parserUtils =3D new ParserUtils();
>+ this.componentManager =3D componentManager;
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ *
>+ * @see org.xwiki.rendering.macro.Macro#execute(Object, String, Macro=
TransformationContext)
>+ */
>+ @SuppressWarnings("unchecked")
>+ public List<Block> execute(WikiMacroParameters parameters, String mac=
roContent, MacroTransformationContext context)
>+ throws MacroExecutionException
>+ {
>+ // First verify that all mandatory parameters are provided.
>+ Map<String, ParameterDescriptor> parameterDescriptors =3D getDesc=
riptor().getParameterDescriptorMap();
>+ for (String parameterName : parameterDescriptors.keySet()) {
>+ ParameterDescriptor parameterDescriptor =3D parameterDescript=
ors.get(parameterName);
>+ if (parameterDescriptor.isMandatory() && (null =3D=3D paramet=
ers.get(parameterName))) {
>+ throw new MacroParameterException(String.format("Paramete=
r [%s] is mandatory", parameterName));
>+ }
>+ }
>+
>+ // Next, make sure no extra parameters are provided other than th=
ose defined by the macro.
>+ // Question: Do we need this check?
>+ for (String parameterName : parameters.getParameterNames()) {
>+ if (null =3D=3D parameterDescriptors.get(parameterName)) {
>+ throw new MacroParameterException(String.format("Unknown =
parameter : [%s]", parameterName));
>+ }
>+ }
>+
>+ // Parse the wiki macro content.
>+ XDOM xdom =3D null;
>+ try {
>+ Parser parser =3D componentManager.lookup(Parser.class, synta=
xId);
>+ xdom =3D parser.parse(new StringReader(this.content));
>+ } catch (ComponentLookupException ex) {
>+ throw new MacroExecutionException("Could not find a parser fo=
r macro content", ex);
>+ } catch (ParseException ex) {
>+ throw new MacroExecutionException("Error while parsing macro =
content", ex);
>+ }
>+
>+ // Set macro context inside XWikiContext.
>+ Map<String, Object> macroContext =3D new HashMap<String, Object>(=
);
>+ macroContext.put(MACRO_PARAMS_KEY, parameters);
>+ macroContext.put(MACRO_CONTENT_KEY, macroContent);
>+ macroContext.put(MACRO_CONTEXT_KEY, context);
>+ try {
>+ Execution execution =3D componentManager.lookup(Execution.cla=
ss);
>+ Map xwikiContext =3D (Map) execution.getContext().getProperty=
("xwikicontext");
>+ xwikiContext.put(MACRO_KEY, macroContext);
>+ } catch (ComponentLookupException ex) {
>+ throw new MacroExecutionException("Error while injecting macr=
o parameters", ex);
>+ }
>+
>+ // Perform internal macro transformations.
>+ try {
>+ SyntaxFactory syntaxFactory =3D componentManager.lookup(Synta=
xFactory.class);
>+ Transformation macroTransformation =3D componentManager.looku=
p(Transformation.class, MACRO_HINT);
>+ macroTransformation.transform(xdom, syntaxFactory.createSynta=
xFromIdString(syntaxId));
>+ } catch (Exception ex) {
>+ throw new MacroExecutionException("Error while performing int=
ernal macro transformations", ex);
>+ }
>+
>+ List<Block> result =3D xdom.getChildren();
>+ // If in inline mode remove any top level paragraph.
>+ if (context.isInline()) {
>+ this.parserUtils.removeTopLevelParagraph(result);
>+ }
>+
>+ return result;
>+ }
Did you take care of make sure the macro is executed with programming
rights ? As far as i can see in your code the document from where the
macro is called need to be be saved with programming right for the
macro to be executed with programming right so this will not work for
a normal user.
Note: programming right is working this way: first the author of
context document is tested for programming right, if there is no
context document then the context user is tested for programming
right. In your case i would say the best is to put the macro's
document as context document when before executing it so you have to
remember the document or at least its name in WikiMacro (which btw
even without this need would be logical).
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public MacroDescriptor getDescriptor()
>+ {
>+ return this.descriptor;
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public int getPriority()
>+ {
>+ return 1000;
>+ }
>+
>+ /**
>+ * @return the name of this wiki macro.
>+ */
>+ public String getName()
>+ {
>+ return this.macroName;
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public int compareTo(Macro< ? > macro)
>+ {
>+ if (getPriority() !=3D macro.getPriority()) {
>+ return getPriority() - macro.getPriority();
>+ }
>+ return this.getClass().getSimpleName().compareTo(macro.getClass()=
.getSimpleName());
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public boolean supportsInlineMode()
>+ {
>+ return true;
>+ }
>+}
>
>Added: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-re=
ndering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge=
/WikiMacroBuilder.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacroBuilder.java (rev 0)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacroBuilder.java 2009-07-15 18:57:45 UTC (rev 21967)
>@@ -0,0 +1,88 @@
>+/*
>+ * See the NOTICE file distributed with this work for additional
>+ * information regarding copyright ownership.
>+ *
>+ * This is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU Lesser General Public License as
>+ * published by the Free Software Foundation; either version 2.1 of
>+ * the License, or (at your option) any later version.
>+ *
>+ * This software is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this software; if not, write to the Free
>+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>+ */
>+
>+package org.xwiki.rendering.macro.wikibridge;
>+
>+import org.xwiki.component.annotation.ComponentRole;
>+
>+/**
>+ * Component interface for defining wiki macro builders.
>+ *
>+ * @version $Id$
>+ * @since 2.0M2
>+ */
>+@ComponentRole
>+public interface WikiMacroBuilder
>+{
>+ /**
>+ * Constant for representing XWiki.WikiMacroClass xwiki class.
>+ */
>+ String WIKI_MACRO_CLASS =3D "XWiki.WikiMacroClass";
>+
>+ /**
>+ * Constant for representing macro name property.
>+ */
>+ String MACRO_NAME_PROPERTY =3D "name";
>+
>+ /**
>+ * Constant for representing macro name property.
>+ */
>+ String MACRO_DESCRIPTION_PROPERTY =3D "description";
>+
>+ /**
>+ * Constant for representing macro name property.
>+ */
>+ String MACRO_CONTENT_PROPERTY =3D "content";
>+
>+ /**
>+ * Constant for representing XWiki.WikiMacroParameterClass xwiki clas=
s.
>+ */
>+ String WIKI_MACRO_PARAMETER_CLASS =3D "XWiki.WikiMacroParameterClass"=
;
>+
>+ /**
>+ * Constant for representing parameter name property.
>+ *
>+ * Same as MACRO_NAME_PROPERTY (Check style Fix)
>+ */
>+ String PARAMETER_NAME_PROPERTY =3D MACRO_NAME_PROPERTY;
>+
>+ /**
>+ * Constant for representing parameter description property.
>+ *
>+ * Same as MACRO_DESCRIPTION_PROPERTY (Check style Fix)
>+ */
>+ String PARAMETER_DESCRIPTION_PROPERTY =3D MACRO_DESCRIPTION_PROPERTY;
>+
>+ /**
>+ * Constant for representing parameter mandatory property.
>+ */
>+ String PARAMETER_MANDATORY_PROPERTY =3D "mandatory";
All this has nothing to do here, the fact that it's stored in a
document object is an implementation detail. WikiMacroBuilder user
should not know that.
>+
>+ /**
>+ * Searches the given document for a wiki macro definition and tries =
to build a {@link WikiMacro} if a definition is
>+ * found.
>+ *
>+ * @param documentName name of the document to search for wiki macros=
.
>+ * @return a {@link WikiMacro} corresponding to the macro definition =
found.
>+ * @throws WikiMacroBuilderException if no macro definition is found =
or if an error is encountered while building
>+ * the macro.
>+ */
>+ WikiMacro buildMacro(String documentName) throws WikiMacroBuilderExce=
ption;
>+}
>
[snip]
>
>Added: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-re=
ndering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge=
/WikiMacroDescriptor.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacroDescriptor.java (rev 0)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacroDescriptor.java 2009-07-15 18:57:45 UTC (rev 21967)
>@@ -0,0 +1,98 @@
>+/*
>+ * See the NOTICE file distributed with this work for additional
>+ * information regarding copyright ownership.
>+ *
>+ * This is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU Lesser General Public License as
>+ * published by the Free Software Foundation; either version 2.1 of
>+ * the License, or (at your option) any later version.
>+ *
>+ * This software is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this software; if not, write to the Free
>+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>+ */
>+package org.xwiki.rendering.macro.wikibridge;
>+
>+import java.util.HashMap;
>+import java.util.List;
>+import java.util.Map;
>+
>+import org.xwiki.rendering.macro.descriptor.ContentDescriptor;
>+import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor;
>+import org.xwiki.rendering.macro.descriptor.MacroDescriptor;
>+import org.xwiki.rendering.macro.descriptor.ParameterDescriptor;
>+
>+/**
>+ * A {@link MacroDescriptor} for describing wiki macros.
>+ *
>+ * @version $Id$
>+ * @since 2.0M2
>+ */
>+public class WikiMacroDescriptor implements MacroDescriptor
>+{
>+ /**
>+ * Macro description.
>+ */
>+ private String description;
>+
>+ /**
>+ * Parameter descriptors.
>+ */
>+ private List<WikiMacroParameterDescriptor> parameterDescriptors;
>+
>+ /**
>+ * Creates a new {@link WikiMacroDescriptor} instance.
>+ *
>+ * @param description macro description.
>+ * @param parameterDescriptors parameter descriptors.
>+ */
>+ public WikiMacroDescriptor(String description, List<WikiMacroParamete=
rDescriptor> parameterDescriptors)
>+ {
>+ this.description =3D description;
>+ this.parameterDescriptors =3D parameterDescriptors;
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public String getDescription()
>+ {
>+ return this.description;
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public ContentDescriptor getContentDescriptor()
>+ {
>+ return new DefaultContentDescriptor();
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public Class< ? > getParametersBeanClass()
>+ {
>+ return WikiMacroParameters.class;
>+ }
>+
>+ /**
>+ * {@inheritDoc}
>+ */
>+ public Map<String, ParameterDescriptor> getParameterDescriptorMap()
>+ {
>+ Map<String, ParameterDescriptor> descriptors =3D new HashMap<Stri=
ng, ParameterDescriptor>();
>+
>+ for (WikiMacroParameterDescriptor descriptor : parameterDescripto=
rs) {
>+ descriptors.put(descriptor.getName(), descriptor);
>+ }
>+
>+ return descriptors;
>+ }
>+}
>
>Added: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-re=
ndering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge=
/WikiMacroInitializer.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacroInitializer.java (rev 0)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacroInitializer.java 2009-07-15 18:57:45 UTC (rev 21967)
>@@ -0,0 +1,37 @@
>+/*
>+ * See the NOTICE file distributed with this work for additional
>+ * information regarding copyright ownership.
>+ *
>+ * This is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU Lesser General Public License as
>+ * published by the Free Software Foundation; either version 2.1 of
>+ * the License, or (at your option) any later version.
>+ *
>+ * This software is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this software; if not, write to the Free
>+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>+ */
>+package org.xwiki.rendering.macro.wikibridge;
>+
>+import org.xwiki.component.annotation.ComponentRole;
>+
>+/**
>+ * Responsible for registering wiki macros against the ComponentManager a=
t XE startup.
>+ *
>+ * @version $Id$
>+ * @since 2.0M2
>+ */
>+@ComponentRole
>+public interface WikiMacroInitializer
>+{
>+ /**
>+ * Initializes this {@link WikiMacroInitializer}'s macros and registe=
rs them against the ComponentManager.
>+ */
>+ void init();
>+}
>
>Added: platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-re=
ndering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge=
/WikiMacroManager.java
>--- platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacroManager.java (rev 0)
>+++ platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rende=
ring-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/Wi=
kiMacroManager.java 2009-07-15 18:57:45 UTC (rev 21967)
>@@ -0,0 +1,56 @@
>+/*
>+ * See the NOTICE file distributed with this work for additional
>+ * information regarding copyright ownership.
>+ *
>+ * This is free software; you can redistribute it and/or modify it
>+ * under the terms of the GNU Lesser General Public License as
>+ * published by the Free Software Foundation; either version 2.1 of
>+ * the License, or (at your option) any later version.
>+ *
>+ * This software is distributed in the hope that it will be useful,
>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>+ * Lesser General Public License for more details.
>+ *
>+ * You should have received a copy of the GNU Lesser General Public
>+ * License along with this software; if not, write to the Free
>+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>+ */
>+package org.xwiki.rendering.macro.wikibridge;
>+
>+import org.xwiki.component.annotation.ComponentRole;
>+
>+/**
>+ * Component interface responsible for managing wiki macro instances.
>+ *
>+ * @version $Id$
>+ * @since 2.0M2
>+ */
>+@ComponentRole
>+public interface WikiMacroManager
>+{
>+ /**
>+ * Registers the given {@link WikiMacro} against ComponentManager and=
keeps a reference to it for future reference.
>+ *
>+ * @param documentName name of the document which contains the wiki m=
acro.
>+ * @param wikiMacro the {@link WikiMacro} instance.
>+ */
>+ void registerWikiMacro(String documentName, WikiMacro wikiMacro);
>+
>+ /**
>+ * Unregisters a wiki macro defined on the given document (if there i=
s one).
>+ *
>+ * @param documentName name of the document which contains the wiki m=
acro.
>+ */
>+ void unregisterWikiMacro(String documentName);
>+
>+ /**
>+ * Utility method for querying {@link WikiMacroManager} to see if the=
re is a {@link WikiMacro} already registered
>+ * for the given document.
>+ *
>+ * @param documentName name of the document which contains the wiki m=
acro.
>+ * @return true if there is already a macro registered under the give=
nd document name.
>+ */
>+ boolean hasWikiMacro(String documentName);
>+}
>
[snip]
Hi All,
I have completed the wiki macro bridge implementation and it's almost ready
to be comitted. However there were few design decisions taken that needs to
be discussed / debated a little here.
1. wiki macro Initialization on startup
This is about searching for existing wiki macro definition documents on XE
startup and registering them as macros. As you might already know I cannot
use the ApplicationStartupEvent for this purpose because at that time the
XWikiContext is not available. This is true for any module that requires
database access on XE startup. Currently this is not possible. The real
solution for this is the new model which will be ready on XE startup. But
until we have the new model there has to be a workaround for it. We found
two solutions:
- Initialize the XWiki on XE startup: Thomas says that this can be done by
implementing ApplicationContextListener and making few changes to
XWiki.initXWiki() method.
- Have a WikiMacroInitializer component which will be invoked at the end of
XWiki.initXWiki() method, like below:
<code>
// Initialize all wiki macros
try {
WikiMacroInitializer wikiMacroInitializer =
Utils.getComponentManager().lookup(WikiMacroInitializer.class);
wikiMacroInitializer.init();
} catch (ComponentLookupException ex) {
LOG.error("Error while initializing wiki macros", ex);
}
</code>
I went with the second approach because: It works, easy to implement, and we
have 2.0M2 due today or tomorrow. The approach thomas suggested sounds much
better than the approach I've taken but we don't know what problems it might
pose and I don't know whether I have enough time to implement it. May be we
can have it for 2.0M3.
2. wiki macros and virtual wikis
There is a problem with supporting wiki macros comming from multiple wikis
in a wiki farm. If a particular wiki is initialized at some point in time,
it could introduce a bunch of new macros all of a sudden and it might also
override some existing macros. For this reason we have restricted wiki
macros only for the main wiki, if you need to create a wiki macro it has to
be on the main wiki and you have to save it with programming rights. Note
however that this doesn't solve the overriding issue, an admin could easily
override an existing macro by defining a wiki macro with the same name, we
do not have any protection for this yet. Should we do something about it?
3. wiki macro parameter binding
It would be nice to define a wiki macro parameter named "param1" and refer
to it inside a script as $param1. We can do this easily but this allows wiki
macro authors to override default parameters like $xwiki, $context etc. So
the approach we took is to bind the parameters through the XWikiContext.
For an example, to refer macro parameters a wiki macro author will have to
say:
$context.macro.params.param1
-To acces macro content (body):
$context.macro.content
To access MacroTransformationContext:
$context.macro.context
So these are the design decisions we took during the development of the wiki
macro bridge. Please let us know what you think. We might not be able to
implement any big changes for 2.0M2 but we will be able to do it for 2.0M3,
otherwise we will have to delay wiki macro bridge till 2.0M3 ;(
Thanks.
- Asiri
Hi devs,
I have completed wiki macro bridge implementation but there are few things
that needs to be done inorder to commit it.
1. xwiki-properties module currently under sandbox (
http://svn.xwiki.org/svnroot/xwiki/sandbox/xwiki-core-properties/) need to
be moved into /platform/core/trunk/xwiki-properties
2. Need to commit the xwiki-application-wiki-macro-bridge under
/platform/xwiki-applications/trunk/wiki-macro-bridge. This application hosts
XWiki.WikiMacroClass and XWiki.WikiMacroParameterClass documents. For 2.0M3
we will remove this application and add initialization code that will
generate these two pages automatically.
3. Commit xwiki-core-rendering-macro-wikibridge under
/platform/core/trunk/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge
4. Make necessary dependancy changes so that XE will bundled with wiki-macro
support by default.
Here is my +1 for all of above.
Note that this is a quite large commit (had to refactor macros to use
xwiki-properties), there might be few places where my code can be improved.
Any comments are welcome.
Thanks.
- Asiri
Hello everyone,
I was looking forward to use the live table component, but it seems that you can only use it with Xwiki 1.9. I have xwiki 1.8, and I was wondering if it is possible to import only this component, instead of having the overhead of updating all xwiki just to use this component.
So, is it possible to import/install this component in version 1.8? If it is, how can I do it?
Thanks in advance!
BR,
Roney Castro
Business Efficiency Trainee
Gemalto
Tel: +55 11 5105-7670 - +55 11 7535-4135
Fax: +55 11 5105-7600
Av. das Nações Unidas, 12495, 8º Andar
05425-070 - São Paulo - SP - Brasil
roney.castro(a)gemalto.com<mailto:roney.castro@gemalto.com>
www.gemalto.com<http://www.gemalto.com>
[cid:image001.jpg@01CA053F.962B5060]