=== modified file 'dhis-2/dhis-support/dhis-support-system/pom.xml'
--- dhis-2/dhis-support/dhis-support-system/pom.xml 2011-03-02 00:23:51 +0000
+++ dhis-2/dhis-support/dhis-support-system/pom.xml 2011-03-31 11:10:04 +0000
@@ -104,6 +104,14 @@
net.sf.jasperreportsjasperreports
+
+ velocity
+ velocity
+
+
+ velocity-tools
+ velocity-tools
+ ../../
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2011-03-31 11:10:04 +0000
@@ -0,0 +1,273 @@
+package org.hisp.dhis.system.grid;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import static org.hisp.dhis.system.util.CsvUtils.NEWLINE;
+import static org.hisp.dhis.system.util.CsvUtils.SEPARATOR_B;
+import static org.hisp.dhis.system.util.CsvUtils.csvEncode;
+import static org.hisp.dhis.system.util.PDFUtils.addTableToDocument;
+import static org.hisp.dhis.system.util.PDFUtils.closeDocument;
+import static org.hisp.dhis.system.util.PDFUtils.getEmptyCell;
+import static org.hisp.dhis.system.util.PDFUtils.getItalicCell;
+import static org.hisp.dhis.system.util.PDFUtils.getSubtitleCell;
+import static org.hisp.dhis.system.util.PDFUtils.getTextCell;
+import static org.hisp.dhis.system.util.PDFUtils.getTitleCell;
+import static org.hisp.dhis.system.util.PDFUtils.openDocument;
+import static org.hisp.dhis.system.util.PDFUtils.resetPaddings;
+
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.List;
+
+import jxl.Workbook;
+import jxl.write.Label;
+import jxl.write.Number;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableFont;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import net.sf.jasperreports.engine.JasperCompileManager;
+import net.sf.jasperreports.engine.JasperExportManager;
+import net.sf.jasperreports.engine.JasperFillManager;
+import net.sf.jasperreports.engine.JasperPrint;
+import net.sf.jasperreports.engine.JasperReport;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.GridHeader;
+import org.hisp.dhis.system.util.CodecUtils;
+import org.hisp.dhis.system.util.MathUtils;
+import org.hisp.dhis.system.util.StreamUtils;
+
+import com.lowagie.text.Document;
+import com.lowagie.text.pdf.PdfPTable;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class GridUtils
+{
+ private static final String EMPTY = "";
+
+ private static final String XLS_DEFAULT_SHEET_NAME = "Sheet 1";
+
+ private static final WritableCellFormat XLS_FORMAT_TTTLE = new WritableCellFormat( new WritableFont(
+ WritableFont.TAHOMA, 13, WritableFont.NO_BOLD, false ) );
+
+ private static final WritableCellFormat XLS_FORMAT_LABEL = new WritableCellFormat( new WritableFont(
+ WritableFont.ARIAL, 11, WritableFont.NO_BOLD, true ) );
+
+ private static final WritableCellFormat XLS_FORMAT_TEXT = new WritableCellFormat( new WritableFont( WritableFont.ARIAL,
+ 11, WritableFont.NO_BOLD, false ) );
+
+ private static final String KEY_GRID = "grid";
+ private static final String TEMPLATE = "grid.vm";
+ private static final String RESOURCE_LOADER_NAME = "class";
+
+ /**
+ * Writes a PDF representation of the given Grid to the given OutputStream.
+ */
+ public static void toPdf( Grid grid, OutputStream out )
+ {
+ Document document = openDocument( out );
+
+ PdfPTable table = new PdfPTable( grid.getVisibleWidth() );
+
+ table.setHeaderRows( 1 );
+ table.setWidthPercentage( 100f );
+ table.setKeepTogether( false );
+
+ table.addCell( resetPaddings( getTitleCell( grid.getTitle(), grid.getVisibleWidth() ), 0, 45, 0, 0 ) );
+ table.addCell( getSubtitleCell( grid.getSubtitle(), grid.getVisibleWidth() ) );
+ table.addCell( getEmptyCell( grid.getVisibleWidth(), 30 ) );
+
+ for ( GridHeader header : grid.getVisibleHeaders() )
+ {
+ table.addCell( getItalicCell( header.getName() ) );
+ }
+
+ table.addCell( getEmptyCell( grid.getVisibleWidth(), 10 ) );
+
+ for ( List