### Eclipse Workspace Patch 1.0
#P xwiki-core-rendering
Index: src/main/resources/META-INF/plexus/components.xml
===================================================================
--- src/main/resources/META-INF/plexus/components.xml	(revision 14522)
+++ src/main/resources/META-INF/plexus/components.xml	(working copy)
@@ -339,5 +339,19 @@
         <priority>20</priority>
       </configuration>
     </component>
+    <component>
+      <role>org.xwiki.rendering.macro.Macro</role>
+      <role-hint>useravatar</role-hint>
+      <implementation>org.xwiki.rendering.internal.macro.useravatar.UserAvatarMacro</implementation>
+      <instantiation-strategy>singleton</instantiation-strategy>
+      <requirements>
+      	<requirement>
+          <role>org.xwiki.bridge.DocumentAccessBridge</role>
+        </requirement>
+      	<requirement>
+          <role>org.xwiki.bridge.SkinAccessBridge</role>
+        </requirement>
+      </requirements>
+    </component>
   </components>
 </component-set>
Index: src/main/java/org/xwiki/rendering/macro/useravatar/UserAvatarMacroParameters.java
===================================================================
--- src/main/java/org/xwiki/rendering/macro/useravatar/UserAvatarMacroParameters.java	(revision 0)
+++ src/main/java/org/xwiki/rendering/macro/useravatar/UserAvatarMacroParameters.java	(revision 0)
@@ -0,0 +1,53 @@
+/*
+ * 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.useravatar;
+
+import org.xwiki.rendering.macro.descriptor.ParameterDescription;
+
+/**
+ * Parameters for the {@link org.xwiki.rendering.internal.macro.useravatar.UserAvatarMacro} Macro.
+ * 
+ * @version $Id: $
+ * @since 1.7
+ */
+public class UserAvatarMacroParameters
+{
+    /**
+     * The name of the user whose avatar is to be displayed.
+     */
+    private String username;
+
+    /**
+     * @return the name of the user whose avatar is to be displayed
+     */
+    public String getUsername()
+    {
+        return username;
+    }
+
+    /**
+     * @param username he name of the user whose avatar is to be displayed
+     */
+    @ParameterDescription("the name of the user whose avatar is to be displayed")
+    public void setUsername(String username)
+    {
+        this.username = username;
+    }
+}
Index: src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java
===================================================================
--- src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java	(revision 14522)
+++ src/test/java/org/xwiki/rendering/internal/MockDocumentAccessBridge.java	(working copy)
@@ -89,7 +89,10 @@
 
     public String getProperty(String documentName, String className, String propertyName) throws Exception
     {
-        throw new RuntimeException("Not implemented");
+        return documentName.equals("XWiki.Admin") && 
+            className.equals("XWiki.XWikiUsers") && propertyName.equals("avatar") 
+            ? "mockAvatar.png"
+            : null;
     }
 
     public String getProperty(String documentName, String propertyName) throws Exception
Index: src/test/java/org/xwiki/rendering/scaffolding/AbstractRenderingTestCase.java
===================================================================
--- src/test/java/org/xwiki/rendering/scaffolding/AbstractRenderingTestCase.java	(revision 14522)
+++ src/test/java/org/xwiki/rendering/scaffolding/AbstractRenderingTestCase.java	(working copy)
@@ -24,6 +24,7 @@
 import org.xwiki.rendering.block.Block;
 import org.xwiki.rendering.block.XDOM;
 import org.xwiki.rendering.internal.MockDocumentAccessBridge;
+import org.xwiki.rendering.internal.MockSkinAccessBridge;
 import org.xwiki.rendering.internal.configuration.MockConfigurationSourceCollection;
 import org.xwiki.rendering.internal.util.MockIdGenerator;
 import org.xwiki.rendering.renderer.DefaultWikiPrinter;
@@ -65,6 +66,7 @@
         super.setUp();
 
         getComponentManager().registerComponentDescriptor(MockDocumentAccessBridge.getComponentDescriptor());
+        getComponentManager().registerComponentDescriptor(MockSkinAccessBridge.getComponentDescriptor());
         getComponentManager().registerComponentDescriptor(MockIdGenerator.getComponentDescriptor());
         getComponentManager().registerComponentDescriptor(MockConfigurationSourceCollection.getComponentDescriptor());
     }
