=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/ExportXMLAction.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/ExportXMLAction.java 2012-05-03 10:04:29 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/ExportXMLAction.java 2012-11-02 04:42:01 +0000
@@ -104,8 +104,7 @@
}
}
- xmlStructureResponse = new XMLStructureResponse( selectionManager.getDownloadFilePath(), sheets, false,
- false, true, false, true ).getXml();
+ xmlStructureResponse = new XMLStructureResponse( selectionManager.getDownloadFilePath(), sheets ).getXml();
return SUCCESS;
}
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponse.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponse.java 2012-05-03 10:04:29 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponse.java 2012-11-02 04:42:01 +0000
@@ -29,7 +29,6 @@
import static org.apache.commons.io.FilenameUtils.getExtension;
import static org.hisp.dhis.reportsheet.utils.ExcelUtils.convertAlignmentString;
-import static org.hisp.dhis.reportsheet.utils.ExcelUtils.convertVerticalString;
import static org.hisp.dhis.reportsheet.utils.ExcelUtils.readValueByPOI;
import static org.hisp.dhis.reportsheet.utils.NumberUtils.PATTERN_DECIMAL_FORMAT1;
import static org.hisp.dhis.reportsheet.utils.NumberUtils.applyPatternDecimalFormat;
@@ -41,7 +40,6 @@
import java.util.Locale;
import java.util.Set;
-import org.apache.poi.hssf.usermodel.HSSFPatternFormatting;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
@@ -53,7 +51,6 @@
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
/**
* Simple demo class which uses the api to present the contents of an excel 97
@@ -78,16 +75,6 @@
private FormulaEvaluator evaluatorFormula;
- private boolean bWRITE_VERSION;
-
- private boolean bWRITE_DTD;
-
- private static final String XML_VERSION = "";
-
- private static final String DOCTYPE_NORMAL = "";
-
- private static final String DOCTYPE_FORMAT = "";
-
private static final String WORKBOOK_OPENTAG = "";
private static final String WORKBOOK_CLOSETAG = "";
@@ -121,13 +108,10 @@
* @exception java.io.IOException
*/
- public XMLStructureResponse( String pathFileName, Set collectSheets, boolean bWriteDTD,
- boolean bWriteVersion, boolean bFormat, boolean bDetailed, boolean bWriteDescription )
+ public XMLStructureResponse( String pathFileName, Set collectSheets )
throws Exception
{
this.cleanUpForResponse();
- this.bWRITE_DTD = bWriteDTD;
- this.bWRITE_VERSION = bWriteVersion;
if ( getExtension( pathFileName ).equals( "xls" ) )
{
@@ -143,61 +127,8 @@
this.evaluatorFormula = WORKBOOK.getCreationHelper().createFormulaEvaluator();
- if ( bFormat )
- {
- writeFormattedXML( collectSheets, bDetailed, bWriteDescription );
- }
- else
- {
- writeXML( collectSheets );
- }
- }
-
- /**
- * Writes out the WORKBOOK data as XML, without formatting information
- */
- private void writeXML( Collection collectSheets )
- throws IOException
- {
- if ( this.bWRITE_VERSION )
- {
- xml.append( XML_VERSION );
- }
-
- if ( this.bWRITE_DTD )
- {
- xml.append( DOCTYPE_NORMAL );
- }
-
- xml.append( WORKBOOK_OPENTAG );
-
- for ( Integer sheetNo : collectSheets )
- {
- Sheet sheet = WORKBOOK.getSheetAt( sheetNo - 1 );
-
- xml.append( "" );
- xml.append( "" );
-
- for ( Row row : sheet )
- {
- xml.append( "" );
-
- for ( Cell cell : row )
- {
- if ( cell.getCellType() != Cell.CELL_TYPE_BLANK )
- {
- xml.append( "" );
- xml.append( "" );
- xml.append( "" );
- }
- }
- xml.append( "
" );
- }
- xml.append( "" );
- }
- xml.append( WORKBOOK_CLOSETAG );
+ writeFormattedXML( collectSheets );
+
}
/**
@@ -208,29 +139,17 @@
* @throws Exception
*/
- private void writeFormattedXML( Collection collectSheets, boolean bDetailed, boolean bWriteDescription )
+ private void writeFormattedXML( Collection collectSheets )
throws Exception
{
- if ( bWriteDescription )
- {
- this.writeXMLMergedDescription( collectSheets );
- }
-
- if ( this.bWRITE_VERSION )
- {
- xml.append( XML_VERSION );
- }
-
- if ( this.bWRITE_DTD )
- {
- xml.append( DOCTYPE_FORMAT );
- }
+
+ this.writeXMLMergedDescription( collectSheets );
xml.append( WORKBOOK_OPENTAG );
for ( Integer sheet : collectSheets )
{
- writeBySheetNo( sheet, bDetailed );
+ writeBySheetNo( sheet );
}
xml.append( WORKBOOK_CLOSETAG );
@@ -240,7 +159,7 @@
// Sub-methods
// -------------------------------------------------------------------------
- private void writeBySheetNo( int sheetNo, boolean bDetailed )
+ private void writeBySheetNo( int sheetNo )
{
Sheet s = WORKBOOK.getSheetAt( sheetNo - 1 );
@@ -262,7 +181,7 @@
+ readValueByPOI( row.getRowNum() + 1, cell.getColumnIndex() + 1, s, evaluatorFormula )
+ "]]>" );
- this.readingDetailsFormattedCell( s, cell, bDetailed );
+ this.readingDetailsFormattedCell( s, cell );
xml.append( "" );
}
@@ -272,44 +191,28 @@
xml.append( "" );
}
- private void readingDetailsFormattedCell( Sheet sheet, Cell objCell, boolean bDetailed )
+ private void readingDetailsFormattedCell( Sheet sheet, Cell objCell )
{
// The format information
CellStyle format = objCell.getCellStyle();
if ( format != null )
{
- xml.append( "" );
-
- xml.append( "" );
-
- // The cell background information
- if ( format.getFillBackgroundColor() != IndexedColors.WHITE.getIndex()
- || format.getFillPattern() != HSSFPatternFormatting.NO_FILL )
- {
- xml.append( "" );
- }
-
- // The cell number/date format
- if ( !format.getDataFormatString().equals( "" ) )
- {
- xml.append( "" );
- }
+ xml.append( ">" );
+
xml.append( "" );
}
else
@@ -325,25 +228,19 @@
private void writeXMLMergedDescription( Collection collectSheets )
throws IOException
{
- // Get the Range of the Merged Cells //
- if ( this.bWRITE_VERSION )
- {
- xml.append( XML_VERSION );
- }
-
// Open the main Tag //
xml.append( MERGEDCELL_OPENTAG );
for ( Integer sheet : collectSheets )
{
- writeBySheetNo( sheet );
+ writeMergedInfoBySheetNo( sheet );
}
// Close the main Tag //
xml.append( MERGEDCELL_CLOSETAG );
}
- private void writeBySheetNo( int sheetNo )
+ private void writeMergedInfoBySheetNo( int sheetNo )
{
Sheet sheet = WORKBOOK.getSheetAt( sheetNo - 1 );
CellRangeAddress cellRangeAddress = null;
@@ -360,4 +257,24 @@
}
}
}
+
+ private String getSimilarColor( short index )
+ {
+ if ( IndexedColors.BLUE.getIndex() == index )
+ {
+ return "blue";
+ }
+
+ if ( IndexedColors.DARK_BLUE.getIndex() == index )
+ {
+ return "darkblue";
+ }
+
+ if ( IndexedColors.BROWN.getIndex() == index )
+ {
+ return "brown";
+ }
+
+ return "";
+ }
}
\ No newline at end of file
=== added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponseBIS.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponseBIS.java 1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponseBIS.java 2012-11-02 04:42:01 +0000
@@ -0,0 +1,376 @@
+package org.hisp.dhis.reportsheet.preview.action;
+
+/*
+ * Copyright (c) 2004-2012, 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.apache.commons.io.FilenameUtils.getExtension;
+import static org.hisp.dhis.reportsheet.utils.ExcelUtils.convertAlignmentString;
+import static org.hisp.dhis.reportsheet.utils.ExcelUtils.convertVerticalString;
+import static org.hisp.dhis.reportsheet.utils.ExcelUtils.readValueByPOI;
+import static org.hisp.dhis.reportsheet.utils.NumberUtils.PATTERN_DECIMAL_FORMAT1;
+import static org.hisp.dhis.reportsheet.utils.NumberUtils.applyPatternDecimalFormat;
+import static org.hisp.dhis.reportsheet.utils.NumberUtils.resetDecimalFormatByLocale;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Set;
+
+import org.apache.poi.hssf.usermodel.HSSFPatternFormatting;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.FontUnderline;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+/**
+ * Simple demo class which uses the api to present the contents of an excel 97
+ * spreadsheet as an XML document, using a workbook and output stream of your
+ * choice
+ *
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+
+public class XMLStructureResponseBIS
+{
+ /**
+ * The encoding to write
+ */
+ private StringBuffer xml = new StringBuffer( 200000 );
+
+ /**
+ * The workbook we are reading from a given file
+ */
+ private Workbook WORKBOOK;
+
+ private FormulaEvaluator evaluatorFormula;
+
+ private boolean bWRITE_VERSION;
+
+ private boolean bWRITE_DTD;
+
+ private static final String XML_VERSION = "";
+
+ private static final String DOCTYPE_NORMAL = "";
+
+ private static final String DOCTYPE_FORMAT = "";
+
+ private static final String WORKBOOK_OPENTAG = "";
+
+ private static final String WORKBOOK_CLOSETAG = "";
+
+ private static final String MERGEDCELL_OPENTAG = "";
+
+ private static final String MERGEDCELL_CLOSETAG = "";
+
+ // -------------------------------------------------------------------------
+ // Get & Set methods
+ // -------------------------------------------------------------------------
+
+ protected String getXml()
+ {
+ return xml.toString();
+ }
+
+ private void cleanUpForResponse()
+ {
+ System.gc();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param w The workbook to interrogate
+ * @param enc The encoding used by the output stream. Null or unrecognized
+ * values cause the encoding to default to UTF8
+ * @param f Indicates whether the generated XML document should contain the
+ * cell format information
+ * @exception java.io.IOException
+ */
+
+ public XMLStructureResponseBIS( String pathFileName, Set collectSheets, boolean bWriteDTD,
+ boolean bWriteVersion, boolean bFormat, boolean bDetailed, boolean bWriteDescription )
+ throws Exception
+ {
+ this.cleanUpForResponse();
+ this.bWRITE_DTD = bWriteDTD;
+ this.bWRITE_VERSION = bWriteVersion;
+
+ if ( getExtension( pathFileName ).equals( "xls" ) )
+ {
+ this.WORKBOOK = new HSSFWorkbook( new FileInputStream( pathFileName ) );
+ }
+ else
+ {
+ this.WORKBOOK = new XSSFWorkbook( new FileInputStream( pathFileName ) );
+ }
+
+ resetDecimalFormatByLocale( Locale.GERMAN );
+ applyPatternDecimalFormat( PATTERN_DECIMAL_FORMAT1 );
+
+ this.evaluatorFormula = WORKBOOK.getCreationHelper().createFormulaEvaluator();
+
+ if ( bFormat )
+ {
+ writeFormattedXML( collectSheets, bDetailed, bWriteDescription );
+ }
+ else
+ {
+ writeXML( collectSheets );
+ }
+ }
+
+ /**
+ * Writes out the WORKBOOK data as XML, without formatting information
+ */
+ private void writeXML( Collection collectSheets )
+ throws IOException
+ {
+ if ( this.bWRITE_VERSION )
+ {
+ xml.append( XML_VERSION );
+ }
+
+ if ( this.bWRITE_DTD )
+ {
+ xml.append( DOCTYPE_NORMAL );
+ }
+
+ xml.append( WORKBOOK_OPENTAG );
+
+ for ( Integer sheetNo : collectSheets )
+ {
+ Sheet sheet = WORKBOOK.getSheetAt( sheetNo - 1 );
+
+ xml.append( "" );
+ xml.append( "" );
+
+ for ( Row row : sheet )
+ {
+ xml.append( "" );
+
+ for ( Cell cell : row )
+ {
+ if ( cell.getCellType() != Cell.CELL_TYPE_BLANK )
+ {
+ xml.append( "" );
+ xml.append( "" );
+ xml.append( "" );
+ }
+ }
+ xml.append( "
" );
+ }
+ xml.append( "" );
+ }
+ xml.append( WORKBOOK_CLOSETAG );
+ }
+
+ /**
+ * Writes out the WORKBOOK data as XML, with formatting information
+ *
+ * @param bDetailed
+ *
+ * @throws Exception
+ */
+
+ private void writeFormattedXML( Collection collectSheets, boolean bDetailed, boolean bWriteDescription )
+ throws Exception
+ {
+ if ( bWriteDescription )
+ {
+ this.writeXMLMergedDescription( collectSheets );
+ }
+
+ if ( this.bWRITE_VERSION )
+ {
+ xml.append( XML_VERSION );
+ }
+
+ if ( this.bWRITE_DTD )
+ {
+ xml.append( DOCTYPE_FORMAT );
+ }
+
+ xml.append( WORKBOOK_OPENTAG );
+
+ for ( Integer sheet : collectSheets )
+ {
+ writeBySheetNo( sheet, bDetailed );
+ }
+
+ xml.append( WORKBOOK_CLOSETAG );
+ }
+
+ // -------------------------------------------------------------------------
+ // Sub-methods
+ // -------------------------------------------------------------------------
+
+ private void writeBySheetNo( int sheetNo, boolean bDetailed )
+ {
+ Sheet s = WORKBOOK.getSheetAt( sheetNo - 1 );
+
+ xml.append( "" );
+ xml.append( "" );
+
+ for ( Row row : s )
+ {
+ xml.append( "" );
+
+ for ( Cell cell : row )
+ {
+ // Remember that empty cells can contain format information
+ if ( (cell.getCellStyle() != null || cell.getCellType() != Cell.CELL_TYPE_BLANK)
+ && !s.isColumnHidden( cell.getColumnIndex() ) )
+ {
+ xml.append( "" );
+ xml.append( "" );
+
+ this.readingDetailsFormattedCell( s, cell, bDetailed );
+
+ xml.append( "" );
+ }
+ }
+ xml.append( "
" );
+ }
+ xml.append( "" );
+ }
+
+ private void readingDetailsFormattedCell( Sheet sheet, Cell objCell, boolean bDetailed )
+ {
+ // The format information
+ CellStyle format = objCell.getCellStyle();
+
+ if ( format != null )
+ {
+ xml.append( "" );
+
+ xml.append( "" );
+
+ // The cell background information
+ if ( format.getFillBackgroundColor() != IndexedColors.WHITE.getIndex()
+ || format.getFillPattern() != HSSFPatternFormatting.NO_FILL )
+ {
+ xml.append( "" );
+ }
+
+ // The cell number/date format
+ if ( !format.getDataFormatString().equals( "" ) )
+ {
+ xml.append( "" );
+ }
+ xml.append( "" );
+ }
+ else
+ {
+ xml.append( "/>" );
+ }
+ }
+ }
+
+ // -------------------------------------------------------------------------
+ // Get the merged cell's information
+ // -------------------------------------------------------------------------
+ private void writeXMLMergedDescription( Collection collectSheets )
+ throws IOException
+ {
+ // Get the Range of the Merged Cells //
+ if ( this.bWRITE_VERSION )
+ {
+ xml.append( XML_VERSION );
+ }
+
+ // Open the main Tag //
+ xml.append( MERGEDCELL_OPENTAG );
+
+ for ( Integer sheet : collectSheets )
+ {
+ writeBySheetNo( sheet );
+ }
+
+ // Close the main Tag //
+ xml.append( MERGEDCELL_CLOSETAG );
+ }
+
+ private void writeBySheetNo( int sheetNo )
+ {
+ Sheet sheet = WORKBOOK.getSheetAt( sheetNo - 1 );
+ CellRangeAddress cellRangeAddress = null;
+
+ for ( int i = 0; i < sheet.getNumMergedRegions(); i++ )
+ {
+ cellRangeAddress = sheet.getMergedRegion( i );
+
+ if ( cellRangeAddress.getFirstColumn() != cellRangeAddress.getLastColumn() )
+ {
+ xml.append( ""
+ + (cellRangeAddress.getLastColumn() - cellRangeAddress.getFirstColumn() + 1) + " | " );
+ }
+ }
+ }
+
+ private String getSimilarColor( short index )
+ {
+ if ( IndexedColors.DARK_BLUE.getIndex() == index || IndexedColors.BLUE.getIndex() == index )
+ {
+ return "blue";
+ }
+
+ if ( IndexedColors.BROWN.getIndex() == index )
+ {
+ return "brown";
+ }
+
+ return "";
+ }
+}
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/preview.js'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/preview.js 2012-11-01 02:12:05 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/preview.js 2012-11-02 04:42:01 +0000
@@ -8,7 +8,7 @@
importItemIds = new Array();
htmlStyle = ["