### Eclipse Workspace Patch 1.0
#P platform
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/AreaPlotFactory.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/AreaPlotFactory.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/AreaPlotFactory.java	(revision 0)
@@ -0,0 +1,73 @@
+/*
+ * 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.plots;
+
+import java.util.Map;
+
+import org.jfree.chart.plot.Plot;
+import org.jfree.chart.renderer.xy.XYAreaRenderer;
+import org.jfree.chart.renderer.xy.XYItemRenderer;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.plots.PlotFactory;
+import org.xwiki.chart.source.DataSource;
+
+/**
+ * An implementation for the PlotFactory needed for building an area chart.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public final class AreaPlotFactory implements PlotFactory
+{
+    /** 
+     * We're dealing with a singleton. 
+     */
+    private static AreaPlotFactory uniqueInstance = new AreaPlotFactory();
+
+    /** 
+     * Prevents the user from instantiating the class. 
+     */
+    private AreaPlotFactory()
+    {
+        // empty
+    }
+
+    /** 
+     * Forces the user to use only the unique instance. 
+     * @return the unique instance of this class
+     */
+    public static AreaPlotFactory 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
+    {
+        XYItemRenderer renderer = new XYAreaRenderer();
+        return XYPlotGenerator.getInstance().create(dataSource, params, renderer);
+    }
+}
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/source/DataSource.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/source/DataSource.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/source/DataSource.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.chart.source;
+
+import org.xwiki.chart.ChartGeneratorException;;
+
+/**
+ * A data source for generating a chart.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public interface DataSource
+{
+    /**
+     * @return the number of rows of this data source
+     */
+    int getRowCount(); 
+
+    /**
+     * @return the number of columns of this data source
+     */    
+    int getColumnCount();
+
+    /**
+     * @param rowIndex the index of the row
+     * @param colIndex the index of the column
+     * @return the value of a single cell
+     * @throws ChartGeneratorException in case of invalid indexes
+     */
+    Number getCell(int rowIndex, int colIndex) throws ChartGeneratorException;
+
+    /**
+     * @param rowIndex the index of the row
+     * @return a whole row
+     * @throws ChartGeneratorException in case of invalid index
+     */
+    Number[] getRow(int rowIndex) throws ChartGeneratorException;
+
+    /**
+     * @param colIndex the index of the column
+     * @return A whole column
+     * @throws ChartGeneratorException in case of invalid index
+     */
+    Number[] getColumn(int colIndex) throws ChartGeneratorException;
+
+    /**
+     * @return a matrix containing the all data source values
+     */
+    Number[][] getAllCells();
+
+    /**
+     * @return true when this data source has a header row
+     */
+    boolean hasHeaderRow();
+
+    /**
+     * @return true when this data source has a header column
+     */
+    boolean hasHeaderColumn();
+
+    /**
+     * @param columnIndex the given index
+     * @return the value in the header row, given by columnIndex
+     * @throws ChartGeneratorException in case of invalid index
+     */
+    String getHeaderRowValue(int columnIndex) throws ChartGeneratorException;
+
+    /**
+     * @return the whole header row
+     * @throws ChartGeneratorException in case there is no header defined
+     */
+    String[] getHeaderRow() throws ChartGeneratorException;
+
+    /**
+     * @param rowIndex the index of the row
+     * @return the value in the header column, given by rowIndex
+     * @throws ChartGeneratorException in case there is no header defined or the index is invalid
+     */
+    String getHeaderColumnValue(int rowIndex) throws ChartGeneratorException;
+
+    /**
+     * @return the whole header column
+     * @throws ChartGeneratorException in case there is no header define
+     */
+    String[] getHeaderColumn() throws ChartGeneratorException;
+}
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,81 @@
+/*
+ * 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;
+import org.xwiki.component.annotation.ComponentRole;
+
+/**
+ * An interface containing the specifications for the chart generator.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+@ComponentRole
+public interface ChartGenerator
+{
+    /**
+     * The name of the parameter designating the chart type.
+     */
+    String TYPE_PARAM = "charType";
+    
+    /**
+     *  The name of the parameter designating the chart's title.
+     */
+    String TITLE_PARAM = "title";
+    
+    /**
+     *  The name of the parameter designating the chart's title.
+     */
+    String HEIGHT_PARAM = "height";
+
+    /**
+     *  The name of the parameter designating the chart's title.
+     */
+    String WIDTH_PARAM = "width";
+
+    /** 
+     * The series. 
+     */
+    String SERIES_PARAM = "series";
+
+    /** 
+     * If the border should be visible or not. 
+     */
+    String BORDER_VISIBLE_PARAM = "border_visible";
+
+    /** 
+     * Anti alias feature.
+     */ 
+    String ANTI_ALIAS_PARAM = "anti_alias";
+
+    /**
+     * @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
+     * @param outputDirectory the directory which will hold the generated chart
+     * @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/src/main/java/org/xwiki/chart/internal/plots/BarPlotFactory.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/BarPlotFactory.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/BarPlotFactory.java	(revision 0)
@@ -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.chart.internal.plots;
+
+import java.util.Map;
+
+import org.jfree.chart.axis.CategoryAxis;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.axis.ValueAxis;
+import org.jfree.chart.plot.CategoryPlot;
+import org.jfree.chart.plot.Plot;
+import org.jfree.chart.renderer.category.BarRenderer;
+import org.jfree.chart.renderer.category.CategoryItemRenderer;
+import org.jfree.data.category.DefaultCategoryDataset;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.plots.PlotFactory;
+import org.xwiki.chart.source.DataSource;
+
+/**
+ * An implementation for the PlotFactory.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public final class BarPlotFactory implements PlotFactory
+{
+    /** 
+     * We're dealing with a singleton. 
+     */
+    private static BarPlotFactory uniqueInstance = new BarPlotFactory();
+
+    /**
+     * A constant string to be included in the output.
+     */
+    private static final String CATEGORY_STRING = "Category ";
+
+    /**
+     * A constant string to be included in the output.
+     */
+    private static final String SERIES_STRING = "Series ";
+
+    /** 
+     * Prevents the user from instantiating the class. 
+     */
+    private BarPlotFactory()
+    {
+        // empty
+    }
+
+    /** 
+     * Forces the user to use only the unique instance. 
+     * @return the unique instance of this class
+     */
+    public static BarPlotFactory 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
+    {
+        CategoryItemRenderer renderer = new BarRenderer();
+        String dataSeries = (String) params.get(SERIES);
+        CategoryAxis domainAxis = new CategoryAxis();
+        ValueAxis rangeAxis = new NumberAxis();
+
+        DefaultCategoryDataset dataset;
+        if (COLUMNS.equals(dataSeries)) {
+            dataset = extractDataFromColumnsSeries(dataSource);
+        } else if (ROWS.equals(dataSeries)) {
+            dataset = extractDataFromRowsSeries(dataSource);
+        } else {
+            throw new ChartGeneratorException("Invalid series parameter: " + dataSeries);
+        }
+    
+        return new CategoryPlot(dataset, domainAxis, rangeAxis, (CategoryItemRenderer) renderer);
+    }
+
+    /**
+     * @param dataSource the DataSource from which to get the data
+     * @throws ChartGeneratorException in case data cannot be read
+     * @return a data set built taking the rows into account as series. 
+     */
+    private DefaultCategoryDataset extractDataFromRowsSeries(DataSource dataSource) 
+        throws ChartGeneratorException 
+    {
+        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
+        for (int row = 0; row < dataSource.getRowCount(); row++) {
+            for (int column = 0; column < dataSource.getColumnCount(); column++) {
+                dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderColumn() ? dataSource
+                    .getHeaderColumnValue(row) 
+                        : (CATEGORY_STRING + (row + 1)), dataSource.hasHeaderRow() 
+                        ? dataSource
+                            .getHeaderRowValue(column) : (SERIES_STRING + (column + 1)));
+            }
+        }
+        return dataset;
+    }
+
+    /**
+     * @param dataSource the DataSource from which to get the data
+     * @throws ChartGeneratorException in case data cannot be read
+     * @return a data set built taking the columns into account as series. 
+     */
+    private DefaultCategoryDataset extractDataFromColumnsSeries(DataSource dataSource) 
+        throws ChartGeneratorException 
+    {
+        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
+        for (int row = 0; row < dataSource.getRowCount(); row++) {
+            for (int column = 0; column < dataSource.getColumnCount(); column++) {
+                dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderRow() ? dataSource
+                    .getHeaderRowValue(column) : (CATEGORY_STRING + (column + 1)), dataSource.hasHeaderColumn()
+                        ? dataSource.getHeaderColumnValue(row) : (SERIES_STRING + (row + 1)));
+            }
+        }
+        return dataset;
+    }    
+}
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/source/DefaultDataSource.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/source/DefaultDataSource.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/source/DefaultDataSource.java	(revision 0)
@@ -0,0 +1,279 @@
+/*
+ * 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.source;
+
+import org.xwiki.chart.ChartGeneratorException;
+
+/**
+ * This offers a set of basic features for a data source and can be used as a
+ * base class for more complex data sources, too.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public class DefaultDataSource implements DataSource
+{
+    /**
+     * A matrix for storing the actual data.
+     */
+    protected Number[][] data;
+
+    /**
+     * The header rows.
+     */
+    protected String[] headerRow;
+
+    /**
+     * The header columns.
+     */
+    protected String[] headerColumn;
+
+    /**
+     * This no-arg constructor creates an empty data source with no headers.
+     */
+    public DefaultDataSource()
+    {
+        data = new Number[0][0];
+    }
+
+    /**
+     * This constructor creates a data source with no headers.
+     * 
+     * @param data A matrix containing the values of the data source
+     */
+    public DefaultDataSource(Number[][] data)
+    {
+        this.data = data;
+    }
+
+    /**
+     * This constructor creates a data source with the given data and headers.
+     * 
+     * @param data A matrix containing the values of the data source
+     * @param headerRow The header row with headerRow.length == data[x].length, for x=0,data.length-1
+     * @param headerColumn The header column with headerColumn.length == data.length
+     * @throws IllegalArgumentException Thrown when the conditions above are not satisfied
+     */
+    public DefaultDataSource(Number[][] data, String[] headerRow, String[] headerColumn)
+    {
+        if (headerColumn != null && headerColumn.length != data.length) {
+            throw new IllegalArgumentException("headerColumn.length != data.length");
+        }
+        for (int i = 0; i < data.length; i++) {
+            if (headerRow != null && headerRow.length != data[i].length) {
+                throw new IllegalArgumentException("headerRow.length != data[" + i + "]" + ".length");
+            } else if (headerRow == null && i > 0 && data[i].length != data[i - 1].length) {
+                throw new IllegalArgumentException("data[" + i + "].length != data[" + (i - 1) + "].length");
+            }
+        }
+        this.data = data;
+        this.headerColumn = headerColumn;
+        this.headerRow = headerRow;
+    }
+
+    /**
+     * @return the number of rows of this data source
+     */
+    public int getRowCount()
+    {
+        return data.length;
+    }
+
+    /**
+     * @return the number of columns of this data source
+     */
+    public int getColumnCount()
+    {
+        if (data.length > 0) {
+            return data[0].length;
+        } else {
+            return 0;
+        }
+    }
+
+    /**
+     * @param rowIndex the index of the row
+     * @param colIndex the index of the column
+     * @return the value of a single cell
+     * @throws ChartGeneratorException in case of invalid indexes
+     */
+    public Number getCell(int rowIndex, int colIndex) throws ChartGeneratorException
+    {
+        checkRowIndex(rowIndex);
+        checkColumnIndex(colIndex);
+        return data[rowIndex][colIndex];
+    }
+
+    /**
+     * Sets the value of a single cell.
+     * 
+     * @param rowIndex the index of the row
+     * @param colIndex the index of the column
+     * @param content the value to set in the cell
+     * @throws ChartGeneratorException in case of invalid indexes
+     */
+    public void setCell(int rowIndex, int colIndex, Number content) throws ChartGeneratorException
+    {
+        checkRowIndex(rowIndex);
+        checkColumnIndex(colIndex);
+        data[rowIndex][colIndex] = content;
+    }
+
+    /**
+     * @param rowIndex the index of the row
+     * @return a whole row
+     * @throws ChartGeneratorException in case of invalid index
+     */
+    public Number[] getRow(int rowIndex) throws ChartGeneratorException
+    {
+        checkRowIndex(rowIndex);
+        return data[rowIndex];
+    }
+
+    /**
+     * @param colIndex the index of the column
+     * @return A whole column
+     * @throws ChartGeneratorException in case of invalid index
+     */
+    public Number[] getColumn(int colIndex) throws ChartGeneratorException
+    {
+        checkColumnIndex(colIndex);
+        Number[] column = new Number[getRowCount()];
+        for (int i = 0; i < getRowCount(); i++) {
+            column[i] = data[i][colIndex];
+        }
+        return column;
+    }
+
+    /**
+     * @return a matrix containing the all data source values
+     */
+    public Number[][] getAllCells()
+    {
+        return data;
+    }
+
+    /**
+     * @return true when this data source has a header row
+     */
+    public boolean hasHeaderRow() 
+    {
+        return headerRow != null;
+    }
+
+    /**
+     * @return true when this data source has a header column
+     */
+    public boolean hasHeaderColumn()
+    {
+        return headerColumn != null;
+    }
+
+    /**
+     * @param columnIndex the given index
+     * @return the value in the header row, given by columnIndex
+     * @throws ChartGeneratorException in case of invalid index
+     */
+    public String getHeaderRowValue(int columnIndex) throws ChartGeneratorException
+    {
+        checkHeaderRow();
+        checkColumnIndex(columnIndex);
+        return headerRow[columnIndex];
+    }
+
+    /**
+     * @return the whole header row
+     * @throws ChartGeneratorException in case there is no header defined
+     */
+    public String[] getHeaderRow() throws ChartGeneratorException
+    {
+        checkHeaderRow();
+        return headerRow;
+    }
+
+    /**
+     * @param rowIndex the index of the row
+     * @return the value in the header column, given by rowIndex
+     * @throws ChartGeneratorException in case there is no header defined or the index is invalid
+     */
+    public String getHeaderColumnValue(int rowIndex) throws ChartGeneratorException
+    {
+        checkHeaderColumn();
+        checkRowIndex(rowIndex);
+        return headerColumn[rowIndex];
+    }
+
+    /**
+     * @return the whole header column
+     * @throws ChartGeneratorException in case there is no header define
+     */
+    public String[] getHeaderColumn() throws ChartGeneratorException
+    {
+        checkHeaderColumn();
+        return headerColumn;
+    }
+
+    /**
+     * Checks whether the given value is a valid row index.
+     * @param rowIndex the index of the row
+     * @throws ChartGeneratorException of the given index is invalid
+     */
+    private void checkRowIndex(int rowIndex) throws ChartGeneratorException
+    {
+        if (rowIndex < 0 || rowIndex >= getRowCount()) {
+            throw new ChartGeneratorException("Invalid row index: " + rowIndex);
+        }
+    }
+ 
+   /**
+    * Checks whether the given value is a valid column index.
+    * @param columnIndex the index of the row
+    * @throws ChartGeneratorException if the given index is invalid
+    */
+    private void checkColumnIndex(int columnIndex) throws ChartGeneratorException
+    {
+        if (columnIndex < 0 || columnIndex >= getColumnCount()) {
+            throw new ChartGeneratorException("Invalid column index: " + columnIndex);
+        }
+    }
+
+    /**
+     * Checks if we have a header row defined.
+     * @throws ChartGeneratorException if we don't
+     */
+    private void checkHeaderRow() throws ChartGeneratorException
+    {
+        if (!hasHeaderRow()) {
+            throw new ChartGeneratorException("No header row defined for the table.");
+        }
+    }
+
+    /**
+     * Checks if we have a header column defined.
+     * @throws ChartGeneratorException if we don't
+     */
+    private void checkHeaderColumn() throws ChartGeneratorException
+    {
+        if (!hasHeaderColumn()) {
+            throw new ChartGeneratorException("No header column defined for the table.");
+        }
+    }
+}
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/XYPlotGenerator.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/XYPlotGenerator.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/XYPlotGenerator.java	(revision 0)
@@ -0,0 +1,85 @@
+/*
+ * 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.plots;
+
+import java.util.Map;
+
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.plot.Plot;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.renderer.xy.XYItemRenderer;
+import org.jfree.data.xy.XYDataset;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.source.DataSource;
+
+/**
+ * This class is not used directly but through area, bar and line (there is a sort of dynamic inheritance here).
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public final class XYPlotGenerator
+{
+    /** 
+     * We're dealing with a singleton. 
+     */
+    private static XYPlotGenerator uniqueInstance = new XYPlotGenerator();
+
+    /** 
+     * Prevents the user from instantiating the class. 
+     */
+    private XYPlotGenerator()
+    {
+        // empty
+    }
+
+    /** 
+     * Forces the user to use only the unique instance. 
+     * @return the unique instance of this class
+     */
+    public static XYPlotGenerator getInstance()
+    {
+        return uniqueInstance;
+    }
+
+    /**
+     * @param dataSource the chart's data source
+     * @param params additional parameters
+     * @param renderer the renderer to be used for building the plot
+     * @return a Plot to be embedded within the chart 
+     * @throws ChartGeneratorException in case the data cannot be read
+     */
+    public Plot create(DataSource dataSource, Map<String, Object> params, XYItemRenderer renderer)
+        throws ChartGeneratorException
+    {
+        NumberAxis domainAxis = new NumberAxis();
+        NumberAxis rangeAxis = new NumberAxis();
+
+        XYDataset dataset = TableXYDatasetFactory.getInstance().create(dataSource, params);
+
+        if (renderer instanceof XYItemRenderer) {
+            XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, (XYItemRenderer) renderer);
+            return plot;
+        } else {
+            throw new ChartGeneratorException("Invalid renderer: " + renderer.getClass()); 
+        }
+    }
+}
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/TableXYDatasetFactory.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/TableXYDatasetFactory.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/TableXYDatasetFactory.java	(revision 0)
@@ -0,0 +1,134 @@
+/*
+ * 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.plots;
+
+import java.util.Map;
+
+import org.jfree.data.xy.DefaultTableXYDataset;
+import org.jfree.data.xy.XYDataset;
+import org.jfree.data.xy.XYSeries;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.plots.PlotFactory;
+import org.xwiki.chart.source.DataSource;
+
+/**
+ * A factory for building an XYDataset.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public final class TableXYDatasetFactory
+{
+    /** 
+     * We're dealing with a singleton. 
+     */
+    private static TableXYDatasetFactory uniqueInstance = new TableXYDatasetFactory();
+
+    /**
+     * A constant string to be included in the output.
+     */
+    private static final String SERIES_STRING = "Series ";
+    
+    /**
+     * This class is not used directly but through area, bar and line (there is a sort of dynamic inheritance here).
+     */
+    private TableXYDatasetFactory()
+    {
+        // empty
+    }
+
+    /** 
+     * Forces the user to use only the unique instance. 
+     * @return the unique instance of this class
+     */
+    public static TableXYDatasetFactory getInstance()
+    {
+        return uniqueInstance;
+    }
+
+    /**
+     * @param dataSource the source which the data will be taken from
+     * @param params various parameters
+     * @return a data set created to fit the given parameters
+     * @throws ChartGeneratorException in case a problem occurs with the data source
+     */
+    public XYDataset create(DataSource dataSource, Map<String, Object> params) 
+        throws ChartGeneratorException
+    {
+        String dataSeries = (String) params.get(PlotFactory.SERIES);
+
+        DefaultTableXYDataset dataset = new DefaultTableXYDataset();
+        if (dataSeries.equals(PlotFactory.COLUMNS)) {
+            inspectColumns(dataset, dataSource);
+        } else if (dataSeries.equals(PlotFactory.ROWS)) {
+            inspectRows(dataset, dataSource);
+        } else {
+            throw new ChartGeneratorException("Invalid series parameter:" + dataSeries);
+        }
+        return dataset;
+    }
+    
+    /**
+     * Inspects the table columns for grabbing the data.
+     * @param dataset the data set in which the values are to be added
+     * @param dataSource the data source which is to be inspected
+     * @throws ChartGeneratorException in case the data cannot be read
+     */
+    private void inspectColumns(DefaultTableXYDataset dataset, DataSource dataSource) throws ChartGeneratorException 
+    {
+        if (!dataSource.hasHeaderColumn()) {
+            throw new ChartGeneratorException("Header column required");
+        }
+        for (int column = 0; column < dataSource.getColumnCount(); column++) {
+            XYSeries series =
+                new XYSeries(dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column)
+                    : (SERIES_STRING + (column + 1)), false, false);
+            for (int row = 0; row < dataSource.getRowCount(); row++) {
+                series.add(Double.parseDouble(dataSource.getHeaderColumnValue(row)), dataSource
+                    .getCell(row, column));
+            }
+            dataset.addSeries(series);
+        }
+    }
+
+    /**
+     * Inspects the table rows for grabbing the data.
+     * @param dataset the data set in which the values are to be added
+     * @param dataSource the data source which is to be inspected
+     * @throws ChartGeneratorException in case the data cannot be read
+     */
+    private void inspectRows(DefaultTableXYDataset dataset, DataSource dataSource) throws ChartGeneratorException 
+    {
+        if (!dataSource.hasHeaderRow()) {
+            throw new ChartGeneratorException("Header row required");
+        }
+        for (int row = 0; row < dataSource.getRowCount(); row++) {
+            XYSeries series =
+                new XYSeries(dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row)
+                    : (SERIES_STRING + (row + 1)), false, false);
+            for (int column = 0; column < dataSource.getColumnCount(); column++) {
+                series.add(Double.parseDouble(dataSource.getHeaderRowValue(column)), 
+                    dataSource.getCell(row, column));
+            }
+            dataset.addSeries(series);
+        }    
+    }
+}
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/LinePlotFactory.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/LinePlotFactory.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/LinePlotFactory.java	(revision 0)
@@ -0,0 +1,73 @@
+/*
+ * 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.plots;
+
+import java.util.Map;
+
+import org.jfree.chart.plot.Plot;
+import org.jfree.chart.renderer.xy.XYItemRenderer;
+import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.plots.PlotFactory;
+import org.xwiki.chart.source.DataSource;
+
+/**
+ * An implementation for the PlotFactory needed for building a line chart.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+public final class LinePlotFactory implements PlotFactory
+{
+    /** 
+     * We're dealing with a singleton. 
+     */
+    private static LinePlotFactory uniqueInstance = new LinePlotFactory();
+
+    /** 
+     * Prevents the user from instantiating the class. 
+     */
+    private LinePlotFactory()
+    {
+        // empty
+    }
+
+    /** 
+     * Forces the user to use only the unique instance. 
+     * @return the unique instance of this class
+     */
+    public static LinePlotFactory 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
+    {
+        XYItemRenderer renderer = new XYLineAndShapeRenderer();
+        return XYPlotGenerator.getInstance().create(dataSource, params, renderer);
+    }
+}
Index: core/xwiki-jfreechart/pom.xml
===================================================================
--- core/xwiki-jfreechart/pom.xml	(revision 0)
+++ core/xwiki-jfreechart/pom.xml	(revision 0)
@@ -0,0 +1,80 @@
+<?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>org.xwiki.platform</groupId>
+  		<artifactId>xwiki-core-component</artifactId>
+  		<version>${pom.version}</version>
+	</dependency>
+    <dependency>
+  		<groupId>jfree</groupId>
+  		<artifactId>jcommon</artifactId>
+  		<version>1.0.12</version>
+	</dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/ChartGeneratorTests.java</include>
+          </includes>
+        </configuration>
+      </plugin>
+      <plugin>
+        <!-- Apply the Checkstyle configurations defined in the top level pom.xml file -->
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+</project>
Index: core/xwiki-jfreechart/src/test/java/org/xwiki/chart/ChartGeneratorTests.java
===================================================================
--- core/xwiki-jfreechart/src/test/java/org/xwiki/chart/ChartGeneratorTests.java	(revision 0)
+++ core/xwiki-jfreechart/src/test/java/org/xwiki/chart/ChartGeneratorTests.java	(revision 0)
@@ -0,0 +1,114 @@
+package org.xwiki.chart;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.xwiki.chart.ChartGenerator;
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.chart.internal.DefaultChartGenerator;
+import org.xwiki.chart.source.DataSource;
+import org.xwiki.chart.source.DefaultDataSource;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for {@link RssMacro}.
+ * 
+ * @version $Id: $
+ * @since 1.9
+ */
+public class ChartGeneratorTests extends TestCase
+{
+    /** Whether we want to delete the outputed files after a test chart is generated. **/
+    private static final boolean DELETE_OUTPUT = false;
+    
+    private ChartGenerator chartGenerator = new DefaultChartGenerator();
+    private File tempDir;
+    private File outputFile;
+    private DataSource dataSource;
+    
+    public ChartGeneratorTests(String name)
+    {
+        super(name);
+        String tempDirLocation = System.getProperty("java.io.tmpdir"); 
+        this.tempDir = new File(tempDirLocation, "chartGenerator");
+        this.tempDir.mkdirs();
+        Short dataArray[][]= {{1,2,3}, {1,3,5}}; 
+        String headerRow[] = {"1", "2", "3"};
+        this.dataSource = new DefaultDataSource(dataArray, headerRow, null);
+    }
+
+    /**
+     * Tests whether the component is able to build a pie chart.
+     * @throws ChartGeneratorException in case the chart cannot be build.
+     */
+    public final void testPieChart() throws ChartGeneratorException
+    {
+        Map<String, Object> parameters = new HashMap<String, Object>();
+        parameters.put(ChartGenerator.TITLE_PARAM, "Test pie chart");
+        parameters.put(ChartGenerator.TYPE_PARAM, "pie");
+        parameters.put(ChartGenerator.SERIES_PARAM, "rows");
+        
+        outputFile = this.chartGenerator.buildChart(dataSource, parameters, tempDir);
+        assertTrue(outputFile.exists());
+        assertTrue(outputFile.isFile());
+    }
+    
+    /**
+     * Tests whether the component is able to build a bar chart.
+     * @throws ChartGeneratorException in case the chart cannot be build.
+     */
+    public final void testBarChart() throws ChartGeneratorException
+    {
+        Map<String, Object> parameters = new HashMap<String, Object>();
+        parameters.put(ChartGenerator.TITLE_PARAM, "Test bar chart");
+        parameters.put(ChartGenerator.TYPE_PARAM, "bar");
+        parameters.put(ChartGenerator.SERIES_PARAM, "rows");
+        
+        outputFile = this.chartGenerator.buildChart(dataSource, parameters, tempDir);
+        assertTrue(outputFile.exists());
+        assertTrue(outputFile.isFile());
+    }
+
+    /**
+     * Tests whether the component is able to build a line chart.
+     * @throws ChartGeneratorException in case the chart cannot be build.
+     */
+    public final void testLineChart() throws ChartGeneratorException
+    {
+        Map<String, Object> parameters = new HashMap<String, Object>();
+        parameters.put(ChartGenerator.TITLE_PARAM, "Test line chart");
+        parameters.put(ChartGenerator.TYPE_PARAM, "line");
+        parameters.put(ChartGenerator.SERIES_PARAM, "rows");
+        
+        outputFile = this.chartGenerator.buildChart(dataSource, parameters, tempDir);
+        assertTrue(outputFile.exists());
+        assertTrue(outputFile.isFile());
+    }
+
+    /**
+     * Tests whether the component is able to build an area chart.
+     * @throws ChartGeneratorException in case the chart cannot be build.
+     */
+    public final void testAreaChart() throws ChartGeneratorException
+    {
+        Map<String, Object> parameters = new HashMap<String, Object>();
+        parameters.put(ChartGenerator.TITLE_PARAM, "Test area chart");
+        parameters.put(ChartGenerator.TYPE_PARAM, "area");
+        parameters.put(ChartGenerator.SERIES_PARAM, "rows");
+        
+        outputFile = this.chartGenerator.buildChart(dataSource, parameters, tempDir);
+        assertTrue(outputFile.exists());
+        assertTrue(outputFile.isFile());
+    }
+
+    @Override
+    protected void tearDown() 
+    {
+        System.out.println("Successfully generated " + outputFile.getAbsolutePath());
+        if (DELETE_OUTPUT) {
+            outputFile.deleteOnExit();
+        }
+    }
+}
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,125 @@
+/*
+ * 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;
+import org.xwiki.component.annotation.Component;
+
+
+/**
+ * A class containing the specifications for the chart generator.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+
+@Component
+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) {
+        setValue(SERIES_PARAM, "columns", parameters);
+        setValue(BORDER_VISIBLE_PARAM, "false", parameters);
+        setValue(ANTI_ALIAS_PARAM, "true", parameters);
+        setValue(WIDTH_PARAM, 400, parameters);
+        setValue(HEIGHT_PARAM, 300, parameters);
+    }
+    
+    /**
+     * Sets up values in a map, unless they already exist.
+     * @param key the key
+     * @param value the corresponding value
+     * @param map the map in which the values are put
+     */
+    private static void setValue(String key, Object value, Map<String, Object> map)
+    {
+        if (!map.containsKey(key)) {
+            map.put(key, value); 
+        }
+    }
+    
+    /**
+     * {@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(TYPE_PARAM);
+        String title = (String) parameters.get(TITLE_PARAM);
+        Plot plot;
+        
+        String factoryClassName = ChartGenerator.class.getPackage().getName() 
+            + ".internal.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(title, plot);
+        File file = getTempFile(parameters.hashCode() + "." + "png", outputDirectory);
+
+        int width = (Integer) parameters.get(WIDTH_PARAM);
+        int height = (Integer) parameters.get(HEIGHT_PARAM);
+        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
+     * @param outputDirectory the directory in which the file is 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/java/org/xwiki/chart/source/DataSourceFactory.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/source/DataSourceFactory.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/source/DataSourceFactory.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.source;
+
+import java.util.Map;
+
+import org.xwiki.chart.ChartGeneratorException;
+import org.xwiki.component.annotation.ComponentRole;
+
+/**
+ * A factory for building a specific data source.
+ * 
+ * @version $Id: $
+ * @since 1.9M1
+ */
+
+@ComponentRole
+public interface DataSourceFactory
+{
+    /**
+     * @return the actual data source it creates. 
+     * @param params the parameters required for building the source
+     * @throws ChartGeneratorException in case the datasource cannot be created
+     */
+    DataSource create(Map<String, Object> params) throws ChartGeneratorException;
+}
Index: core/xwiki-jfreechart/src/main/resources/META-INF/components.txt
===================================================================
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,66 @@
+/*
+ * 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
+{
+    /**
+     * The string representation of the "renderer" parameter. 
+     */
+    String RENDERER = "renderer";
+    
+    /**
+     * The string representation of the "series" parameter. 
+     */
+    String SERIES = "series";
+    
+    /**
+     * The string representation of the "rows" parameter. 
+     */
+    String ROWS = "rows";
+    
+    /**
+     * The string representation of the "column" parameter. 
+     */
+    String COLUMNS = "columns";
+
+    /**
+     * @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;
+}
Index: core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/PiePlotFactory.java
===================================================================
--- core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/PiePlotFactory.java	(revision 0)
+++ core/xwiki-jfreechart/src/main/java/org/xwiki/chart/internal/plots/PiePlotFactory.java	(revision 0)
@@ -0,0 +1,100 @@
+/*
+ * 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.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.plots.PlotFactory;
+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;
+    }
+}