Index: src/test/resources/macros/useravatar/macrouseravatar1.test
===================================================================
--- src/test/resources/macros/useravatar/macrouseravatar1.test	(revision 0)
+++ src/test/resources/macros/useravatar/macrouseravatar1.test	(revision 0)
@@ -0,0 +1,12 @@
+.#-----------------------------------------------------
+.input|xwiki/2.0
+.#-----------------------------------------------------
+{{useravatar username="XWiki.Admin" /}}
+.#-----------------------------------------------------
+.expect|xhtml
+.#-----------------------------------------------------
+<!--startmacro:useravatar|-|username="XWiki.Admin"|-|--><!--startimage:XWiki.Admin@mockAvatar.png--><img src="/xwiki/bin/download/XWiki/Admin/mockAvatar.png" alt="mockAvatar.png"/><!--stopimage--><!--stopmacro-->
+.#-----------------------------------------------------
+.expect|xwiki
+.#-----------------------------------------------------
+{{useravatar username="XWiki.Admin"/}}
\ No newline at end of file
Index: src/test/java/org/xwiki/rendering/scaffolding/RenderingPlexusTestSetup.java
===================================================================
--- src/test/java/org/xwiki/rendering/scaffolding/RenderingPlexusTestSetup.java	(revision 14522)
+++ src/test/java/org/xwiki/rendering/scaffolding/RenderingPlexusTestSetup.java	(working copy)
@@ -1,6 +1,7 @@
 package org.xwiki.rendering.scaffolding;
 
 import org.xwiki.rendering.internal.MockDocumentAccessBridge;
+import org.xwiki.rendering.internal.MockSkinAccessBridge;
 import org.xwiki.rendering.internal.configuration.MockConfigurationSourceCollection;
 import org.xwiki.rendering.internal.util.MockIdGenerator;
 
@@ -21,6 +22,7 @@
         super.setUp();
 
         getComponentManager().registerComponentDescriptor(MockDocumentAccessBridge.getComponentDescriptor());
+        getComponentManager().registerComponentDescriptor(MockSkinAccessBridge.getComponentDescriptor());
         getComponentManager().registerComponentDescriptor(MockIdGenerator.getComponentDescriptor());
         getComponentManager().registerComponentDescriptor(MockConfigurationSourceCollection.getComponentDescriptor());
     }
