### Eclipse Workspace Patch 1.0
#P platform
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/plots/PiePlotFactory.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/plots/PiePlotFactory.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/plots/PiePlotFactory.java	(revision 0)
@@ -0,0 +1,95 @@
+/*
+ * 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.chart.plots;
+
+import java.util.Map;
+
+import org.jfree.chart.plot.PiePlot;
+import org.jfree.chart.plot.Plot;
+import org.jfree.data.general.DefaultPieDataset;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.source.DataSource;
+
+/**
+ * An implementation for the PlotFactory needed for building a pie chart.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public final class PiePlotFactory implements PlotFactory
+{
+    /** We're dealing with a singleton. */
+    private static PiePlotFactory uniqueInstance = new PiePlotFactory();
+
+    /** Prevents the user from instantiating the class. */
+    private PiePlotFactory()
+    {
+        // empty
+    }
+
+    /** 
+     * Forces the user to use only the unique instance. 
+     * @return the unique instance of this class
+     */
+    public static PiePlotFactory getInstance()
+    {
+        return uniqueInstance;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see org.xwiki.chart.plots.PlotFactory#create(DataSource, Map)
+     */
+    @Override
+    public Plot create(DataSource dataSource, Map<String, Object> params)
+        throws ChartGeneratorException
+    {
+        final String categoryString = "Category ";
+        
+        DefaultPieDataset dataset = new DefaultPieDataset();
+        String dataSeries = (String) params.get("series");
+        
+        if (dataSeries.equals("columns")) {
+            for (int row = 0; row < dataSource.getRowCount(); row++) {
+                if (dataSource.hasHeaderColumn()) {
+                    String category = dataSource.getHeaderColumnValue(row);
+                    dataset.setValue(category, dataSource.getCell(row, 0));
+                } else {
+                    dataset.setValue(categoryString + (row + 1), dataSource.getCell(row, 0));
+                }
+            }
+        } else if (dataSeries.equals("rows")) {
+            for (int column = 0; column < dataSource.getColumnCount(); column++) {
+                if (dataSource.hasHeaderRow()) {
+                    String category = dataSource.getHeaderRowValue(column);
+                    dataset.setValue(category, dataSource.getCell(0, column));
+                } else {
+                    dataset.setValue(categoryString + (column + 1), dataSource.getCell(0, column));
+                }
+            }
+        } else {
+            throw new ChartGeneratorException("Invalid series parameter:" + dataSeries);
+        }
+
+        PiePlot plot = new PiePlot(dataset);
+        return plot;
+    }
+}
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/ChartGenerator.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/ChartGenerator.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/ChartGenerator.java	(revision 0)
@@ -0,0 +1,43 @@
+/*
+ * 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.chart;
+
+import java.io.File;
+import java.util.Map;
+
+import org.xwiki.chart.source.DataSource;
+
+/**
+ * An interface containing the specifications for the chart generator.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public interface ChartGenerator
+{
+    /**
+     * @return an URL to the generated chart encoded as image file.
+     * @param dataSource the dataSource from which the chart collects the data
+     * @param parameters chart's parameters
+     * @throws ChartGeneratorException in case of an invalid data source
+     */
+    File buildChart(DataSource dataSource, Map<String, Object> parameters, File outputDirectory) 
+        throws ChartGeneratorException;
+}
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/ChartGeneratorException.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/ChartGeneratorException.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/ChartGeneratorException.java	(revision 0)
@@ -0,0 +1,64 @@
+/*
+ * 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.chart;
+
+/**
+ * The class used to indicate exceptions specific to the Chart generator.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public class ChartGeneratorException extends Exception
+{
+    /**
+     * Class version.
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Constructs a new exception with the specified message.
+     * 
+     * @param message The explanation of the exception.
+     */
+    public ChartGeneratorException(String message)
+    {
+        super(message);
+    }
+    
+    /**
+     * Constructs a new exception with the specified cause.
+     * 
+     * @param throwable The underlying cause for this exception.
+     */
+    public ChartGeneratorException(Throwable throwable) {
+        super(throwable);
+    }
+
+    /**
+     * Constructs a new exception with the specified message and cause.
+     * 
+     * @param message The explanation of the exception.
+     * @param throwable The underlying cause for this exception.
+     */
+    public ChartGeneratorException(String message, Throwable throwable)
+    {
+        super(message, throwable);
+    }
+}
Index: core/xwiki-jfreechart/pom.xml
===================================================================
--- core/xwiki-jfreechart/pom.xml	(revision 0)
+++ core/xwiki-jfreechart/pom.xml	(revision 0)
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ *
+ * 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.
+ *
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>com.xpn.xwiki.platform</groupId>
+    <artifactId>xwiki-core-parent</artifactId>
+    <version>1.9-SNAPSHOT</version>
+  </parent>
+  <groupId>org.xwiki.platform</groupId>
+  <artifactId>xwiki-core-jfreechart</artifactId>
+  <name>XWiki Platform - Core - Chart Generator</name>
+  <packaging>jar</packaging>
+  <description>XWiki Platform - Core - Chart Generator</description>
+  <!-- needed for the jfreechart artifact -->
+  <!-- Temporary removed for speeding up the build process. To be re-enabled soon.
+  <repositories>
+        <repository>
+            <id>Atlassian</id>
+            <name>Atlassian Repository</name>
+            <url>https://maven.atlassian.com/repository/public/</url>
+        </repository>
+  </repositories>
+  -->      
+  <dependencies>
+	<dependency>
+  		<groupId>jfree</groupId>
+  		<artifactId>jfreechart</artifactId>
+  		<version>1.0.11</version>
+	</dependency>
+    <dependency>
+  		<groupId>jfree</groupId>
+  		<artifactId>jcommon</artifactId>
+  		<version>1.0.12</version>
+	</dependency>
+  </dependencies>
+  <build>
+  </build>
+</project>
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/DefaultChartGenerator.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/DefaultChartGenerator.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/DefaultChartGenerator.java	(revision 0)
@@ -0,0 +1,109 @@
+/*
+ * 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.chart.internal;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Map;
+import org.xwiki.chart.ChartGenerator;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.plots.PlotFactory;
+import org.xwiki.chart.source.DataSource;
+import org.jfree.chart.ChartUtilities;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.Plot;
+
+
+
+/**
+ * A class containing the specifications for the chart generator.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public class DefaultChartGenerator implements ChartGenerator
+{
+    /**
+     * Sets up default values for certain parameters, if they are not provided.
+     * @param parameters the parameter set which the values are to be put into
+     */
+    public void setDefaultValues(Map<String, Object> parameters) {
+        // TODO: temporary only
+        parameters.put("width", 400);
+        parameters.put("height", 300);
+        parameters.put("series", "columns");
+        parameters.put("border_visible", "false");
+        parameters.put("anti_alias", "true");
+    }
+    
+    /**
+     * {@inheritDoc}
+     * @see org.xwiki.chart.ChartGenerator#getImageURL()
+     */
+    @Override
+    public File buildChart(DataSource dataSource, Map<String, Object> parameters, File outputDirectory) 
+        throws ChartGeneratorException
+    {        
+        if (!outputDirectory.isDirectory()) {
+            throw new ChartGeneratorException(outputDirectory.getAbsolutePath() + " is not a directory.");
+        }
+        setDefaultValues(parameters);
+        
+        String type = (String) parameters.get("chartType");
+        Plot plot;
+        
+        String factoryClassName = ChartGenerator.class.getPackage().getName() 
+            + ".plots." + Character.toUpperCase(type.charAt(0))
+            + type.toLowerCase().substring(1) + "PlotFactory";
+
+        PlotFactory factory = null;
+        try {
+            Class factoryClass = Class.forName(factoryClassName);
+            Method method = factoryClass.getMethod("getInstance", new Class[] {});
+            factory = (PlotFactory) method.invoke(null, new Object[] {});
+        } catch (Exception e) {
+            throw new ChartGeneratorException("Could not initialise the plot factory.", e); 
+        }
+        
+        plot = factory.create(dataSource, parameters);
+        
+        JFreeChart jfchart = new JFreeChart(plot);
+        File file = getTempFile(parameters.hashCode() + "." + "png", outputDirectory);
+
+        int width = (Integer) parameters.get("width");
+        int height = (Integer) parameters.get("height");
+        try {
+            ChartUtilities.saveChartAsPNG(file, jfchart, width, height);
+        } catch (Exception e) {
+            throw new ChartGeneratorException("Error saving the chart to disk.", e);
+        }
+
+        return file;
+    }
+
+    /**
+     * @param filename the name of the file to be created
+     * @return a temporary file
+     */
+    private File getTempFile(String filename, File outputDirectory)
+    {
+        return new File(outputDirectory, filename);
+    }
+}
\ No newline at end of file
Index: core/xwiki-jfreechart/src/main/resources/META-INF/plexus/components.xml
===================================================================
--- core/xwiki-jfreechart/src/main/resources/META-INF/plexus/components.xml	(revision 0)
+++ core/xwiki-jfreechart/src/main/resources/META-INF/plexus/components.xml	(revision 0)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ *
+ * 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.
+ *
+-->
+<component-set>
+  <components>
+    <component>
+      <role>org.xwiki.chart.ChartGenerator</role>
+      <role-hint>default</role-hint>
+      <implementation>org.xwiki.chart.internal.DefaultChartGenerator</implementation>
+      <instantiation-strategy>singleton</instantiation-strategy>
+    </component>
+  </components>
+</component-set>
\ No newline at end of file
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/plots/PlotFactory.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/plots/PlotFactory.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/plots/PlotFactory.java	(revision 0)
@@ -0,0 +1,44 @@
+/*
+ * 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.chart.plots;
+
+import java.util.Map;
+import org.jfree.chart.plot.Plot;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.source.DataSource;
+
+/**
+ * It designates a factory for building Plot structures needed for generating the chart.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public interface PlotFactory
+{
+    /**
+     * @param dataSource the chart's data source
+     * @param params additional parameters
+     * @return a Plot to be embedded within the chart 
+     * @throws ChartGeneratorException in case the data cannot be read
+     */
+    Plot create(DataSource dataSource, Map<String, Object> params) throws ChartGeneratorException;
+}
