diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/META-INF/MANIFEST.MF b/data/org.eclipse.birt.report.data.oda.excel.ui/META-INF/MANIFEST.MF index 735ea8fedee..e3cddc259d6 100644 --- a/data/org.eclipse.birt.report.data.oda.excel.ui/META-INF/MANIFEST.MF +++ b/data/org.eclipse.birt.report.data.oda.excel.ui/META-INF/MANIFEST.MF @@ -2,13 +2,13 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin.name Bundle-SymbolicName: org.eclipse.birt.report.data.oda.excel.ui; singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 4.2.0.qualifier Bundle-Activator: org.eclipse.birt.report.data.oda.excel.ui.Activator Bundle-Vendor: Megha Nidhi Dahal Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.datatools.connectivity.oda.design.ui;bundle-version="[3.2.0,4.0.0)", - org.eclipse.birt.report.data.oda.excel + org.eclipse.birt.report.data.oda.excel;bundle-version="[4.2.0,5.0.0)" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties index f34c2b6acd9..f213e5cf1a1 100644 --- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties +++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties @@ -1,6 +1,6 @@ # #************************************************************************ -# Copyright (c) 2006, 2007 Actuate Corporation. +# Copyright (c) 2012 Actuate Corporation. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -20,7 +20,6 @@ label.selectFile=Select f&ile: label.selectworksheet=Worksheet: label.includeTypeLine=Use second line as &data type indicator. label.includeColumnNameLine = Use first line &as column name indicator. -label.dateFormat=Date Format: button.selectFolder.browse=B&rowse... button.moveUp=&Up diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java index b2aa69b8800..f5500383a3a 100644 --- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java +++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Megha Nidhi Dahal. + * Copyright (c) 2012 Megha Nidhi Dahal and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,7 +7,9 @@ * * Contributors: * Megha Nidhi Dahal - initial API and implementation and/or initial documentation + * Actuate Corporation - support of timestamp, datetime, time, and date data types *******************************************************************************/ + package org.eclipse.birt.report.data.oda.excel.ui.wizards; import java.io.File; @@ -73,7 +75,6 @@ import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; -import org.eclipse.swt.widgets.Text; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; @@ -95,15 +96,16 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements private static String originalName = Messages .getString("editor.title.originalName"); //$NON-NLS-1$ private static String dataType = Messages.getString("editor.title.type"); //$NON-NLS-1$ - private String dateFormat = ExcelODAConstants.DEFAULT_DATE_FORMAT; - - private static String[] dataTypeDisplayNames = new String[] { - Messages.getString("datatypes.decimal"), //$NON-NLS-1$ - Messages.getString("datatypes.float"), //$NON-NLS-1$ - Messages.getString("datatypes.integer"), //$NON-NLS-1$ - Messages.getString("datatypes.date"), //$NON-NLS-1$ - Messages.getString("datatypes.string"), //$NON-NLS-1$ - Messages.getString("datatypes.boolean") //$NON-NLS-1$ + + private static String[] dataTypeDisplayNames = new String[]{ + Messages.getString( "datatypes.dateTime" ), //$NON-NLS-1$ + Messages.getString( "datatypes.decimal" ), //$NON-NLS-1$ + Messages.getString( "datatypes.float" ), //$NON-NLS-1$ + Messages.getString( "datatypes.integer" ), //$NON-NLS-1$ + Messages.getString( "datatypes.date" ), //$NON-NLS-1$ + Messages.getString( "datatypes.time" ), //$NON-NLS-1$ + Messages.getString( "datatypes.string" ), //$NON-NLS-1$ + Messages.getString( "datatypes.boolean" ) //$NON-NLS-1$ }; private Map dataTypeDisplayNameMap = new HashMap(); @@ -115,7 +117,6 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements private transient ComboViewer fileViewer = null; private transient ComboViewer worksheetsCombo = null; - private transient Text dateFormatText = null; private transient List availableList = null; private transient TableViewer selectedColumnsViewer = null; private transient Button btnAdd = null; @@ -178,36 +179,39 @@ public void createPageCustomControl(Composite parent) { IHelpConstants.CONEXT_ID_DATASET_EXCEL); } - /** - * - * - */ - private void createColumnTypeMap() { - dataTypeDisplayNameMap.put(new Integer(4), - Messages.getString("datatypes.integer")); //$NON-NLS-1$ - dataTypeDisplayNameMap.put(new Integer(8), - Messages.getString("datatypes.float")); //$NON-NLS-1$ - dataTypeDisplayNameMap.put(new Integer(12), - Messages.getString("datatypes.string")); //$NON-NLS-1$ - dataTypeDisplayNameMap.put(new Integer(91), - Messages.getString("datatypes.date")); //$NON-NLS-1$ - dataTypeDisplayNameMap.put(new Integer(2), - Messages.getString("datatypes.decimal")); //$NON-NLS-1$ - dataTypeDisplayNameMap.put(new Integer(16), - Messages.getString("datatypes.boolean")); //$NON-NLS-1$ - - dataTypeValueMape.put(Messages.getString("datatypes.integer"), "INT"); //$NON-NLS-1$ //$NON-NLS-2$ - dataTypeValueMape.put(Messages.getString("datatypes.float"), //$NON-NLS-1$ - "DOUBLE"); //$NON-NLS-1$ - dataTypeValueMape.put(Messages.getString("datatypes.string"), //$NON-NLS-1$ - "STRING"); //$NON-NLS-1$ - dataTypeValueMape.put(Messages.getString("datatypes.date"), "DATE"); //$NON-NLS-1$ //$NON-NLS-2$ - dataTypeValueMape.put(Messages.getString("datatypes.decimal"), //$NON-NLS-1$ - "BIGDECIMAL"); //$NON-NLS-1$ - dataTypeValueMape.put(Messages.getString("datatypes.boolean"), //$NON-NLS-1$ - "BOOLEAN"); //$NON-NLS-1$ + private void createColumnTypeMap( ) + { + dataTypeDisplayNameMap.put( new Integer(4), + Messages.getString( "datatypes.integer" ) ); //$NON-NLS-1$ + dataTypeDisplayNameMap.put( new Integer(8), + Messages.getString( "datatypes.float" ) ); //$NON-NLS-1$ + dataTypeDisplayNameMap.put( new Integer(12), + Messages.getString( "datatypes.string" ) ); //$NON-NLS-1$ + dataTypeDisplayNameMap.put( new Integer(91), + Messages.getString( "datatypes.date" ) ); //$NON-NLS-1$ + dataTypeDisplayNameMap.put( new Integer(92), + Messages.getString( "datatypes.time" ) ); //$NON-NLS-1$ + dataTypeDisplayNameMap.put( new Integer(93), + Messages.getString( "datatypes.dateTime" ) ); //$NON-NLS-1$ + dataTypeDisplayNameMap.put( new Integer(2), + Messages.getString( "datatypes.decimal" ) ); //$NON-NLS-1$ + dataTypeDisplayNameMap.put( new Integer(16), + Messages.getString( "datatypes.boolean" ) ); //$NON-NLS-1$ + + dataTypeValueMape.put( Messages.getString( "datatypes.integer" ), "INT" ); //$NON-NLS-1$ //$NON-NLS-2$ + dataTypeValueMape.put( Messages.getString( "datatypes.float" ), //$NON-NLS-1$ + "DOUBLE" ); //$NON-NLS-1$ + dataTypeValueMape.put( Messages.getString( "datatypes.string" ), //$NON-NLS-1$ + "STRING" ); //$NON-NLS-1$ + dataTypeValueMape.put( Messages.getString( "datatypes.date" ), "DATE" ); //$NON-NLS-1$ //$NON-NLS-2$ + dataTypeValueMape.put( Messages.getString( "datatypes.time" ), "TIME" ); //$NON-NLS-1$ //$NON-NLS-2$ + dataTypeValueMape.put( Messages.getString( "datatypes.dateTime" ), //$NON-NLS-1$ + "TIMESTAMP" ); //$NON-NLS-1$ + dataTypeValueMape.put( Messages.getString( "datatypes.decimal" ), //$NON-NLS-1$ + "BIGDECIMAL" ); //$NON-NLS-1$ + dataTypeValueMape.put( Messages.getString( "datatypes.boolean" ), //$NON-NLS-1$ + "BOOLEAN" ); //$NON-NLS-1$ } - /** * * @@ -232,12 +236,7 @@ private void initializeControl() { currentSheetName = dataSetDesign.getPublicProperties().getProperty( ExcelODAConstants.CONN_WORKSHEETS_PROP); } - if (dataSetDesign.getPublicProperties() != null) { - dateFormat = dataSetDesign.getPublicProperties().getProperty( - ExcelODAConstants.CONN_DATE_FORMAT_PROP); - dateFormat = dateFormat == null ? ExcelODAConstants.DEFAULT_DATE_FORMAT : dateFormat.trim(); - dateFormatText.setText(dateFormat); - } + /* * Optionally honor the request for an editable or read-only design * session isSessionEditable(); @@ -368,17 +367,6 @@ public String getText(Object element) { data = new FormData(); data.left = new FormAttachment(worksheetsCombo.getControl(), 5); data.top = new FormAttachment(0, 5); - - label = new Label(composite, SWT.NONE); - label.setText(Messages.getString("label.dateFormat")); //$NON-NLS-1$ - label.setLayoutData(data); - - data = new FormData(); - data.left = new FormAttachment(label, 5); - data.right = new FormAttachment(100, -5); - dateFormatText = new Text(composite, SWT.BORDER); - dateFormatText.setLayoutData(data); - dateFormatText.setText(dateFormat); } /** @@ -914,10 +902,6 @@ private void loadProperties() { currentSheetName = dataSetDesign.getPublicProperties().getProperty( ExcelODAConstants.CONN_WORKSHEETS_PROP); } - if (dataSetDesign.getPublicProperties() != null) { - dateFormat = dataSetDesign.getPublicProperties().getProperty( - ExcelODAConstants.CONN_DATE_FORMAT_PROP); - } } /** @@ -1598,17 +1582,7 @@ else if (dataSetDesign.getPublicProperties() != null) { .findProperty(ExcelODAConstants.CONN_WORKSHEETS_PROP) .setNameValue(ExcelODAConstants.CONN_WORKSHEETS_PROP, currentSheetName); - if (dataSetDesign.getPublicProperties().findProperty( - ExcelODAConstants.CONN_DATE_FORMAT_PROP) != null) - dateFormat = dateFormatText.getText(); - dateFormat = dateFormat != null ? dateFormat.trim() : ExcelODAConstants.DEFAULT_DATE_FORMAT; - dataSetDesign - .getPublicProperties() - .findProperty(ExcelODAConstants.CONN_DATE_FORMAT_PROP) - .setNameValue(ExcelODAConstants.CONN_DATE_FORMAT_PROP, - dateFormat); } - } private java.util.Properties getPageProperties() { diff --git a/data/org.eclipse.birt.report.data.oda.excel/META-INF/MANIFEST.MF b/data/org.eclipse.birt.report.data.oda.excel/META-INF/MANIFEST.MF index d5bafb2c8a5..8bc78d0659e 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/META-INF/MANIFEST.MF +++ b/data/org.eclipse.birt.report.data.oda.excel/META-INF/MANIFEST.MF @@ -2,15 +2,13 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin.name Bundle-SymbolicName: org.eclipse.birt.report.data.oda.excel; singleton:=true -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 4.2.0.qualifier Bundle-ClassPath: ., src, lib/poi-3.7/poi-3.7-20101029.jar, lib/poi-3.7/poi-ooxml-3.7-20101029.jar, lib/poi-3.7/poi-ooxml-schemas-3.7-20101029.jar, - lib/poi-3.7/lib/log4j-1.2.13.jar, lib/poi-3.7/ooxml-lib/dom4j-1.6.1.jar, - lib/poi-3.7/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar, lib/poi-3.7/ooxml-lib/xmlbeans-2.3.0.jar Bundle-Activator: org.eclipse.birt.report.data.oda.excel.Activator Bundle-Vendor: Megha Nidhi Dahal @@ -24,6 +22,7 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.datatools.connectivity.oda.profile;bundle-version="[3.2.0,4.0.0)", org.apache.xerces;bundle-version="[2.9.0,3.0.0)", org.apache.xml.serializer;bundle-version="[2.7.1,3.0.0)", - org.apache.commons.logging;bundle-version="[1.0.4,2.0.0)" + org.apache.commons.logging;bundle-version="[1.0.4,2.0.0)", + javax.xml.stream;bundle-version="[1.0.1,2.0.0)";resolution:=optional Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy diff --git a/data/org.eclipse.birt.report.data.oda.excel/lib/poi-3.7/lib/log4j-1.2.13.jar b/data/org.eclipse.birt.report.data.oda.excel/lib/poi-3.7/lib/log4j-1.2.13.jar deleted file mode 100644 index dde9972109d..00000000000 Binary files a/data/org.eclipse.birt.report.data.oda.excel/lib/poi-3.7/lib/log4j-1.2.13.jar and /dev/null differ diff --git a/data/org.eclipse.birt.report.data.oda.excel/lib/poi-3.7/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar b/data/org.eclipse.birt.report.data.oda.excel/lib/poi-3.7/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar deleted file mode 100644 index 0d6d37423b2..00000000000 Binary files a/data/org.eclipse.birt.report.data.oda.excel/lib/poi-3.7/ooxml-lib/geronimo-stax-api_1.0_spec-1.0.jar and /dev/null differ diff --git a/data/org.eclipse.birt.report.data.oda.excel/plugin.xml b/data/org.eclipse.birt.report.data.oda.excel/plugin.xml index e21623ee49d..db59bda478f 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/plugin.xml +++ b/data/org.eclipse.birt.report.data.oda.excel/plugin.xml @@ -62,6 +62,14 @@ nativeDataType="DATE" nativeDataTypeCode="91" odaScalarDataType="Date"/> + + - - - - + diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/ExcelODAConstants.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/ExcelODAConstants.java index 1fb79619970..67a7a08a231 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/ExcelODAConstants.java +++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/ExcelODAConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Megha Nidhi Dahal. + * Copyright (c) 2012 Megha Nidhi Dahal and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,25 +7,24 @@ * * Contributors: * Megha Nidhi Dahal - initial API and implementation and/or initial documentation + * Actuate Corporation - support of timestamp, datetime, time, and date data types *******************************************************************************/ - package org.eclipse.birt.report.data.oda.excel; public class ExcelODAConstants { - public static final String CONN_HOME_DIR_PROP = "HOME"; - public static final String XLS_FORMAT = "xls"; - public static final String XLSX_FORMAT = "xlsx"; - public static final String CONN_INCLCOLUMNNAME_PROP = "INCLCOLUMNNAME"; - public static final String INC_COLUMN_NAME_YES = "YES"; - public static final String CONN_INCLTYPELINE_PROP = "INCLTYPELINE"; - public static final String INC_TYPE_LINE_YES = "YES"; - public static final String INC_TYPE_LINE_NO = "NO"; - public static final String INC_COLUMN_NAME_NO = "NO"; + public static final String CONN_HOME_DIR_PROP = "HOME"; //$NON-NLS-1$ + public static final String XLS_FORMAT = "xls"; //$NON-NLS-1$ + public static final String XLSX_FORMAT = "xlsx"; //$NON-NLS-1$ + public static final String CONN_INCLCOLUMNNAME_PROP = "INCLCOLUMNNAME"; //$NON-NLS-1$ + public static final String INC_COLUMN_NAME_YES = "YES"; //$NON-NLS-1$ + public static final String CONN_INCLTYPELINE_PROP = "INCLTYPELINE"; //$NON-NLS-1$ + public static final String INC_TYPE_LINE_YES = "YES"; //$NON-NLS-1$ + public static final String INC_TYPE_LINE_NO = "NO"; //$NON-NLS-1$ + public static final String INC_COLUMN_NAME_NO = "NO"; //$NON-NLS-1$ - public static final String CONN_WORKSHEETS_PROP = "WORKSHEETS"; - public static final String CONN_DATE_FORMAT_PROP = "DATEFORMAT"; + public static final String CONN_WORKSHEETS_PROP = "WORKSHEETS"; //$NON-NLS-1$ public static final String DELIMITER_SPACE = " "; //$NON-NLS-1$ public static final char DELIMITER_DOUBLEQUOTE = '"'; @@ -37,7 +36,6 @@ public class ExcelODAConstants { public static final String KEYWORD_ASTERISK = "*";//$NON-NLS-1$ public static final String KEYWORD_AS = "AS"; //$NON-NLS-1$ public static final String KEYWORD_FROM = "FROM"; //$NON-NLS-1$ - public static final String EMPTY_STRING = ""; - public static final String ALL_SHEETS = "ALL"; - public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; + public static final String EMPTY_STRING = ""; //$NON-NLS-1$ + public static final String ALL_SHEETS = "ALL"; //$NON-NLS-1$ } diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java index 8d2953c2c8d..789457cea89 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java +++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Megha Nidhi Dahal. + * Copyright (c) 2012 Megha Nidhi Dahal and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,8 @@ * * Contributors: * Megha Nidhi Dahal - initial API and implementation and/or initial documentation + * Actuate Corporation - more efficient xlsx processing; + * support of timestamp, datetime, time, and date data types *******************************************************************************/ package org.eclipse.birt.report.data.oda.excel.impl; @@ -37,14 +39,13 @@ import org.eclipse.datatools.connectivity.oda.spec.QuerySpecification; /** - * Implementation class of IQuery for an ODA runtime driver.
- * For demo purpose, the auto-generated method stubs have hard-coded - * implementation that returns a pre-defined set of meta-data and query results. - * A custom ODA driver is expected to implement own data source specific - * behavior in its place. + * Implementation class of IQuery for the Excel ODA runtime driver. */ public class ExcelFileQuery implements IQuery { + public static final int DEFAULT_MAX_ROWS_TO_READ = 10; + private int maxRows; + private int maxRowsToRead = DEFAULT_MAX_ROWS_TO_READ; private static final String NAME_LITERAL = "NAME"; //$NON-NLS-1$ private static final String TYPE_LITERAL = "TYPE"; //$NON-NLS-1$ @@ -71,7 +72,6 @@ public class ExcelFileQuery implements IQuery { private ResultSetMetaDataHelper resultSetMetaDataHelper; private String worksheetNames; - private String dateFormatString = ExcelODAConstants.DEFAULT_DATE_FORMAT; private String savedSelectedColInfo; @@ -189,8 +189,10 @@ private void validateOpenConnection() throws OdaException { * @throws OdaException */ private void prepareMetaData() throws OdaException { + // limit the number of Rows to read to optimize getting metadata + // from a xlsx file ExcelFileSource excelFileReader = new ExcelFileSource(connProperties, - currentTableName, worksheetNames, dateFormatString, 0, null, + currentTableName, worksheetNames, maxRowsToRead, null, null); String[] allColumnNames; @@ -483,9 +485,11 @@ private String getPreparedColumnNames(String[] parsedQueryFragments) { */ private String[] discoverActualColumnMetaData(String metaDataType, String tableName) throws OdaException { + // limit the number of Rows to read to optimize getting metadata + // from a xlsx file ExcelFileSource excelFileSource = new ExcelFileSource( this.connProperties, tableName, worksheetNames, - dateFormatString, 0, null, null); + maxRowsToRead, null, null); try { if (!(metaDataType.trim().equalsIgnoreCase(NAME_LITERAL) || metaDataType .trim().equalsIgnoreCase(TYPE_LITERAL))) @@ -495,12 +499,12 @@ private String[] discoverActualColumnMetaData(String metaDataType, // if want to discover type information then just skip all the empty // lines and the first line if (metaDataType.trim().equalsIgnoreCase(TYPE_LITERAL)) { - while (ExcelFileSource.isEmptyRow(excelFileSource.readLine())) + while (excelFileSource.isEmptyRow(excelFileSource.readLine())) continue; } // Skip all the empty lines until reach the first line List columnNameLine; - while (ExcelFileSource.isEmptyRow(columnNameLine = excelFileSource + while (excelFileSource.isEmptyRow(columnNameLine = excelFileSource .readLine())) continue; @@ -567,7 +571,7 @@ private void validateColumnTypeConsistency(String[] aCT) return; for (int i = 0; i < aCT.length; i++) { if (!DataTypes.isValidType(aCT[i])) { - throw new OdaException("TYPE_NAME_INVALID" + aCT[i]); //$NON-NLS-1$ + throw new OdaException( Messages.getString("dataTypes_TYPE_NAME_INVALID") + aCT[i]); //$NON-NLS-1$ } } } @@ -649,7 +653,7 @@ public IResultSet executeQuery() throws OdaException { Messages.getString("query_COMMAND_NOT_VALID")); //$NON-NLS-1$ return new ResultSet(new ExcelFileSource(this.connProperties, - this.currentTableName, worksheetNames, this.dateFormatString, + this.currentTableName, worksheetNames, this.maxRows, this.resultSetMetaData, this.resultSetMetaDataHelper), this.resultSetMetaData); } @@ -662,11 +666,6 @@ public IResultSet executeQuery() throws OdaException { public void setProperty(String name, String value) throws OdaException { if (name.equals(ExcelODAConstants.CONN_WORKSHEETS_PROP)) this.worksheetNames = value; - if (name.equals(ExcelODAConstants.CONN_DATE_FORMAT_PROP)) { - if (name == null || name.trim().equals("")) - throw new OdaException(Messages.getString("date_format_null")); - this.dateFormatString = value; - } } /* @@ -687,7 +686,6 @@ public int getMaxRows() throws OdaException { * @see org.eclipse.datatools.connectivity.oda.IQuery#clearInParameters() */ public void clearInParameters() throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -697,7 +695,6 @@ public void clearInParameters() throws OdaException { * int) */ public void setInt(String parameterName, int value) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter } @@ -705,7 +702,6 @@ public void setInt(String parameterName, int value) throws OdaException { * @see org.eclipse.datatools.connectivity.oda.IQuery#setInt(int, int) */ public void setInt(int parameterId, int value) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -716,7 +712,6 @@ public void setInt(int parameterId, int value) throws OdaException { */ public void setDouble(String parameterName, double value) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter } @@ -724,7 +719,6 @@ public void setDouble(String parameterName, double value) * @see org.eclipse.datatools.connectivity.oda.IQuery#setDouble(int, double) */ public void setDouble(int parameterId, double value) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -735,7 +729,6 @@ public void setDouble(int parameterId, double value) throws OdaException { */ public void setBigDecimal(String parameterName, BigDecimal value) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter } @@ -745,7 +738,6 @@ public void setBigDecimal(String parameterName, BigDecimal value) */ public void setBigDecimal(int parameterId, BigDecimal value) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -756,7 +748,6 @@ public void setBigDecimal(int parameterId, BigDecimal value) */ public void setString(String parameterName, String value) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter System.out.println(parameterName); } @@ -766,7 +757,6 @@ public void setString(String parameterName, String value) * java.lang.String) */ public void setString(int parameterId, String value) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter System.out.println(value); } @@ -777,7 +767,6 @@ public void setString(int parameterId, String value) throws OdaException { * java.sql.Date) */ public void setDate(String parameterName, Date value) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter } @@ -786,7 +775,6 @@ public void setDate(String parameterName, Date value) throws OdaException { * java.sql.Date) */ public void setDate(int parameterId, Date value) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -796,7 +784,6 @@ public void setDate(int parameterId, Date value) throws OdaException { * java.sql.Time) */ public void setTime(String parameterName, Time value) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter } @@ -805,7 +792,6 @@ public void setTime(String parameterName, Time value) throws OdaException { * java.sql.Time) */ public void setTime(int parameterId, Time value) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -816,7 +802,6 @@ public void setTime(int parameterId, Time value) throws OdaException { */ public void setTimestamp(String parameterName, Timestamp value) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter } @@ -826,7 +811,6 @@ public void setTimestamp(String parameterName, Timestamp value) */ public void setTimestamp(int parameterId, Timestamp value) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -839,7 +823,6 @@ public void setTimestamp(int parameterId, Timestamp value) */ public void setBoolean(String parameterName, boolean value) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter } @@ -850,7 +833,6 @@ public void setBoolean(String parameterName, boolean value) * boolean) */ public void setBoolean(int parameterId, boolean value) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -863,7 +845,6 @@ public void setBoolean(int parameterId, boolean value) throws OdaException { */ public void setObject(String parameterName, Object value) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter } @@ -874,7 +855,6 @@ public void setObject(String parameterName, Object value) * java.lang.Object) */ public void setObject(int parameterId, Object value) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -885,7 +865,6 @@ public void setObject(int parameterId, Object value) throws OdaException { * org.eclipse.datatools.connectivity.oda.IQuery#setNull(java.lang.String) */ public void setNull(String parameterName) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter } @@ -895,7 +874,6 @@ public void setNull(String parameterName) throws OdaException { * @see org.eclipse.datatools.connectivity.oda.IQuery#setNull(int) */ public void setNull(int parameterId) throws OdaException { - // TODO Auto-generated method stub // only applies to input parameter } @@ -905,7 +883,6 @@ public void setNull(int parameterId) throws OdaException { * .String) */ public int findInParameter(String parameterName) throws OdaException { - // TODO Auto-generated method stub // only applies to named input parameter return 0; } @@ -914,10 +891,6 @@ public int findInParameter(String parameterName) throws OdaException { * @see org.eclipse.datatools.connectivity.oda.IQuery#getParameterMetaData() */ public IParameterMetaData getParameterMetaData() throws OdaException { - /* - * TODO Auto-generated method stub Replace with implementation to return - * an instance based on this prepared query. - */ return new ParameterMetaData(); } @@ -969,7 +942,6 @@ public QuerySpecification getSpecification() { * org.eclipse.datatools.connectivity.oda.IQuery#getEffectiveQueryText() */ public String getEffectiveQueryText() { - // TODO Auto-generated method stub throw new UnsupportedOperationException(); } diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ResultSet.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ResultSet.java index 3cac0496132..f300f645873 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ResultSet.java +++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ResultSet.java @@ -1,14 +1,14 @@ /******************************************************************************* - * Copyright (c) 2012 Megha Nidhi Dahal. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Megha Nidhi Dahal - initial API and implementation and/or initial documentation - *******************************************************************************/ - + * Copyright (c) 2012 Megha Nidhi Dahal and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Megha Nidhi Dahal - initial API and implementation and/or initial documentation + * Actuate Corporation - support of timestamp, datetime, time, and date data types + *******************************************************************************/ package org.eclipse.birt.report.data.oda.excel.impl; @@ -16,11 +16,7 @@ import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; -import java.text.DateFormat; import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.TimeZone; import org.eclipse.birt.report.data.oda.excel.impl.i18n.Messages; import org.eclipse.birt.report.data.oda.excel.impl.util.ExcelFileSource; @@ -55,11 +51,6 @@ public class ResultSet implements IResultSet { private static ULocale JRE_DEFAULT_LOCALE = ULocale.getDefault(); - private DateFormat dateFormat; - /** The Excel epoch in milliseconds */ - final static private long EXCEL_EPOCH_MILLIS = -2209161600000L; - /** The number of milliseconds in a day */ - final static private BigDecimal MILLIS_IN_DAY = new BigDecimal(24 * 60 * 60 * 1000); /** * Constructor * @@ -72,8 +63,6 @@ public class ResultSet implements IResultSet { this.excelFileSource = excelSource; this.resultSetMetaData = rsmd; this.maxRows = this.excelFileSource.getMaxRowsToRead(this.maxRows); - this.dateFormat = new SimpleDateFormat( - this.excelFileSource.getDateFormatString()); } /* @@ -232,33 +221,49 @@ public Date getDate(String columnName) throws OdaException { /* * @see org.eclipse.datatools.connectivity.oda.IResultSet#getTime(int) */ - public Time getTime(int index) throws OdaException { - throw new UnsupportedOperationException(); + public Time getTime( int index ) throws OdaException + { + try{ + return new Time(Long.parseLong( getString( index ) )); + }catch (Exception e){ + return null; + } } /* - * @see - * org.eclipse.datatools.connectivity.oda.IResultSet#getTime(java.lang.String - * ) + * @see org.eclipse.datatools.connectivity.oda.IResultSet#getTime(java.lang.String) */ - public Time getTime(String columnName) throws OdaException { - throw new UnsupportedOperationException(); + public Time getTime( String columnName ) throws OdaException + { + try{ + return new Time(Long.parseLong( getString( columnName ) )); + }catch (Exception e){ + return null; + } } /* * @see org.eclipse.datatools.connectivity.oda.IResultSet#getTimestamp(int) */ - public Timestamp getTimestamp(int index) throws OdaException { - throw new UnsupportedOperationException(); + public Timestamp getTimestamp( int index ) throws OdaException + { + try{ + return new Timestamp(Long.parseLong( getString( index ) )); + }catch (Exception e){ + return null; + } } /* - * @see - * org.eclipse.datatools.connectivity.oda.IResultSet#getTimestamp(java.lang - * .String) + * @see org.eclipse.datatools.connectivity.oda.IResultSet#getTimestamp(java.lang.String) */ - public Timestamp getTimestamp(String columnName) throws OdaException { - throw new UnsupportedOperationException(); + public Timestamp getTimestamp( String columnName ) throws OdaException + { + try{ + return new Timestamp(Long.parseLong( getString( columnName ) )); + }catch (Exception e){ + return null; + } } /* @@ -319,7 +324,6 @@ public boolean getBoolean(String columnName) throws OdaException { * @see org.eclipse.datatools.connectivity.oda.IResultSet#getObject(int) */ public Object getObject(int index) throws OdaException { - // TODO Auto-generated method stub throw new UnsupportedOperationException(); } @@ -331,7 +335,6 @@ public Object getObject(int index) throws OdaException { * .String) */ public Object getObject(String columnName) throws OdaException { - // TODO Auto-generated method stub throw new UnsupportedOperationException(); } @@ -377,7 +380,7 @@ private int stringToInt(String stringValue) { } catch (NumberFormatException e) { try { Number number = NumberFormat - .getInstance(JRE_DEFAULT_LOCALE).parse(stringValue); + .getInstance(JRE_DEFAULT_LOCALE).parse(stringValue); if (number != null) { return number.intValue(); } @@ -403,7 +406,7 @@ private double stringToDouble(String stringValue) { } catch (NumberFormatException e) { try { Number number = NumberFormat - .getInstance(JRE_DEFAULT_LOCALE).parse(stringValue); + .getInstance(JRE_DEFAULT_LOCALE).parse(stringValue); if (number != null) { return number.doubleValue(); } @@ -429,7 +432,7 @@ private BigDecimal stringToBigDecimal(String stringValue) { } catch (NumberFormatException e) { try { Number number = NumberFormat - .getInstance(JRE_DEFAULT_LOCALE).parse(stringValue); + .getInstance(JRE_DEFAULT_LOCALE).parse(stringValue); if (number != null) { return new BigDecimal(number.toString()); } @@ -452,19 +455,13 @@ private BigDecimal stringToBigDecimal(String stringValue) { private Date stringToDate(String stringValue) throws OdaException { if (stringValue != null && stringValue.length() > 0) { - try { - java.util.Date date = dateFormat.parse(stringValue); - return new Date(date.getTime()); - } catch (ParseException e) { - try{ - return new Date (excelDateToDate(Double.parseDouble(stringValue)).getTime()); - - - } catch( Exception ex){ + try{ + //return new Date (excelDateToDate(Double.parseDouble(stringValue)).getTime()); + return new Date( Long.parseLong(stringValue) ); + } catch( Exception ex){ - throw new OdaException(Messages.getFormattedString( - "invalid_date_value", new String[] { stringValue })); - } + throw new OdaException(Messages.getFormattedString( + "invalid_date_value", new String[] { stringValue })); //$NON-NLS-1$ } } @@ -506,54 +503,4 @@ else if (stringValue.equalsIgnoreCase("false")) //$NON-NLS-1$ return Boolean.FALSE; } - - /** - * Creates a Java Date object from an Excel numeric date value - * @param number the Excel date to convert - * @return the Date object corresponding to the specified numeric Excel date - */ - public static java.util.Date excelDateToDate(double number) - { - Calendar calendar = excelDateToCalendar(number, null); - return calendar.getTime(); - } - /** - * Creates an Java Calendar object from an Excel numeric date value - * @param number the Excel date to convert - * @param tz the time-zone to use, or null for the default time-zone - * @return the Calendar object corresponding to the specified numeric date - */ - private static Calendar excelDateToCalendar(double number, TimeZone tz) - { - if (tz == null) - { - tz = TimeZone.getDefault(); - } - Calendar calendar = Calendar.getInstance(tz); - long millis = excelDateToMilliseconds(number); - millis -= calendar.getTimeZone().getOffset(millis); - calendar.setTimeInMillis(millis); - //Excel considers 1900 to be a leap year. Must correct for that. - final long dec311899 = -2209143600000L; //December 31, 1899 - final long mar011900 = -2203873200000L; //March 1, 1900 - if (millis >= dec311899 && millis < mar011900) - { - calendar.add(Calendar.DAY_OF_YEAR, 1); - } - return calendar; - } - /** - * @param number the Excel date value to convert - * @return the number of milliseconds since the 1970 (Java) epoch - */ - private static long excelDateToMilliseconds(double number) - { - long millis = (long)(number * MILLIS_IN_DAY.doubleValue()); - millis += EXCEL_EPOCH_MILLIS; - return millis; - } - - - - } \ No newline at end of file diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/i18n/messages.properties b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/i18n/messages.properties index 9f36d4c31db..082ae824e92 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/i18n/messages.properties +++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/i18n/messages.properties @@ -20,7 +20,7 @@ resultSetMetaData_INVALID_COLUMN_INDEX=Invalid column index: savedSelectedColumnsInfoString_INVALID=Invalid Saved Columns Information -dataTypes_TYPE_NAME_INVALID=Invalid type name: +dataTypes_TYPE_NAME_INVALID=Invalid data type name: dataSetMetaData_PRODUCT_NAME=Excel ODA Data Source Provider diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java index b788859f3c2..f158365e5f4 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java +++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Megha Nidhi Dahal. + * Copyright (c) 2012 Megha Nidhi Dahal and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,7 +7,10 @@ * * Contributors: * Megha Nidhi Dahal - initial API and implementation and/or initial documentation + * Actuate Corporation - more efficient xlsx processing; + * support of timestamp, datetime, time, and date data types *******************************************************************************/ + package org.eclipse.birt.report.data.oda.excel.impl.util; import java.io.File; @@ -15,6 +18,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; +import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -49,6 +53,7 @@ public class ExcelFileReader { private int maxRowsInThisSheet; private int currentRowIndex = 0; private int maxColumnIndex = 0; + private int xlsxRowsToRead; private XlsxRowCallBack callback; private XlsxFileReader xlsxread; Map xlsxSheetRidNameMap; @@ -58,10 +63,11 @@ public void setMaxColumnIndex(int maxColumnIndex) { } public ExcelFileReader(FileInputStream fis, String fileExtension, - List sheetNameList, String dateFormatString) { + List sheetNameList, int rowsToRead) { this.fis = fis; this.fileExtension = fileExtension; this.workSheetList = sheetNameList; + this.xlsxRowsToRead = rowsToRead; } public List readLine() throws IOException, OdaException { @@ -107,17 +113,17 @@ private void initialise() throws IOException, OdaException { callback = new XlsxRowCallBack(); xlsxSheetRidNameMap = xlsxread.getSheetNames(); String rid = xlsxSheetRidNameMap.get(workSheetList.get(currentSheetIndex)); - xlsxread.processSheet(rid, callback); + xlsxread.processSheet(rid, callback, this.xlsxRowsToRead); maxRowsInThisSheet = callback.getMaxRowsInSheet(); for (String sheetName : workSheetList) { rid = xlsxSheetRidNameMap.get(sheetName); if (rid == null) throw new OdaException( - Messages.getString("invalid_sheet_name")); + Messages.getString("invalid_sheet_name")); //$NON-NLS-1$ XlsxRowCallBack newCallback = new XlsxRowCallBack(); - xlsxread.processSheet(rid, newCallback); + xlsxread.processSheet(rid, newCallback, this.xlsxRowsToRead); maxRowsInAllSheet += newCallback.getMaxRowsInSheet(); } @@ -141,7 +147,12 @@ private void initialise() throws IOException, OdaException { } catch (OpenXML4JException e) { throw new OdaException(e); } catch (SAXException e) { - throw new OdaException(e); + if( e.getMessage().equalsIgnoreCase( XlsxFileReader.ROW_LIMIT_REACHED_EX_MSG ) ){ + maxRowsInThisSheet = callback.getMaxRowsInSheet(); + isInitialised = true; + }else{ + throw new OdaException(e); + } } } @@ -153,7 +164,7 @@ private boolean initialiseNextSheet() throws IOException, OdaException { try { String rid = xlsxSheetRidNameMap.get(workSheetList.get(currentSheetIndex)); callback = new XlsxRowCallBack(); - xlsxread.processSheet(rid, callback); + xlsxread.processSheet(rid, callback,this.xlsxRowsToRead); maxRowsInThisSheet = callback.getMaxRowsInSheet(); } catch (OpenXML4JException e) { throw new OdaException(e); @@ -187,10 +198,11 @@ public String getCellValue(Cell cell) { } if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { - /*if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) { - Date date = cell.getDateCellValue(); - return dateFormat.format(date); - }*/ + if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) { + Date myjavadate = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(cell.getNumericCellValue()); + long millis = myjavadate.getTime(); + return Long.toString(millis); + } return ((Double) cell.getNumericCellValue()).toString(); } @@ -201,15 +213,20 @@ private String resolveFormula(Cell cell) { if (formulaEvaluator == null) return cell.toString(); + if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell) ){ + //need to check for nulls + //double myexdate = org.apache.poi.ss.usermodel.DateUtil.getExcelDate(cell.getDateCellValue()); + Date myjavadate = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(cell.getNumericCellValue()); + long millis = myjavadate.getTime(); + return Long.toString(millis); + + } + switch (formulaEvaluator.evaluateFormulaCell(cell)) { case Cell.CELL_TYPE_BOOLEAN: return ((Boolean) cell.getBooleanCellValue()).toString(); case Cell.CELL_TYPE_NUMERIC: - /*if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) { - Date date = cell.getDateCellValue(); - return dateFormat.format(date); - }*/ return ((Double) cell.getNumericCellValue()).toString(); case Cell.CELL_TYPE_STRING: @@ -228,7 +245,7 @@ public int getMaxRows() throws IOException, OdaException { public static List getSheetNamesInExcelFile(File file) { String extension = file.getName(); - extension = extension.substring(extension.lastIndexOf(".") + 1, + extension = extension.substring(extension.lastIndexOf(".") + 1, //$NON-NLS-1$ extension.length()); FileInputStream fis; List sheetNames = new ArrayList(); diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java index b59584d8e95..a9deb5fcb4b 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java +++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Megha Nidhi Dahal. + * Copyright (c) 2012 Megha Nidhi Dahal and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,7 +7,10 @@ * * Contributors: * Megha Nidhi Dahal - initial API and implementation and/or initial documentation + * Actuate Corporation - more efficient xlsx processing; + * support of timestamp, datetime, time, and date data types *******************************************************************************/ + package org.eclipse.birt.report.data.oda.excel.impl.util; import java.io.File; @@ -45,11 +48,6 @@ public class ExcelFileSource { private String[] originalColumnNames; private boolean isFirstTimeToReadSourceData = true; private List nextDataLine; - private String dateFormatString; - - public String getDateFormatString() { - return dateFormatString; - } /** * Constructor @@ -58,7 +56,6 @@ public String getDateFormatString() { * Connection properties * @param currentTableName * The current table name of this connection - * @param dateFormatString * @param statementMaxRows * The max number of rows specified in the query * @param rsmd @@ -68,14 +65,14 @@ public String getDateFormatString() { * @throws OdaException */ public ExcelFileSource(Properties connProperties, String currentTableName, - String workSheetNames, String dateFormatString, + String workSheetNames, int statementMaxRows, IResultSetMetaData rsmd, ResultSetMetaDataHelper rsmdHelper) throws OdaException { this.rsmd = rsmd; this.rsmdHelper = rsmdHelper; this.statementMaxRows = statementMaxRows; this.currentTableName = currentTableName; - this.dateFormatString = dateFormatString; + this.fileExtension = extractFileExtension(currentTableName); Properties properties = getCopyOfConnectionProperties(connProperties); populateHomeDir(properties); @@ -184,10 +181,11 @@ public int getColumnCount() throws OdaException { try { String dataFilePath = findDataFileAbsolutePath(); FileInputStream fis = new FileInputStream(dataFilePath); - ExcelFileReader excelreader = new ExcelFileReader(fis, - fileExtension, sheetNameList, dateFormatString); + //ExcelFileReader excelreader = new ExcelFileReader(fis, + // fileExtension, sheetNameList); + initialiseReader(); List columnLine; - while (isEmptyRow(columnLine = excelreader.readLine())) { + while (isEmptyRow(columnLine = this.excelFileReader.readLine())) { continue; } count = columnLine.size(); @@ -213,8 +211,8 @@ public String findDataFileAbsolutePath() throws OdaException { File file = new File(this.homeDir + File.separator + this.currentTableName.trim()); if (!file.exists()) - throw new OdaException(Messages.getString("query_invalidTableName") - + this.homeDir + File.separator + this.currentTableName); //$NON-NLS-1$ + throw new OdaException(Messages.getString("query_invalidTableName") //$NON-NLS-1$ + + this.homeDir + File.separator + this.currentTableName); return file.getAbsolutePath(); } @@ -424,8 +422,7 @@ private void initialiseReader() throws OdaException, IOException { if (this.excelFileReader == null) { String dataFilePath = findDataFileAbsolutePath(); this.excelFileReader = new ExcelFileReader(new FileInputStream( - dataFilePath), this.fileExtension, this.sheetNameList, - dateFormatString); + dataFilePath), this.fileExtension, this.sheetNameList, this.statementMaxRows); } } catch (IOException e) { @@ -471,7 +468,7 @@ public static String[] getStringArrayFromList(List list) { * @return * @throws OdaException */ - public static boolean isEmptyRow(List line) throws OdaException { + public boolean isEmptyRow(List line) throws OdaException { if (line == null) throw new OdaException( Messages.getString("query_INVALID_EXCEL_FILE")); //$NON-NLS-1$ diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/XlsxFileReader.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/XlsxFileReader.java index 15a23c76675..333755b4748 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/XlsxFileReader.java +++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/XlsxFileReader.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Megha Nidhi Dahal. + * Copyright (c) 2012 Megha Nidhi Dahal and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,20 +7,27 @@ * * Contributors: * Megha Nidhi Dahal - initial API and implementation and/or initial documentation + * Actuate Corporation - more efficient xlsx processing; + * support of timestamp, datetime, time, and date data types *******************************************************************************/ + package org.eclipse.birt.report.data.oda.excel.impl.util; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Date; import java.util.LinkedHashMap; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.ss.usermodel.BuiltinFormats; import org.apache.poi.xssf.eventusermodel.XSSFReader; import org.apache.poi.xssf.model.SharedStringsTable; +import org.apache.poi.xssf.model.StylesTable; +import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFRichTextString; import org.eclipse.birt.report.data.oda.excel.ExcelODAConstants; import org.xml.sax.Attributes; @@ -32,7 +39,21 @@ import org.xml.sax.helpers.XMLReaderFactory; public class XlsxFileReader { - final private XSSFReader reader; + final static String PARSER_CLASS_NAME = "org.apache.xerces.parsers.SAXParser"; //$NON-NLS-1$ + final static String ROW_LIMIT_REACHED_EX_MSG = "Row Limit Reached"; //$NON-NLS-1$ + + final private XSSFReader reader; + + enum cDataType { + BOOL, + DATE, + DATETIME, + FORMULA, + SSTINDEX, + TIME, + NUMBER, + STATIC + } public XlsxFileReader(FileInputStream fis) throws IOException, OpenXML4JException { @@ -55,10 +76,12 @@ public LinkedHashMap getSheetNames() return sheetMap; } - public void processSheet(String rid, RowCallBack callback) + public void processSheet(String rid, XlsxRowCallBack callback, int xlsxRowsToRead) throws InvalidFormatException, IOException, SAXException { SharedStringsTable sst = reader.getSharedStringsTable(); - XMLReader parser = fetchSheetParser(sst, callback); + StylesTable st = reader.getStylesTable(); + + XMLReader parser = fetchSheetParser(st, sst, callback, xlsxRowsToRead); InputStream sheet = reader.getSheet(rid); try { InputSource sheetSource = new InputSource(sheet); @@ -69,11 +92,11 @@ public void processSheet(String rid, RowCallBack callback) } } - private XMLReader fetchSheetParser(SharedStringsTable sst, - RowCallBack callback) throws SAXException { + private XMLReader fetchSheetParser(StylesTable st, SharedStringsTable sst, + XlsxRowCallBack callback, int xlsxRowsToRead) throws SAXException { XMLReader parser = XMLReaderFactory - .createXMLReader("org.apache.xerces.parsers.SAXParser"); - ContentHandler handler = new SheetHandler(sst, callback); + .createXMLReader( PARSER_CLASS_NAME ); + ContentHandler handler = new SheetHandler(st, sst, callback, xlsxRowsToRead); parser.setContentHandler(handler); return parser; } @@ -81,7 +104,7 @@ private XMLReader fetchSheetParser(SharedStringsTable sst, private XMLReader fetchWorkbookParser(LinkedHashMap sheetMap) throws SAXException { XMLReader parser = XMLReaderFactory - .createXMLReader("org.apache.xerces.parsers.SAXParser"); + .createXMLReader( PARSER_CLASS_NAME ); ContentHandler handler = new WorkbookHandler(sheetMap); parser.setContentHandler(handler); return parser; @@ -91,45 +114,85 @@ private XMLReader fetchWorkbookParser(LinkedHashMap sheetMap) * See org.xml.sax.helpers.DefaultHandler javadocs */ private static class SheetHandler extends DefaultHandler { - static private enum CellType { - non, num, staticText, sharedText - }; + private cDataType cellDataType; + private int columnCount =1; final private SharedStringsTable sst; - final private RowCallBack callback; + final private StylesTable st; + final private XlsxRowCallBack callback; private String lastContents; - private CellType cellType; private ArrayList values; - private int currentIdx = -1; + private int currentColumn = 0; + private int xlsxRowsToRead=0; + private int currentXlsxRowNumber = 0; - private SheetHandler(SharedStringsTable sst, RowCallBack callback) { + private SheetHandler(StylesTable st, SharedStringsTable sst, XlsxRowCallBack callback, int xlsxRowsToRead) { this.sst = sst; + this.st = st; this.callback = callback; values = new ArrayList(); + this.cellDataType = cDataType.NUMBER; + this.xlsxRowsToRead = xlsxRowsToRead; } public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - // c => cell if (qName.equals("c")) { - // Figure out if the value is an index in the SST - String type = attributes.getValue("t"); - if (type == null) { - cellType = CellType.num; - } else if (type.equals("s")) { - cellType = CellType.sharedText; - } else if (type.equals("str")) { - cellType = CellType.staticText; - } else { - cellType = CellType.non; - } - currentIdx++; - values.add(currentIdx, ExcelODAConstants.EMPTY_STRING); + String vCellType = attributes.getValue("t"); + String cellS = attributes.getValue("s"); + if ("b".equals(vCellType)) + cellDataType = cDataType.BOOL; + else if ("e".equals(vCellType)) + cellDataType = cDataType.FORMULA; + else if ("s".equals(vCellType)) + cellDataType = cDataType.SSTINDEX; + else if("str".equals(vCellType)) + cellDataType = cDataType.STATIC; + else if (cellS != null) { + //number with formatting or date + int styleIndex = Integer.parseInt(cellS); + XSSFCellStyle style = st.getStyleAt(styleIndex); + short formatIndex = style.getDataFormat(); + String formatString = style.getDataFormatString(); + + if (formatString == null) + formatString = BuiltinFormats.getBuiltinFormat(formatIndex); + + if( org.apache.poi.ss.usermodel.DateUtil.isADateFormat(formatIndex, formatString) ){ + cellDataType = cDataType.DATETIME; + }else{ + cellDataType = cDataType.NUMBER; + } + } + else + cellDataType = cDataType.NUMBER; + + String r = attributes.getValue("r"); + + currentColumn = getColumnNumber( r ); + //expand the number of columns if needed in existing rows + if( currentColumn+1 > columnCount){ + callback.columnExpansion(currentColumn+1); + + //clean up current row + int newvals = (currentColumn+1) - columnCount; + for( int ii=0; ii 0 ){ + if( currentXlsxRowNumber > xlsxRowsToRead){ + throw new SAXException( ROW_LIMIT_REACHED_EX_MSG ); + } + } return; } else if (name.equals("c")) { - cellType = CellType.non; + cellDataType = cDataType.NUMBER; return; } else if (name.equals("v")) { - String val = null; + String val = ExcelODAConstants.EMPTY_STRING; // Process the last contents as required. // Do now, as characters() may be called more than once - if (cellType == CellType.sharedText) { + if (cellDataType == cDataType.SSTINDEX) { int idx; idx = Integer.parseInt(lastContents); val = new XSSFRichTextString(sst.getEntryAt(idx)) .toString(); - } else if (cellType == CellType.staticText - || cellType == CellType.num) { + } else if (cellDataType == cDataType.STATIC + || cellDataType == cDataType.NUMBER) { val = lastContents; + }else if( cellDataType == cDataType.DATETIME || cellDataType == cDataType.DATE || cellDataType == cDataType.TIME ){ + + Date myjavadate = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(Double.parseDouble(lastContents)); + long millis = myjavadate.getTime(); + val = Long.toString(millis); + }else if( cellDataType == cDataType.BOOL ){ + if( lastContents.compareTo("1") == 0){ + Boolean mybool = new Boolean(true); + val = mybool.toString(); + }else if( lastContents.compareTo("0") == 0 ){ + Boolean mybool = new Boolean(false); + val = mybool.toString(); + } } // v => contents of a cell if (val != null) { - values.remove(currentIdx); - values.add(currentIdx, val); + if( currentColumn != -1){ + values.remove(currentColumn); + values.add(currentColumn, val); + } } } } @@ -169,6 +254,19 @@ public void characters(char[] ch, int start, int length) throws SAXException { lastContents += new String(ch, start, length); } + + private int getColumnNumber(String colname) { + + int tmpcol = 0; + + //remove cell number + for (int ch = 0; ch < colname.length(); ++ch) { + if( Character.isLetter(colname.charAt(ch)) ){ + tmpcol = (ch*26) + colname.charAt(ch) - 'A'; + } + } + return tmpcol; + } } /** @@ -192,23 +290,4 @@ public void startElement(String uri, String localName, String qName, } } - /* - * public static void main(String[] args) throws Exception { // String - * xlsxFileName = "test.xlsx"; String xlsxFileName = - * "c:/work/styles/LargeXls.xlsx"; FileInputStream fis = new - * FileInputStream(xlsxFileName); XlsxFileReader poiTest = new - * XlsxFileReader(fis); - * - * LinkedHashMap sheetMap = poiTest.getSheetNames(); - * - * XlsxRowCallback callback = new XlsxRowCallback(); String rid = - * sheetMap.get("Data"); poiTest.processSheet(rid, callback); - * - * - * for (String sheetName : sheetMap.keySet()) { String rid = - * sheetMap.get(sheetName); poiTest.processOneSheet(rid, callback); } - * - * } - */ - } diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/XlsxRowCallBack.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/XlsxRowCallBack.java index 290069a38c8..9b8eca93146 100644 --- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/XlsxRowCallBack.java +++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/XlsxRowCallBack.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Megha Nidhi Dahal. + * Copyright (c) 2012 Megha Nidhi Dahal and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,12 +7,17 @@ * * Contributors: * Megha Nidhi Dahal - initial API and implementation and/or initial documentation + * Actuate Corporation - more efficient xlsx processing; + * support of timestamp, datetime, time, and date data types *******************************************************************************/ + package org.eclipse.birt.report.data.oda.excel.impl.util; import java.util.ArrayList; import java.util.List; +import org.eclipse.birt.report.data.oda.excel.ExcelODAConstants; + public class XlsxRowCallBack implements RowCallBack { private ArrayList xlsxRowData = new ArrayList(); private int rowNum; @@ -25,10 +30,19 @@ public void handleRow(List values) { } String[] valArray = new String[values.size()]; values.toArray(valArray); + if( rowNum == 1 ){ + for( int i=0; i initArrayList(String[] strings) { ArrayList list = new ArrayList(); for (String i : strings) { @@ -44,4 +58,28 @@ public int getMaxRowsInSheet() { public ArrayList getRow(int rownum) { return (initArrayList(xlsxRowData.get(rownum))); } + + // Need this function because there is no easy way of determining the number of columns in xlsx with SAX Parser. + // This function expands all the previous data rows with blanks. + public void columnExpansion(int newColumnCount){ + for(int i=0;i