Index: src/test/java/org/xwiki/rendering/RenderingTests.java
===================================================================
--- src/test/java/org/xwiki/rendering/RenderingTests.java	(revision 14522)
+++ src/test/java/org/xwiki/rendering/RenderingTests.java	(working copy)
@@ -36,7 +36,7 @@
     public static Test suite() throws Exception
     {
         RenderingTestSuite suite = new RenderingTestSuite("Test all Parsers/Renderers");
-
+        
         // Text formatting
         suite.addTestsFromResource("bold/bold1", false);
         suite.addTestsFromResource("bold/bold2", false);
@@ -102,6 +102,8 @@
         suite.addTestsFromResource("macros/xhtml/macroxhtml7", true);
         suite.addTestsFromResource("macros/xhtml/macroxhtml8", true);
         suite.addTestsFromResource("macros/macroid", true);
+        suite.addTestsFromResource("macros/useravatar/macrouseravatar1", true);
+        suite.addTestsFromResource("macros/useravatar/macrouseravatar2", true);
         suite.addTestsFromResource("macros/toc/macrotoc1", true);
         suite.addTestsFromResource("macros/toc/macrotoc2", true);
         suite.addTestsFromResource("macros/toc/macrotoc3", true);
Index: src/test/java/org/xwiki/rendering/internal/MockSkinAccessBridge.java
===================================================================
--- src/test/java/org/xwiki/rendering/internal/MockSkinAccessBridge.java	(revision 0)
+++ src/test/java/org/xwiki/rendering/internal/MockSkinAccessBridge.java	(revision 0)
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import org.xwiki.bridge.SkinAccessBridge;
+import org.xwiki.component.descriptor.ComponentDescriptor;
+import org.xwiki.component.descriptor.DefaultComponentDescriptor;
+
+/**
+ * Mock {@link XWikiAccessBridge} implementation used for testing, since we don't want to pull any dependency on the
+ * Model/Skin/etc for the Rendering module's unit tests.
+ * 
+ * @version $Id: MockVelocityManager.java 10176 2008-06-09 16:11:28Z vmassol $
+ * @since 1.6M1
+ */
+public class MockSkinAccessBridge implements SkinAccessBridge
+{
+    /**
+     * Create and return a descriptor for this component.
+     * 
+     * @return the descriptor of the component.
+     */
+    public static ComponentDescriptor getComponentDescriptor()
+    {
+        DefaultComponentDescriptor componentDescriptor = new DefaultComponentDescriptor();
+
+        componentDescriptor.setRole(SkinAccessBridge.ROLE);
+        componentDescriptor.setRoleHint("default");
+        componentDescriptor.setImplementation(MockSkinAccessBridge.class.getName());
+
+        return componentDescriptor;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see org.xwiki.bridge.XWikiBridge#getSkinFile(String fileName)
+     */
+    public String getSkinFile(String fileName)
+    {
+        return fileName.equals("noavatar.png") 
+            ? "/xwiki/noavatar.png"
+            : null;
+    }
+}

Property changes on: src/test/java/org/xwiki/rendering/internal/MockSkinAccessBridge.java
___________________________________________________________________
Added: svn:mergeinfo

Index: src/test/resources/macros/useravatar/macrouseravatar2.test
===================================================================
--- src/test/resources/macros/useravatar/macrouseravatar2.test	(revision 0)
+++ src/test/resources/macros/useravatar/macrouseravatar2.test	(revision 0)
@@ -0,0 +1,12 @@
+.#-----------------------------------------------------
+.input|xwiki/2.0
+.#-----------------------------------------------------
+{{useravatar username="XWiki.noUser" /}}
+.#-----------------------------------------------------
+.expect|xhtml
+.#-----------------------------------------------------
+<!--startmacro:useravatar|-|username="XWiki.noUser"|-|--><!--startimage:/xwiki/noavatar.png--><img src="/xwiki/noavatar.png" alt="/xwiki/noavatar.png"/><!--stopimage--><!--stopmacro-->
+.#-----------------------------------------------------
+.expect|xwiki
+.#-----------------------------------------------------
+{{useravatar username="XWiki.noUser"/}}
\ No newline at end of file
Index: src/main/java/org/xwiki/rendering/internal/macro/useravatar/UserAvatarMacro.java
===================================================================
--- src/main/java/org/xwiki/rendering/internal/macro/useravatar/UserAvatarMacro.java	(revision 0)
+++ src/main/java/org/xwiki/rendering/internal/macro/useravatar/UserAvatarMacro.java	(revision 0)
@@ -0,0 +1,105 @@
+/*
+ * 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.useravatar;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.xwiki.bridge.DocumentAccessBridge;
+import org.xwiki.bridge.SkinAccessBridge;
+import org.xwiki.rendering.block.Block;
+import org.xwiki.rendering.block.WordBlock;
+import org.xwiki.rendering.block.ImageBlock;
+import org.xwiki.rendering.macro.AbstractMacro;
+import org.xwiki.rendering.macro.MacroExecutionException;
+import org.xwiki.rendering.macro.descriptor.DefaultMacroDescriptor;
+import org.xwiki.rendering.macro.useravatar.UserAvatarMacroParameters;
+import org.xwiki.rendering.transformation.MacroTransformationContext;
+import org.xwiki.rendering.listener.DocumentImage;
+import org.xwiki.rendering.listener.Image;
+import org.xwiki.rendering.listener.URLImage;
+
+/**
+ * Allows displaying the avatar for a specific user.
+ * 
+ * @version $Id: $
+ * @since 1.7
+ */
+public class UserAvatarMacro extends AbstractMacro<UserAvatarMacroParameters>
+{
+    /**
+     * The description of the macro.
+     */
+    private static final String DESCRIPTION =
+        "Allows displaying the avatar for a specific user.";
+
+    /**
+     * Injected by the Component Manager.
+     */
+    private DocumentAccessBridge documentAccessBridge;
+
+    /**
+     * Injected by the Component Manager.
+     */
+    private SkinAccessBridge skinAccessBridge;
+    
+    /**
+     * Create and initialize the descriptor of the macro.
+     */
+    public UserAvatarMacro()
+    {
+        super(new DefaultMacroDescriptor(DESCRIPTION, UserAvatarMacroParameters.class));
+    }
+    
+    /**
+     *  {@inheritDoc}
+     * @see org.xwiki.rendering.macro.Macro#execute(java.lang.Object, java.lang.String, org.xwiki.rendering.transformation.MacroTransformationContext)
+     */
+    public List<Block> execute(UserAvatarMacroParameters parameters, String content, MacroTransformationContext context)
+        throws MacroExecutionException
+    {
+        String atachment = null;
+        String userName = parameters.getUsername(); 
+        Block resultedBlock = null;
+        
+        try {
+            atachment = documentAccessBridge.getProperty(userName, "XWiki.XWikiUsers", "avatar");
+            Image image = null;
+            image = atachment == null 
+                ? new URLImage(skinAccessBridge.getSkinFile("noavatar.png")) 
+                : new DocumentImage(userName, atachment);
+            resultedBlock = new ImageBlock(image, false);
+        } catch (Exception e) {
+            resultedBlock = new WordBlock(e.getMessage());
+        }
+        return Collections.singletonList(resultedBlock);
+    }
+
+    /** 
+     * {@inheritDoc}
+     * @see org.xwiki.rendering.macro.Macro#supportsInlineMode()
+     */
+    public boolean supportsInlineMode()
+    {
+        return false;
+    }
+
+}
