=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/databrowser/DataBrowserPdfService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/databrowser/DataBrowserPdfService.java 2010-10-21 05:41:06 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/databrowser/DataBrowserPdfService.java 2011-02-18 12:26:26 +0000 @@ -57,6 +57,6 @@ * @return void */ void writeDataBrowserResult( String dataBrowserTitleName, String dataBrowserFromDate, String dataBrowserToDate, - String dataBrowserPeriodType, String pageLayout, String fileName, int fontSize, - DataBrowserTable dataBrowserTable, OutputStream out, I18n i18n ); + String dataBrowserPeriodType, String pageLayout, int fontSize, DataBrowserTable dataBrowserTable, + OutputStream out, I18n i18n ); } \ No newline at end of file === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/databrowser/DataBrowserXLSService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/databrowser/DataBrowserXLSService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/databrowser/DataBrowserXLSService.java 2011-02-18 12:26:26 +0000 @@ -0,0 +1,61 @@ +package org.hisp.dhis.databrowser; + +/* + * 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 java.io.OutputStream; + +import org.hisp.dhis.i18n.I18n; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ +public interface DataBrowserXLSService +{ + final String ID = DataBrowserXLSService.class.getName(); + + /** + * Returns an InputStream representing the tally sheet The InputStream will + * give the opportunity to either print or save the tally sheet. + * + * @param dataBrowserTitleName the title name of data browser + * @param dataBrowserFromDate the start date + * @param dataBrowserToDate the end date + * @param dataBrowserPeriodType the period type + * @param pageLayout the layout of page + * @param fileName the output file name + * @param fontSize the font size + * @param dataBrowserTable the given instance of DataBrowserTable + * @param out the output stream + * @param i18n the internationalization + * @param format the formatter for Date + * @return void + */ + void writeDataBrowserResult( String dataBrowserTitleName, String dataBrowserFromDate, String dataBrowserToDate, + String dataBrowserPeriodType, int fontSize, DataBrowserTable dataBrowserTable, OutputStream out, I18n i18n ); +} \ No newline at end of file === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/databrowser/MetaValue.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/databrowser/MetaValue.java 2009-11-23 12:12:51 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/databrowser/MetaValue.java 2011-02-18 12:26:26 +0000 @@ -36,7 +36,6 @@ */ public class MetaValue { - /** * Id for row/column */ === modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserPdfService.java' --- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserPdfService.java 2011-02-16 13:25:39 +0000 +++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserPdfService.java 2011-02-18 12:26:26 +0000 @@ -67,7 +67,7 @@ private static final Color oddColor = new Color( 0xFCFCFC ); // Whiteish public void writeDataBrowserResult( String dataBrowserTitleName, String dataBrowserFromDate, - String dataBrowserToDate, String dataBrowserPeriodType, String pageLayout, String fileName, int fontSize, + String dataBrowserToDate, String dataBrowserPeriodType, String pageLayout, int fontSize, DataBrowserTable dataBrowserTable, OutputStream out, I18n i18n ) { // There is a problem with IText regarding setting of landscape. The @@ -130,22 +130,21 @@ String dataBrowserToDate, String dataBrowserPeriodType, I18n i18n ) throws DocumentException { - Paragraph titleParagraph = new Paragraph( i18n.getString( "export_results_for" ) + " " + dataBrowserTitleName, PDFUtils.getBoldFont( 12 ) ); + Paragraph titleParagraph = new Paragraph( i18n.getString( "export_results_for" ) + " " + dataBrowserTitleName, + PDFUtils.getBoldFont( 12 ) ); - String fromDate = dataBrowserFromDate; if ( dataBrowserFromDate.length() == 0 ) { - fromDate = i18n.getString( "earliest" ); + dataBrowserFromDate = i18n.getString( "earliest" ); } - String toDate = dataBrowserToDate; if ( dataBrowserToDate.length() == 0 ) { - toDate = i18n.getString( "latest" ); + dataBrowserToDate = i18n.getString( "latest" ); } - Paragraph periodParagraph = new Paragraph( i18n.getString( "from_date" ) + ": " + fromDate + " " - + i18n.getString( "to_date" ) + ": " + toDate + ", " + i18n.getString( "period_type" ) + ": " + Paragraph periodParagraph = new Paragraph( i18n.getString( "from_date" ) + ": " + dataBrowserFromDate + " " + + i18n.getString( "to_date" ) + ": " + dataBrowserToDate + ", " + i18n.getString( "period_type" ) + ": " + i18n.getString( dataBrowserPeriodType ), PDFUtils.getFont( 8 ) ); if ( i18n != null ) @@ -184,6 +183,7 @@ { // Data rows int i = 0; + Color color; Iterator rowIt = dataBrowserTable.getRows().iterator(); for ( List col : dataBrowserTable.getCounts() ) @@ -191,15 +191,7 @@ i = i + 1; MetaValue rowMeta = rowIt.next(); - Color color; - if ( i % 2 == 1 ) - { - color = oddColor; - } - else - { - color = parColor; - } + color = ( i % 2 == 1 ) ? oddColor : parColor; PdfPCell cell = this.createTextCell( rowMeta.getName(), fontSize, color ); @@ -211,7 +203,7 @@ FontFactory.HELVETICA, fontSize, Font.NORMAL, Color.BLACK ) ); // Color zero values as bold red - if ( rowItem.trim().matches("0") ) + if ( rowItem.trim().matches( "0" ) ) { phrase.getFont().setStyle( Font.BOLD ); phrase.getFont().setColor( Color.RED ); === added file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserXLSService.java' --- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserXLSService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserXLSService.java 2011-02-18 12:26:26 +0000 @@ -0,0 +1,107 @@ +package org.hisp.dhis.databrowser; + +/* + * 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 java.io.OutputStream; + +import jxl.format.Alignment; +import jxl.format.Border; +import jxl.format.BorderLineStyle; +import jxl.format.Colour; +import jxl.format.UnderlineStyle; +import jxl.write.WritableCellFormat; +import jxl.write.WritableFont; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; +import jxl.write.WriteException; + +import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.system.util.ExcelUtils; + +import com.lowagie.text.DocumentException; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ +public class DefaultDataBrowserXLSService + implements DataBrowserXLSService +{ + public void writeDataBrowserResult( String dataBrowserTitleName, String dataBrowserFromDate, + String dataBrowserToDate, String dataBrowserPeriodType, int fontSize, DataBrowserTable dataBrowserTable, + OutputStream out, I18n i18n ) + { + WritableCellFormat FORMAT_MAIN_TITLE = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, fontSize + 5, WritableFont.BOLD ) ); + + WritableCellFormat FORMAT_SUB_TITLE = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, fontSize - 2 ) ); + + WritableCellFormat FORMAT_HEADER = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, fontSize + 2, + WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.WHITE ) ); + + WritableCellFormat FORMAT_PAR_TEXT = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, fontSize ) ); + + WritableCellFormat FORMAT_ODD_TEXT = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, fontSize ) ); + + try + { + WritableWorkbook workbook = ExcelUtils.openWorkbook( out ); + + WritableSheet sheet = workbook.createSheet( i18n.getString( "drill_down_data" ), 1 ); + + FORMAT_MAIN_TITLE.setShrinkToFit( true ); + FORMAT_SUB_TITLE.setShrinkToFit( true ); + + ExcelUtils.setUpFormat( FORMAT_MAIN_TITLE, Alignment.GENERAL, Border.NONE, BorderLineStyle.THIN, Colour.WHITE ); + ExcelUtils.setUpFormat( FORMAT_SUB_TITLE, Alignment.GENERAL, Border.NONE, BorderLineStyle.THIN, Colour.WHITE ); + ExcelUtils.setUpFormat( FORMAT_HEADER, Alignment.CENTRE, Border.ALL, BorderLineStyle.NONE, Colour.BLUE_GREY ); + ExcelUtils.setUpFormat( FORMAT_PAR_TEXT, Alignment.GENERAL, Border.NONE, BorderLineStyle.THIN, Colour.GRAY_25 ); + ExcelUtils.setUpFormat( FORMAT_ODD_TEXT, Alignment.GENERAL, Border.NONE, BorderLineStyle.THIN, Colour.WHITE ); + + // Title information + ExcelUtils.writeDataBrowserTitle( sheet, FORMAT_MAIN_TITLE, FORMAT_SUB_TITLE, dataBrowserTitleName, + dataBrowserFromDate, dataBrowserToDate, dataBrowserPeriodType, i18n ); + + // Header information + ExcelUtils.writeDataBrowserHeaders( sheet, FORMAT_HEADER, dataBrowserTable, i18n ); + + // Data information + ExcelUtils.writeDataBrowserResults( sheet, FORMAT_PAR_TEXT, FORMAT_ODD_TEXT, fontSize, dataBrowserTable ); + + ExcelUtils.writeAndCloseWorkbook( workbook ); + } + catch ( WriteException e ) + { + e.printStackTrace(); + } + catch ( DocumentException e ) + { + e.printStackTrace(); + } + } + +} === modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2011-01-16 07:12:01 +0000 +++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2011-02-18 12:26:26 +0000 @@ -109,6 +109,8 @@ + === modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExcelUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExcelUtils.java 2011-01-17 17:03:05 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExcelUtils.java 2011-02-18 12:26:26 +0000 @@ -30,6 +30,8 @@ import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; import jxl.Workbook; @@ -37,13 +39,17 @@ import jxl.format.Border; import jxl.format.BorderLineStyle; import jxl.format.Colour; +import jxl.format.UnderlineStyle; import jxl.write.Label; import jxl.write.WritableCellFormat; +import jxl.write.WritableFont; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException; import jxl.write.biff.RowsExceededException; +import org.hisp.dhis.databrowser.DataBrowserTable; +import org.hisp.dhis.databrowser.MetaValue; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.expression.ExpressionService; import org.hisp.dhis.i18n.I18n; @@ -51,6 +57,8 @@ import org.hisp.dhis.indicator.Indicator; import org.hisp.dhis.organisationunit.OrganisationUnit; +import com.lowagie.text.DocumentException; + /** * @author Dang Duy Hieu * @version $Id$ @@ -254,7 +262,7 @@ throws RowsExceededException, WriteException { sheet.addCell( new Label( column, row, i18n.getString( "organisation_unit_level" ), format1 ) ); - sheet.mergeCells( column, row, level-1, row ); + sheet.mergeCells( column, row, level - 1, row ); row++; @@ -271,6 +279,119 @@ sheet.addCell( new Label( column, row, unit.getName(), format ) ); } + // ------------------------------------------------------------------------- + // DataBrowser + // ------------------------------------------------------------------------- + + public static void writeDataBrowserTitle( WritableSheet sheet, WritableCellFormat formatTitle, + WritableCellFormat formatSubTitle, String dataBrowserTitleName, String dataBrowserFromDate, + String dataBrowserToDate, String dataBrowserPeriodType, I18n i18n ) + { + try + { + sheet.addCell( new Label( 0, 0, i18n.getString( "export_results_for" ) + " " + dataBrowserTitleName, + formatTitle ) ); + sheet.mergeCells( 0, 0, 5, 0 ); + + if ( dataBrowserFromDate.length() == 0 ) + { + dataBrowserFromDate = i18n.getString( "earliest" ); + } + + if ( dataBrowserToDate.length() == 0 ) + { + dataBrowserToDate = i18n.getString( "latest" ); + } + + sheet.addCell( new Label( 0, 1, i18n.getString( "from_date" ) + ": " + dataBrowserFromDate + " " + + i18n.getString( "to_date" ) + ": " + dataBrowserToDate + ", " + i18n.getString( "period_type" ) + + ": " + i18n.getString( dataBrowserPeriodType ), formatSubTitle ) ); + sheet.mergeCells( 0, 1, 5, 1 ); + } + catch ( RowsExceededException e ) + { + e.printStackTrace(); + } + catch ( WriteException e ) + { + e.printStackTrace(); + } + } + + public static void writeDataBrowserHeaders( WritableSheet sheet, WritableCellFormat cellFormat, + DataBrowserTable dataBrowserTable, I18n i18n ) + { + int column = 0; + + try + { + for ( MetaValue col : dataBrowserTable.getColumns() ) + { + sheet.addCell( new Label( column++, 3, i18n.getString( DateUtils.convertDate( col.getName() ) ), + cellFormat ) ); + } + } + catch ( RowsExceededException e ) + { + e.printStackTrace(); + } + catch ( WriteException e ) + { + e.printStackTrace(); + } + } + + public static void writeDataBrowserResults( WritableSheet sheet, WritableCellFormat parFormat, + WritableCellFormat oddFormat, int fontSize, DataBrowserTable dataBrowserTable ) + throws DocumentException + { + // Data rows + int i = 0; + int row = 4; + int column = 0; + + WritableCellFormat cellFormat = null; + WritableFont zeroFont = new WritableFont( WritableFont.ARIAL, fontSize, WritableFont.BOLD, false, + UnderlineStyle.NO_UNDERLINE, Colour.RED ); + + Iterator rowIt = dataBrowserTable.getRows().iterator(); + + for ( List rows : dataBrowserTable.getCounts() ) + { + i++; + MetaValue rowMeta = rowIt.next(); + + cellFormat = (i % 2 == 1) ? parFormat : oddFormat; + + try + { + sheet.addCell( new Label( column++, row, rowMeta.getName(), cellFormat ) ); + + for ( String rowItem : rows ) + { + if ( rowItem.trim().matches( "0" ) ) + { + cellFormat.setFont( zeroFont ); + } + + // Color zero values as bold red + sheet.addCell( new Label( column++, row, rowItem, cellFormat ) ); + } + } + catch ( RowsExceededException e ) + { + e.printStackTrace(); + } + catch ( WriteException e ) + { + e.printStackTrace(); + } + + row++; + column = 0; + } + } + /** * Creates a writable workbook. * === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/AbstractExportDataBrowserResult.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/AbstractExportDataBrowserResult.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/AbstractExportDataBrowserResult.java 2011-02-18 12:26:26 +0000 @@ -0,0 +1,175 @@ +package org.hisp.dhis.dataadmin.action; + +/* + * Copyright (c) 2004-${year}, 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 java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.Iterator; +import java.util.List; + +import org.hisp.dhis.databrowser.DataBrowserTable; +import org.hisp.dhis.databrowser.MetaValue; +import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.util.SessionUtils; + +import com.opensymphony.xwork2.Action; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ +public abstract class AbstractExportDataBrowserResult + implements Action +{ + private static final String KEY_DATABROWSERTITLENAME = "dataBrowserTitleName"; + + private static final String KEY_DATABROWSERFROMDATE = "dataBrowserFromDate"; + + private static final String KEY_DATABROWSERTODATE = "dataBrowserToDate"; + + private static final String KEY_DATABROWSERPERIODTYPE = "dataBrowserPeriodType"; + + private static final String KEY_DATABROWSERTABLE = "dataBrowserTableResults"; + + // ------------------------------------------------------------------------- + // I18n + // ------------------------------------------------------------------------- + + protected I18n i18n; + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + + // ------------------------------------------------------------------------- + // Input / output + // ------------------------------------------------------------------------- + + protected DataBrowserTable dataBrowserTable; + + public List getAllColumns() + { + return dataBrowserTable.getColumns(); + } + + public DataBrowserTable getDataBrowserTable() + { + return dataBrowserTable; + } + + public List> getAllCounts() + { + return dataBrowserTable.getCounts(); + } + + public Iterator getRowNamesIterator() + { + return dataBrowserTable.getRows().iterator(); + } + + protected InputStream inputStream; + + public InputStream getInputStream() + { + return inputStream; + } + + protected String fileName; + + public void setFileName( String fileName ) + { + this.fileName = fileName; + } + + public String getFileName() + { + return this.fileName; + } + + protected String pageLayout; + + public void setPageLayout( String pageLayout ) + { + this.pageLayout = pageLayout; + } + + protected int fontSize; + + public void setFontSize( int fontSize ) + { + this.fontSize = fontSize; + } + + protected String exportType; + + public void setExportType( String type ) + { + this.exportType = type; + } + + protected String contentType; + + public String getContentType() + { + return contentType; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + // Get session variables set by SearchAction + String dataBrowserTitleName = (String) SessionUtils.getSessionVar( KEY_DATABROWSERTITLENAME ); + String dataBrowserFromDate = (String) SessionUtils.getSessionVar( KEY_DATABROWSERFROMDATE ); + String dataBrowserToDate = (String) SessionUtils.getSessionVar( KEY_DATABROWSERTODATE ); + String dataBrowserPeriodType = (String) SessionUtils.getSessionVar( KEY_DATABROWSERPERIODTYPE ); + DataBrowserTable dataBrowserTable = (DataBrowserTable) SessionUtils.getSessionVar( KEY_DATABROWSERTABLE ); + + // Export to XLS + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + executeExportResult( dataBrowserTitleName, dataBrowserFromDate, dataBrowserToDate, dataBrowserPeriodType, + pageLayout, fontSize, dataBrowserTable, baos, i18n ); + + // Set final inputStream for Velocity + inputStream = new ByteArrayInputStream( baos.toByteArray() ); + + return SUCCESS; + } + + protected abstract void executeExportResult( String dataBrowserTitleName, String dataBrowserFromDate, + String dataBrowserToDate, String dataBrowserPeriodType, String pageLayout, int fontSize, + DataBrowserTable dataBrowserTable, ByteArrayOutputStream baos, I18n i18n ); + +} === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ExportDrillDownResultAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ExportDrillDownResultAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ExportDrillDownResultAction.java 2011-02-18 12:26:26 +0000 @@ -0,0 +1,99 @@ +package org.hisp.dhis.dataadmin.action.databrowser; + +/* + * Copyright (c) 2004-${year}, 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 java.io.ByteArrayOutputStream; + +import org.hisp.dhis.dataadmin.action.AbstractExportDataBrowserResult; +import org.hisp.dhis.databrowser.DataBrowserPdfService; +import org.hisp.dhis.databrowser.DataBrowserTable; +import org.hisp.dhis.databrowser.DataBrowserXLSService; +import org.hisp.dhis.i18n.I18n; + +/** + * @author Dang Duy Hieu + * @version $Id$ + */ +public class ExportDrillDownResultAction + extends AbstractExportDataBrowserResult +{ + private static final String REGEX_EXTENSION_PDF = "\\.pdf"; + + private static final String REGEX_EXTENSION_XLS = "\\.xls"; + + private static final String EXTENSION_PDF = ".pdf"; + + private static final String EXTENSION_XLS = ".xls"; + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private DataBrowserPdfService dataBrowserPdfService; + + public void setDataBrowserPdfService( DataBrowserPdfService dataBrowserPdfService ) + { + this.dataBrowserPdfService = dataBrowserPdfService; + } + + private DataBrowserXLSService dataBrowserXLSService; + + public void setDataBrowserXLSService( DataBrowserXLSService dataBrowserXLSService ) + { + this.dataBrowserXLSService = dataBrowserXLSService; + } + + // ------------------------------------------------------------------------- + // Override + // ------------------------------------------------------------------------- + + @Override + protected void executeExportResult( String dataBrowserTitleName, String dataBrowserFromDate, + String dataBrowserToDate, String dataBrowserPeriodType, String pageLayout, int fontSize, + DataBrowserTable dataBrowserTable, ByteArrayOutputStream baos, I18n i18n ) + { + if ( this.exportType.equals( "pdf" ) ) + { + this.contentType = "application/pdf"; + + this.fileName = fileName.replaceAll( REGEX_EXTENSION_PDF, "" ).concat( EXTENSION_PDF ); + + dataBrowserPdfService.writeDataBrowserResult( dataBrowserTitleName, dataBrowserFromDate, dataBrowserToDate, + dataBrowserPeriodType, pageLayout, fontSize, dataBrowserTable, baos, i18n ); + } + else + { + this.contentType = "application/xls"; + + this.fileName = fileName.replaceAll( REGEX_EXTENSION_XLS, "" ).concat( EXTENSION_XLS ); + + dataBrowserXLSService.writeDataBrowserResult( dataBrowserTitleName, dataBrowserFromDate, dataBrowserToDate, + dataBrowserPeriodType, fontSize, dataBrowserTable, baos, i18n ); + } + } +} === removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ExportPDFAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ExportPDFAction.java 2011-02-16 20:19:25 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ExportPDFAction.java 1970-01-01 00:00:00 +0000 @@ -1,173 +0,0 @@ -package org.hisp.dhis.dataadmin.action.databrowser; - -/* - * Copyright (c) 2004-${year}, 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 java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.util.Iterator; -import java.util.List; - -import org.hisp.dhis.databrowser.DataBrowserPdfService; -import org.hisp.dhis.databrowser.DataBrowserTable; -import org.hisp.dhis.databrowser.MetaValue; -import org.hisp.dhis.i18n.I18n; -import org.hisp.dhis.util.SessionUtils; - -import com.opensymphony.xwork2.Action; - -/** - * @author briane, eivinhb - * @version $Id ExportPDFAction.java Oct 21, 2010 ddhieu$ - */ -public class ExportPDFAction - implements Action -{ - private static final String KEY_DATABROWSERTITLENAME = "dataBrowserTitleName"; - - private static final String KEY_DATABROWSERFROMDATE = "dataBrowserFromDate"; - - private static final String KEY_DATABROWSERTODATE = "dataBrowserToDate"; - - private static final String KEY_DATABROWSERPERIODTYPE = "dataBrowserPeriodType"; - - private static final String KEY_DATABROWSERTABLE = "dataBrowserTableResults"; - - private static final String REGEX_EXTENSION_PDF = "\\.pdf"; - - private static final String EXTENSION_PDF = ".pdf"; - - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private DataBrowserPdfService dataBrowserPdfService; - - public void setDataBrowserPdfService( DataBrowserPdfService dataBrowserPdfService ) - { - this.dataBrowserPdfService = dataBrowserPdfService; - } - - // ------------------------------------------------------------------------- - // I18n - // ------------------------------------------------------------------------- - - private I18n i18n; - - public void setI18n( I18n i18n ) - { - this.i18n = i18n; - } - - // ------------------------------------------------------------------------- - // Input / output - // ------------------------------------------------------------------------- - - private DataBrowserTable dataBrowserTable; - - public List getAllColumns() - { - return dataBrowserTable.getColumns(); - } - - public DataBrowserTable getDataBrowserTable() - { - return dataBrowserTable; - } - - public List> getAllCounts() - { - return dataBrowserTable.getCounts(); - } - - public Iterator getRowNamesIterator() - { - return dataBrowserTable.getRows().iterator(); - } - - private InputStream inputStream; - - public InputStream getInputStream() - { - return inputStream; - } - - private String fileName; - - public void setFileName( String fileName ) - { - this.fileName = fileName.replaceAll( REGEX_EXTENSION_PDF, "" ).concat( EXTENSION_PDF ); - } - - public String getFileName() - { - return this.fileName; - } - - private int fontSize; - - public void setFontSize( int fontSize ) - { - this.fontSize = fontSize; - } - - private String pageLayout; - - public void setPageLayout( String pageLayout ) - { - this.pageLayout = pageLayout; - } - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - public String execute() - throws Exception - { - // Get session variables set by SearchAction - String dataBrowserTitleName = (String) SessionUtils.getSessionVar( KEY_DATABROWSERTITLENAME ); - String dataBrowserFromDate = (String) SessionUtils.getSessionVar( KEY_DATABROWSERFROMDATE ); - String dataBrowserToDate = (String) SessionUtils.getSessionVar( KEY_DATABROWSERTODATE ); - String dataBrowserPeriodType = (String) SessionUtils.getSessionVar( KEY_DATABROWSERPERIODTYPE ); - DataBrowserTable dataBrowserTable = (DataBrowserTable) SessionUtils.getSessionVar( KEY_DATABROWSERTABLE ); - - // Export to PDF - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - dataBrowserPdfService.writeDataBrowserResult( dataBrowserTitleName, dataBrowserFromDate, dataBrowserToDate, - dataBrowserPeriodType, pageLayout, fileName, fontSize, dataBrowserTable, baos, i18n ); - - // Set final inputStream for Velocity - inputStream = new ByteArrayInputStream( baos.toByteArray() ); - - return SUCCESS; - } - -} === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml 2011-01-19 06:43:16 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/META-INF/dhis/beans.xml 2011-02-18 12:26:26 +0000 @@ -142,12 +142,14 @@ scope="prototype"> - - + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml 2011-01-06 17:07:18 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/struts.xml 2011-02-18 12:26:26 +0000 @@ -198,10 +198,10 @@ /dhis-web-maintenance-dataadmin/menu.vm - + - application/pdf + ${contentType} inputStream attachment;filename="${fileName}" === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserResult.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserResult.vm 2011-02-16 13:25:39 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserResult.vm 2011-02-18 12:26:26 +0000 @@ -107,11 +107,17 @@ #end
-
+ + $i18n.getString( "export_type" ): + $i18n.getString( "file_name" ): $i18n.getString( "font_size" ): - - + +
-
+

#if ( $fromDate == "" || $toDate == "" ) === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataBrowser.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataBrowser.js 2010-08-31 08:12:53 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/dataBrowser.js 2011-02-18 12:26:26 +0000 @@ -90,4 +90,7 @@ window.location.href = currentUrlLink; } - +function changeType( type ) +{ + type == "xls" ? disable( "pageLayout" ) : enable( "pageLayout" ); +} \ No newline at end of file