summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpshi2012-04-24 04:24:33 (EDT)
committer xgu2012-05-03 04:48:46 (EDT)
commit622db0861a841295f93633fbdb0e727f798359b3 (patch)
tree8e8dd77ad1462d1f443914ec7cb4c40cac2efcb7
parenta556cff5c56903496a8fa91f436cef3f609f4d04 (diff)
downloadorg.eclipse.birt-622db0861a841295f93633fbdb0e727f798359b3.zip
org.eclipse.birt-622db0861a841295f93633fbdb0e727f798359b3.tar.gz
org.eclipse.birt-622db0861a841295f93633fbdb0e727f798359b3.tar.bz2
fix 48202 Summary:Support Relative File Path for the input file in Excel ODA Designer Description:support defining data source using file and URI. code review: bin feng
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/i18n/messages.properties4
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java54
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelFileSelectionWizardPage.java138
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFileSelectionDialog.java (renamed from data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFolderSelectionDialog.java)44
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/plugin.properties2
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/plugin.xml4
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/ExcelODAConstants.java4
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java11
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/ExcelFileQuery.java17
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/i18n/messages.properties2
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileReader.java86
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ExcelFileSource.java92
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ResourceLocatorUtil.java60
-rw-r--r--data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/XlsxFileReader.java4
14 files changed, 328 insertions, 194 deletions
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 a8b22e8..27f6a07 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
@@ -8,10 +8,11 @@
#
# Contributors:
# Actuate Corporation - initial API and implementation
-#
+# Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
#************************************************************************
#
wizard.defaultMessage.selectFolder=Select the folder that contains Excel data source file(s).
+wizard.defaultMessage.selectExcelFile=Select the excel data source file or URI.
wizard.defaultMessage.selectFile=Select the file, worksheet and the columns for the data set.
connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR=Unable to open Excel data source file in selected folder.
ui.ExcelFileNotFound=Unable to locate the specified Excel data source file or folder
@@ -56,6 +57,7 @@ error.invalidConnectionFilePath=The specified connection profile source path, "{
# error.invalidExcelFilePath=Invalid Excel data source folder path.
error.errorExist=Error exists in the current page. Would you like to save it anyway?
error.noFiles=The folder, "{0}", does not have any specified files in it.
+error.noFile=The file, "{0}", dose not exist.
error.invalidFilePath=The file path is invalid. Would you like to continue?
error.emptyFilePath=The file path is empty. Would you like to continue?
error.duplicatedNameValueOrEmpty=Duplicated Name Value or Empty
diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java
index e55cd4f..3c77d78 100644
--- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java
+++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/ExcelDataSourcePageHelper.java
@@ -8,6 +8,7 @@
* Contributors:
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
* Actuate Corporation - added support of relative file path
+ * Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.ui.wizards;
@@ -21,7 +22,6 @@ import org.eclipse.birt.report.data.oda.excel.impl.util.ResourceLocatorUtil;
import org.eclipse.birt.report.data.oda.excel.ui.i18n.Messages;
import org.eclipse.birt.report.data.oda.excel.ui.util.IHelpConstants;
import org.eclipse.birt.report.data.oda.excel.ui.util.Utility;
-import org.eclipse.birt.report.data.oda.excel.ui.wizards.ExcelFileSelectionWizardPage.ExcelFileFilter;
import org.eclipse.datatools.connectivity.IConnection;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.oda.OdaException;
@@ -43,7 +43,7 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
@@ -52,7 +52,7 @@ import org.eclipse.swt.widgets.Text;
public class ExcelDataSourcePageHelper {
static final String DEFAULT_MESSAGE = Messages
- .getString("wizard.defaultMessage.selectFolder"); //$NON-NLS-1$
+ .getString("wizard.defaultMessage.selectExcelFile"); //$NON-NLS-1$
private WizardPage wizardPage;
private PreferencePage propertyPage;
@@ -73,8 +73,15 @@ public class ExcelDataSourcePageHelper {
private static final Integer SELECT_RELATIVE_PATH = 1;
private static final Integer SELECT_ABSOLUTE_PATH = 2;
+ private static final String ALL_XLSX_EXTENSION = "*.xlsx"; //$NON-NLS-1$
+ private static final String ALL_XLS_EXTENSION = "*.xls"; //$NON-NLS-1$
+ private static final String ALL_EXTENSION = "*.*";
+
private ResourceIdentifiers ri;
+ private static final String[] fileExtensions = new String[]{
+ ALL_XLS_EXTENSION, ALL_XLSX_EXTENSION, ALL_EXTENSION};
+
public ExcelDataSourcePageHelper(ExcelDataSourceWizardPage page) {
wizardPage = page;
}
@@ -107,7 +114,7 @@ public class ExcelDataSourcePageHelper {
private void setupFolderLocation(Composite composite) {
Label label = new Label(composite, SWT.NONE);
- label.setText(Messages.getString("label.selectFolder")); //$NON-NLS-1$
+ label.setText(Messages.getString("label.selectFile")); //$NON-NLS-1$
GridData data = new GridData(GridData.FILL_HORIZONTAL);
@@ -189,8 +196,9 @@ public class ExcelDataSourcePageHelper {
{
if ( selectionType == SELECT_RELATIVE_PATH )
{
- RelativeFolderSelectionDialog dialog = new RelativeFolderSelectionDialog( folderLocation.getShell( ),
+ RelativeFileSelectionDialog dialog = new RelativeFileSelectionDialog( folderLocation.getShell( ),
new File( getResourceFolder( ) ) );
+
if ( dialog.open( ) == Window.OK )
{
try
@@ -215,7 +223,8 @@ public class ExcelDataSourcePageHelper {
}
else if ( selectionType == SELECT_ABSOLUTE_PATH )
{
- DirectoryDialog dialog = new DirectoryDialog( folderLocation.getShell( ) );
+ FileDialog dialog = new FileDialog( folderLocation.getShell( ) );
+ dialog.setFilterExtensions( fileExtensions );
String folderLocationValue = getFolderLocationString( );
if ( folderLocationValue != null
&& folderLocationValue.trim( ).length( ) > 0 )
@@ -223,7 +232,6 @@ public class ExcelDataSourcePageHelper {
dialog.setFilterPath( folderLocationValue );
}
- dialog.setMessage( DEFAULT_MESSAGE );
String selectedLocation = dialog.open( );
if ( selectedLocation != null )
{
@@ -291,7 +299,7 @@ public class ExcelDataSourcePageHelper {
props = new Properties();
// set custom driver specific properties
- props.setProperty(ExcelODAConstants.CONN_HOME_DIR_PROP,
+ props.setProperty(ExcelODAConstants.CONN_FILE_URI_PROP,
getFolderLocation().trim());
props.setProperty(ExcelODAConstants.CONN_INCLCOLUMNNAME_PROP,
getWhetherUseFirstLineAsColumnNameLine());
@@ -344,7 +352,7 @@ public class ExcelDataSourcePageHelper {
return; // nothing to initialize
String folderPath = profileProps
- .getProperty(ExcelODAConstants.CONN_HOME_DIR_PROP);
+ .getProperty(ExcelODAConstants.CONN_FILE_URI_PROP);
if (folderPath == null)
folderPath = EMPTY_STRING;
setFolderLocationString(folderPath);
@@ -455,31 +463,17 @@ public class ExcelDataSourcePageHelper {
setPageComplete( false );
return ERROR_FOLDER;
}
- File f = new File( uri );
- if ( f.exists( ) )
+ try
{
- if ( f.isDirectory( ) )
- {
- File[] files = f.getAbsoluteFile( )
- .listFiles( new ExcelFileFilter( ) );
- if ( files.length == 0 )
- {
- setMessage( Messages.getString( "error.emptyFolder" ), IMessageProvider.ERROR ); //$NON-NLS-1$
- setPageComplete( false );
- result = ERROR_FOLDER;
- }
- else
- {
- setMessage( DEFAULT_MESSAGE, IMessageProvider.NONE );
- setPageComplete( true );
- }
- }
+ ResourceLocatorUtil.validateFileURI( uri );
+ setMessage( DEFAULT_MESSAGE, IMessageProvider.NONE );
+ setPageComplete( true );
}
- else
+ catch ( Exception e )
{
- setMessage( Messages.getString( "error.selectFolder" ), IMessageProvider.ERROR ); //$NON-NLS-1$
+ setMessage( Messages.getString( "ui.ExcelFileNotFound" ), IMessageProvider.ERROR ); //$NON-NLS-1$
setPageComplete( false );
- result = ERROR_FOLDER;
+ return ERROR_FOLDER;
}
}
else {
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 d62e718..0e77929 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
@@ -9,12 +9,14 @@
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
* Actuate Corporation - support of timestamp, datetime, time, and date data types
* Actuate Corporation - added support of relative file path
+ * Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.ui.wizards;
import java.io.File;
import java.io.FilenameFilter;
+import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
@@ -127,13 +129,13 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
private transient Button btnMoveUp = null;
private transient Button btnMoveDown = null;
- private String odaHome;
+ private String uriPath;
private String inclColumnNameLine;
private String inclTypeLine;
private String savedSelectedColumnsInfoString;
/** store latest selected file */
- private File selectedFile;
+ private Object selectedFile;
/** store latest selected sheet name */
private String currentSheetName;
@@ -330,7 +332,7 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
fileViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
- File file = (File) ((IStructuredSelection) event.getSelection())
+ Object file = ((IStructuredSelection) event.getSelection())
.getFirstElement();
if (file.equals(selectedFile))
@@ -341,12 +343,17 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
selectedFile = file;
isNewFile = true;
- populateWorkSheetCombo();
+ try {
+ populateWorkSheetCombo();
+ } catch (Exception e) {
+ setMessage(Messages.getString("ui.ExcelFileNotFound"), //$NON-NLS-1$
+ ERROR);
+ }
}
});
fileViewer.setLabelProvider(new LabelProvider() {
public String getText(Object element) {
- return ((File) element).getName();
+ return getFileName( element );
}
});
@@ -813,6 +820,13 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
}
}
+ private String getFileName( Object obj )
+ {
+ if ( obj instanceof File )
+ return ( (File) obj ).getName( );
+ return obj.toString( );
+ }
+
/*
* File Combo Viewer selection changed listener
*
@@ -844,7 +858,7 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
availableList.removeAll();
nameOfFileWithErrorInLastAccess = null;
- String fileName = selectedFile.getName();
+ String fileName = getFileName( selectedFile );
String[] columnNames = getFileColumnNames(selectedFile);
if (columnNames != null && columnNames.length != 0) {
@@ -877,8 +891,8 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
return;
}
- odaHome = dataSourceProps
- .getProperty(ExcelODAConstants.CONN_HOME_DIR_PROP);
+ uriPath = dataSourceProps
+ .getProperty(ExcelODAConstants.CONN_FILE_URI_PROP);
inclColumnNameLine = dataSourceProps
.getProperty(ExcelODAConstants.CONN_INCLCOLUMNNAME_PROP);
inclTypeLine = dataSourceProps
@@ -915,66 +929,71 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
*/
private void updateFileList() {
if (fileViewer != null && !fileViewer.getControl().isDisposed()) {
- if (odaHome == null) {
+ if (uriPath == null) {
disableAll();
return;
}
+ ArrayList<Object> allFiles = new ArrayList<Object>( );
URI uri = null;
try
{
ResourceIdentifiers ri = DesignSessionUtil.createRuntimeResourceIdentifiers( getHostResourceIdentifiers( ) );
- uri = ResourceLocatorUtil.resolvePath( ri, odaHome );
+ uri = ResourceLocatorUtil.resolvePath( ri, uriPath );
}
catch ( OdaException e )
{
- setMessage( Messages.getString("ui.ExcelFileNotFound") + odaHome + //$NON-NLS-1$
+ setMessage( Messages.getString("ui.ExcelFileNotFound") + uri + //$NON-NLS-1$
"; " + e.getLocalizedMessage()); //$NON-NLS-1$
disableAll( );
return;
}
if (uri == null)
{
- setMessage(Messages.getString("ui.ExcelFileNotFound") + odaHome ); //$NON-NLS-1$
+ setMessage(Messages.getString("ui.ExcelFileNotFound") + uri ); //$NON-NLS-1$
disableAll();
return;
}
-
- File folder = new File(uri);
- if (folder.isDirectory() && folder.exists()) {
- File[] files = folder.getAbsoluteFile().listFiles(
- new ExcelFileFilter());
-
- if (files != null) {
- fileViewer.setInput(files);
- } else {
- fileViewer.setInput(new File[] {});
- }
- } else {
- fileViewer.setInput(new File[] {});
+ try
+ {
+ ResourceLocatorUtil.validateFileURI( uri );
+ allFiles.add( uri );
}
- File[] files = (File[]) fileViewer.getInput();
- if (files.length > 0) {
+ catch (Exception ignore)
+ {
+ }
+
+ fileViewer.setInput( allFiles );
+ ArrayList<Object> files = (ArrayList<Object>) fileViewer.getInput( );
+ if (files.size() > 0) {
enableListAndViewer();
- File toSelectFile = null;
+ Object toSelectFile = null;
if (selectedFile != null)
- for (int i = 0; i < files.length; i++) {
- if (files[i].equals(selectedFile)) {
+ for (int i = 0; i < files.size(); i++) {
+ if (files.get(i).equals(selectedFile)) {
toSelectFile = selectedFile;
break;
}
}
if (toSelectFile == null)
- toSelectFile = files[0];
+ toSelectFile = files.get(0);
fileViewer.setSelection(new StructuredSelection(toSelectFile));
if (!(nameOfFileWithErrorInLastAccess != null && nameOfFileWithErrorInLastAccess
.equals(fileViewer.getCombo().getText())))
setMessage(DEFAULT_MESSAGE);
+
+ String extension = ExcelFileReader.getExtensionName( uri );
+ if (extension.equals( ExcelODAConstants.XLS_FORMAT ) || extension
+ .equals( ExcelODAConstants.XLSX_FORMAT )) {
+ setMessage(DEFAULT_MESSAGE);
+ } else
+ setMessage(Messages.getString("warning.fileExtensionInvalid"), //$NON-NLS-1$
+ ERROR);
} else {
setMessage(Messages
.getFormattedString(
- "error.noFiles", new Object[] { folder.getAbsolutePath() })); //$NON-NLS-1$
+ "error.noFile", new Object[] { uri.toString( ) })); //$NON-NLS-1$
disableAll();
}
}
@@ -986,9 +1005,9 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
* @param file
* @return
*/
- private String[] getFileColumnNames(File file) {
+ private String[] getFileColumnNames(Object file) {
java.util.List<String[]> propList = getQueryColumnsInfo(
- "select * from " + QueryTextUtil.getQuotedName(file.getName()), file, currentSheetName); //$NON-NLS-1$
+ "select * from " + QueryTextUtil.getQuotedName(getFileName(file)), file, currentSheetName); //$NON-NLS-1$
String[] result;
if (propList != null) {
@@ -1009,7 +1028,7 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
* @return
*/
private java.util.List<String[]> getQueryColumnsInfo(String queryText,
- File file, String sheetName) {
+ Object file, String sheetName) {
IDriver excelDriver = new Driver();
IConnection conn = null;
java.util.List<String[]> columnList = new ArrayList<String[]>();
@@ -1150,14 +1169,22 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
* @throws OdaException
*/
private IResultSetMetaData getResultSetMetaData(String queryText,
- File file, IConnection conn, String sheetName) throws OdaException {
+ Object file, IConnection conn, String sheetName) throws OdaException {
java.util.Properties prop = new java.util.Properties();
if (file != null) {
- if (file.getParent() == null) {
- throw new OdaException(
- Messages.getString("error.unexpectedError")); //$NON-NLS-1$
+ if (file instanceof File)
+ {
+ if (((File)file).getParent() == null) {
+ throw new OdaException(
+ Messages.getString("error.unexpectedError")); //$NON-NLS-1$
+ }
+ prop.put(ExcelODAConstants.CONN_FILE_URI_PROP, ((File)file).getAbsolutePath());
+ }
+
+ else if (file instanceof URI)
+ {
+ prop.put(ExcelODAConstants.CONN_FILE_URI_PROP, file.toString());
}
- prop.put(ExcelODAConstants.CONN_HOME_DIR_PROP, file.getParent());
}
if (inclColumnNameLine != null) {
prop.put(ExcelODAConstants.CONN_INCLCOLUMNNAME_PROP,
@@ -1233,10 +1260,10 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
String tableName = null;
StringBuffer buf = new StringBuffer();
- File file = (File) ((StructuredSelection) fileViewer.getSelection())
- .getFirstElement();
- if (file != null) {
- tableName = file.getName();
+ Object file = ( (StructuredSelection) fileViewer.getSelection( ) ).getFirstElement( );
+ if ( file != null )
+ {
+ tableName = getFileName( file );
}
if (tableName != null) {
tableName = QueryTextUtil.getQuotedName(tableName);
@@ -1293,7 +1320,7 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
if (metadata != null && metadata[0] != null && metadata[2] != null) {
// Now select the table in the list. If it doesn't exists, no
// need to process the columns.
- File f = selectTableFromQuery(metadata[2]);
+ Object f = selectTableFromQuery(metadata[2]);
if (f != null) {
updateColumnsFromQuery(queryText, f);
}
@@ -1313,7 +1340,7 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
* @param queryText
* @param file
*/
- private void updateColumnsFromQuery(String queryText, File file) {
+ private void updateColumnsFromQuery(String queryText, Object file) {
availableList.setItems(getFileColumnNames(file));
selectedColumnsViewer.getTable().removeAll();
@@ -1338,15 +1365,18 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
* @param tableName
* @return File
*/
- private File selectTableFromQuery(String tableName) {
+ private Object selectTableFromQuery(String tableName) {
// for page refresh
- File[] files = (File[]) fileViewer.getInput();
- if (files != null) {
- for (int n = 0; n < files.length; n++) {
- if (files[n].getName().equalsIgnoreCase(tableName)) {
- fileViewer.setSelection(new StructuredSelection(files[n]));
+ ArrayList<Object> files = (ArrayList<Object>) fileViewer.getInput( );
+ if ( files != null )
+ {
+ for ( int n = 0; n < files.size( ); n++ )
+ {
+ if ( getFileName( files.get( n ) ).equalsIgnoreCase( tableName ) )
+ {
+ fileViewer.setSelection( new StructuredSelection( files.get( n ) ) );
isNewFile = false;
- return files[n];
+ return files.get( n );
}
}
}
@@ -1727,7 +1757,7 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements
getControl().setFocus();
}
- private void populateWorkSheetCombo() {
+ private void populateWorkSheetCombo() throws IOException {
java.util.List<String> sheetNameList = ExcelFileReader
.getSheetNamesInExcelFile(selectedFile);
worksheetsCombo.setInput(sheetNameList.toArray());
diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFolderSelectionDialog.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFileSelectionDialog.java
index d661e3c..0cd773d 100644
--- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFolderSelectionDialog.java
+++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/RelativeFileSelectionDialog.java
@@ -1,13 +1,16 @@
-/*******************************************************************************
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Actuate Corporation - added support of relative file path
- *******************************************************************************/
+/*
+ *************************************************************************
+ * Copyright (c) 2011 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Actuate Corporation - support of relative file path
+ *
+ *************************************************************************
+ */
package org.eclipse.birt.report.data.oda.excel.ui.wizards;
@@ -21,7 +24,6 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
-import org.eclipse.birt.report.data.oda.excel.ui.i18n.Messages;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ILabelProvider;
@@ -37,7 +39,7 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
-public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
+public class RelativeFileSelectionDialog extends ElementTreeSelectionDialog
{
private final static Image IMG_FOLDER = PlatformUI.getWorkbench( )
@@ -50,7 +52,7 @@ public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
private File rootFolder;
- public RelativeFolderSelectionDialog( Shell parent, File rootFolder )
+ public RelativeFileSelectionDialog( Shell parent, File rootFolder )
{
super( parent, new LabelProvider( ), new ContentProvider( ) );
@@ -58,7 +60,7 @@ public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
this.setValidator( new SelectionValidator( ) );
this.setInput( rootFolder.getAbsolutePath( ) );
- this.setTitle( Messages.getString( "RelativeFolderSelectionDialog.Title.SelectFolder" ) ); //$NON-NLS-1$
+ this.setTitle( "SelectFile.Title" ); //$NON-NLS-1$
this.rootFolder = rootFolder;
}
@@ -98,7 +100,7 @@ public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
if ( arg0 instanceof File )
{
File f = (File) arg0;
- return RelativeFolderSelectionDialog.getChildren( f );
+ return RelativeFileSelectionDialog.getChildren( f );
}
return null;
}
@@ -113,7 +115,7 @@ public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
if ( arg0 instanceof File )
{
File f = (File) arg0;
- return RelativeFolderSelectionDialog.getChildren( f ).length > 0;
+ return RelativeFileSelectionDialog.getChildren( f ).length > 0;
}
return false;
}
@@ -207,10 +209,10 @@ public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
{
if ( o instanceof File )
{
- if ( ( (File) o ).isDirectory( ) )
+ if ( ( (File) o ).isFile( ) )
{
return new Status( IStatus.OK,
- "org.eclipse.birt.report.data.oda.excel.ui", //$NON-NLS-1$
+ "org.eclipse.datatools.connectivity.oda.flatfile.ui", //$NON-NLS-1$
IStatus.OK,
"", //$NON-NLS-1$
null );
@@ -219,7 +221,7 @@ public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
}
}
return new Status( IStatus.ERROR,
- "org.eclipse.birt.report.data.oda.excel.ui", //$NON-NLS-1$
+ "org.eclipse.datatools.connectivity.oda.flatfile.ui", //$NON-NLS-1$
IStatus.ERROR,
"", //$NON-NLS-1$
null );
@@ -237,7 +239,7 @@ public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
public boolean accept( File child )
{
- if ( child.isFile( ) )
+ if ( child.isDirectory( ) )
{
return true;
}
@@ -259,7 +261,7 @@ public class RelativeFolderSelectionDialog extends ElementTreeSelectionDialog
for ( Object o : selected )
{
File f = (File) o;
- if ( f.isDirectory( ) )
+ if ( f.isFile( ) )
{
URI relative = rootFolder.toURI( ).relativize( f.toURI( ) );
result.add( relative.getPath( ) );
diff --git a/data/org.eclipse.birt.report.data.oda.excel/plugin.properties b/data/org.eclipse.birt.report.data.oda.excel/plugin.properties
index 7b7442a..c3e6a06 100644
--- a/data/org.eclipse.birt.report.data.oda.excel/plugin.properties
+++ b/data/org.eclipse.birt.report.data.oda.excel/plugin.properties
@@ -15,7 +15,7 @@ data.source.name=Excel Data Source
data.set.name=Excel Data Set
connection.profile.name=Excel Data Source Connection Profile
-datasource.property.home=Home &Folder
+datasource.property.uri=&URI
datasource.property.incltypeline=Use Second Line as &Data Type Indicator
datasource.property.inclcolumnnameline=Use First Line as Column &Name Indicator
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 db59bda..d1f435c 100644
--- a/data/org.eclipse.birt.report.data.oda.excel/plugin.xml
+++ b/data/org.eclipse.birt.report.data.oda.excel/plugin.xml
@@ -14,9 +14,9 @@
<property
allowsEmptyValueAsNull="true"
canInherit="true"
- defaultDisplayName="%datasource.property.home"
+ defaultDisplayName="%datasource.property.uri"
isEncryptable="false"
- name="HOME"
+ name="URI"
type="string">
</property>
<property
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 67a7a08..1c62318 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
@@ -8,15 +8,17 @@
* Contributors:
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
* Actuate Corporation - support of timestamp, datetime, time, and date data types
+ * Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel;
public class ExcelODAConstants {
- public static final String CONN_HOME_DIR_PROP = "HOME"; //$NON-NLS-1$
+ public static final String CONN_FILE_URI_PROP = "URI"; //$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 UNSUPPORT_FORMAT="unSupportFormat";
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$
diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java
index 33fb722..f98e4fd 100644
--- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java
+++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/Connection.java
@@ -9,6 +9,7 @@
* Megha Nidhi Dahal - initial API and implementation and/or initial documentation
* Actuate Corporation - code cleanup
* Actuate Corporation - added support of relative file path
+ * Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
*******************************************************************************/
@@ -45,18 +46,20 @@ public class Connection implements IConnection {
Messages.getString("connection_CONNECTION_PROPERTIES_MISSING")); //$NON-NLS-1$
this.connProperties = connProperties;
- validateHomeDir();
+ validateURI();
}
// move the test connection to ExcelDataSourcePageHelper.createTestConnectionRunnable
- private void validateHomeDir( ) throws OdaException
+ private void validateURI( ) throws OdaException
{
- String homeDir = connProperties.getProperty( ExcelODAConstants.CONN_HOME_DIR_PROP );
- if ( homeDir != null && homeDir.trim( ).length( ) > 0 ) // found
+ String uri = connProperties.getProperty( ExcelODAConstants.CONN_FILE_URI_PROP );
+
+ if ( uri != null && uri.trim( ).length( ) > 0 ) // found
{
this.isOpen = true;
return; // is valid, done
}
+
throw new OdaException( Messages.getString( "connection_MISSING_FILELOCATION" ));
}
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 4db90a0..93ff3cf 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
@@ -10,6 +10,7 @@
* Actuate Corporation - more efficient xlsx processing;
* support of timestamp, datetime, time, and date data types
* Actuate Corporation - added support of relative file path
+ * Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.impl;
@@ -81,16 +82,16 @@ public class ExcelFileQuery implements IQuery {
private Map appContext = null;
- public ExcelFileQuery(Properties connProperties)
- throws OdaException {
- if (connProperties == null
- || connProperties.getProperty(ExcelODAConstants.CONN_HOME_DIR_PROP) == null )
- throw new OdaException(
- Messages.getString("common_ARGUMENT_CANNOT_BE_NULL")); //$NON-NLS-1$
+ public ExcelFileQuery( Properties connProperties ) throws OdaException
+ {
+ if ( connProperties == null
+ || connProperties.getProperty( ExcelODAConstants.CONN_FILE_URI_PROP ) == null )
+ throw new OdaException( Messages.getString( "common_ARGUMENT_CANNOT_BE_NULL" ) ); //$NON-NLS-1$
+
this.connProperties = connProperties;
- extractsHasColumnNamesInfo();
- extractsHasColumnTypeLineInfo();
+ extractsHasColumnNamesInfo( );
+ extractsHasColumnTypeLineInfo( );
}
/**
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 6f31b58..33d80a1 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
@@ -2,7 +2,7 @@
connection_CONNECTION_PROPERTIES_MISSING=Connection properties are missing.
connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR=Cannot open excel file database under directory:
-connection_MISSING_FILELOCATION=The Excel data source folder property is not defined; requires a home folder path or URI for the Excel input file.
+connection_MISSING_FILELOCATION=The Excel data source file property is not defined; requires a file path or URI for the Excel input file.
connection_invalidSource=Invalid or malformed URI specified for the Excel data source folder.
connection_missingResourceIdentifier=No resource identifier is available to resolve the relative path of the Excel data source:
fileSource_excelFileNotFound=Unable to locate the specified Excel data source folder or file ({0}).
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 f158365..e7eb42a 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
@@ -9,14 +9,16 @@
* 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
+ * Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.impl.util;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
@@ -37,7 +39,7 @@ import org.xml.sax.SAXException;
public class ExcelFileReader {
- private FileInputStream fis;
+ private InputStream fis;
private String fileExtension;
private List<String> workSheetList;
static LinkedHashMap<String, String> xlsxWorkSheetList;
@@ -62,7 +64,7 @@ public class ExcelFileReader {
this.maxColumnIndex = maxColumnIndex;
}
- public ExcelFileReader(FileInputStream fis, String fileExtension,
+ public ExcelFileReader(InputStream fis, String fileExtension,
List<String> sheetNameList, int rowsToRead) {
this.fis = fis;
this.fileExtension = fileExtension;
@@ -79,7 +81,7 @@ public class ExcelFileReader {
return null;
}
List<String> rowData = new ArrayList<String>();
- if (!isXlsxFile(fileExtension)) {
+ if (isXlsFile(fileExtension)) {
Row row = sheet.getRow(currentRowIndex);
if (row != null) {
if (maxColumnIndex == 0)
@@ -93,7 +95,7 @@ public class ExcelFileReader {
} else {
return null;
}
- } else {
+ } else if (isXlsxFile(fileExtension)){
rowData = callback.getRow(currentRowIndex);
}
@@ -127,7 +129,7 @@ public class ExcelFileReader {
maxRowsInAllSheet += newCallback.getMaxRowsInSheet();
}
- } else {
+ } else if ( isXlsFile( fileExtension ) ){
workBook = new HSSFWorkbook(fis);
formulaEvaluator = workBook.getCreationHelper()
@@ -171,7 +173,7 @@ public class ExcelFileReader {
} catch (SAXException e) {
throw new OdaException(e);
}
- } else {
+ } else if ( isXlsFile( fileExtension ) ){
do {
sheet = workBook.getSheet(workSheetList.get(currentSheetIndex));
maxRowsInThisSheet = sheet.getPhysicalNumberOfRows();
@@ -186,7 +188,56 @@ public class ExcelFileReader {
}
private static boolean isXlsxFile(String extension) {
- return !extension.equals(ExcelODAConstants.XLS_FORMAT);
+ return extension.equals(ExcelODAConstants.XLSX_FORMAT);
+ }
+
+ private static boolean isXlsFile(String extension) {
+ return extension.equals(ExcelODAConstants.XLS_FORMAT);
+ }
+
+ public static String getExtensionName(Object ri, String path ) throws OdaException
+ {
+ URI uri = ResourceLocatorUtil.resolvePath(ri, path);
+ return getExtensionName( uri );
+ }
+
+ public static String getExtensionName( Object uri )
+ {
+ InputStream xlsxIs = null;
+ InputStream xlsIs = null;
+ try
+ {
+ xlsxIs = ResourceLocatorUtil.getURIStream( uri );
+ new XlsxFileReader( xlsxIs );
+ return ExcelODAConstants.XLSX_FORMAT;
+ }
+ catch ( Exception e )
+ {
+ try {
+ xlsIs = ResourceLocatorUtil.getURIStream( uri );
+ new HSSFWorkbook(xlsIs);
+ return ExcelODAConstants.XLS_FORMAT;
+ } catch (Exception e1) {
+ }
+
+ }
+ finally
+ {
+ try {
+ if (xlsIs != null)
+ {
+ xlsIs.close();
+ }
+ if ( xlsxIs != null)
+ {
+ xlsxIs.close();
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return ExcelODAConstants.UNSUPPORT_FORMAT;
}
public String getCellValue(Cell cell) {
@@ -243,15 +294,14 @@ public class ExcelFileReader {
return maxRowsInAllSheet;
}
- public static List<String> getSheetNamesInExcelFile(File file) {
- String extension = file.getName();
- extension = extension.substring(extension.lastIndexOf(".") + 1, //$NON-NLS-1$
- extension.length());
- FileInputStream fis;
+
+ public static List<String> getSheetNamesInExcelFile(Object file) throws MalformedURLException, IOException {
+ String extension = getExtensionName (file);
+ InputStream fis = ResourceLocatorUtil.getURIStream( file );
List<String> sheetNames = new ArrayList<String>();
try {
- fis = new FileInputStream(file);
+ // using uri, we may not know the extension name of the file.
if (isXlsxFile(extension)) {
XlsxFileReader poiRdr = new XlsxFileReader(fis);
xlsxWorkSheetList = poiRdr.getSheetNames();
@@ -259,7 +309,7 @@ public class ExcelFileReader {
.entrySet()) {
sheetNames.add(entry.getKey());
}
- } else {
+ } else if ( isXlsFile( extension ) ){
Workbook workBook = new HSSFWorkbook(fis);
for (int i = 0; i < workBook.getNumberOfSheets(); i++) {
sheetNames.add(workBook.getSheetName(i));
@@ -273,6 +323,10 @@ public class ExcelFileReader {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ finally
+ {
+ fis.close( );
+ }
return sheetNames;
}
}
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 3a23b7d..ee5f23c 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
@@ -10,12 +10,11 @@
* Actuate Corporation - more efficient xlsx processing;
* support of timestamp, datetime, time, and date data types
* Actuate Corporation - added support of relative file path
+ * Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
*******************************************************************************/
package org.eclipse.birt.report.data.oda.excel.impl.util;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
@@ -38,7 +37,8 @@ public class ExcelFileSource {
private ResultSetMetaDataHelper rsmdHelper;
private int statementMaxRows;
private String currentTableName;
- private String homeDir;
+ private String uriPath;
+ private URI uri;
private boolean hasColumnNames;
private boolean hasTypeLine;
private List<String> sheetNameList = new ArrayList<String>();
@@ -70,6 +70,7 @@ public class ExcelFileSource {
* @param rsmdHelper
* ResultSet meta-data helper
* @throws OdaException
+ * @throws IOException
*/
public ExcelFileSource(Properties connProperties, String currentTableName,
String workSheetNames,
@@ -79,10 +80,10 @@ public class ExcelFileSource {
this.rsmdHelper = rsmdHelper;
this.statementMaxRows = statementMaxRows;
this.currentTableName = currentTableName;
- this.fileExtension = extractFileExtension(currentTableName);
this.resourceIdentifiers = appContext != null ?
appContext.get( ResourceIdentifiers.ODA_APP_CONTEXT_KEY_CONSUMER_RESOURCE_IDS ) :
null;
+ this.fileExtension = ExcelFileReader.getExtensionName(resourceIdentifiers, connProperties.getProperty(ExcelODAConstants.CONN_FILE_URI_PROP));
Properties properties = getCopyOfConnectionProperties(connProperties);
populateHomeDir(properties);
populateHasColumnNames(properties);
@@ -90,14 +91,6 @@ public class ExcelFileSource {
populateWorksheetNames(workSheetNames);
}
- private static String extractFileExtension(String fileName) {
- int lastIndexOfDot = fileName.lastIndexOf('.');
- if (lastIndexOfDot == -1) {
- return ExcelODAConstants.XLS_FORMAT;
- } else {
- return fileName.substring(lastIndexOfDot + 1, fileName.length());
- }
- }
/**
*
@@ -107,10 +100,15 @@ public class ExcelFileSource {
private Properties getCopyOfConnectionProperties(Properties connProperties) {
Properties copyConnProperites = new Properties();
- copyConnProperites.setProperty(ExcelODAConstants.CONN_HOME_DIR_PROP,
+ if (connProperties
+ .getProperty(ExcelODAConstants.CONN_FILE_URI_PROP) != null)
+ {
+ copyConnProperites.setProperty(ExcelODAConstants.CONN_FILE_URI_PROP,
connProperties
- .getProperty(ExcelODAConstants.CONN_HOME_DIR_PROP));
- copyConnProperites
+ .getProperty(ExcelODAConstants.CONN_FILE_URI_PROP));
+ }
+
+ copyConnProperites
.setProperty(
ExcelODAConstants.CONN_INCLCOLUMNNAME_PROP,
connProperties
@@ -128,23 +126,27 @@ public class ExcelFileSource {
* @throws OdaException
*/
private void populateHomeDir(Properties connProperties) throws OdaException {
- this.homeDir = connProperties
- .getProperty(ExcelODAConstants.CONN_HOME_DIR_PROP);
+ this.uriPath = connProperties.getProperty( ExcelODAConstants.CONN_FILE_URI_PROP );
+ uri = ResourceLocatorUtil.resolvePath( resourceIdentifiers, uriPath );
- URI uri = ResourceLocatorUtil.resolvePath(resourceIdentifiers, homeDir);
if (uri == null)
{
throw new OdaException(
Messages.getFormattedString("fileSource_excelFileNotFound", //$NON-NLS-1$
- new Object[]{homeDir} ));
+ new Object[]{uriPath} ));
}
-
- File file = new File(uri);
- if (!file.exists())
- throw new OdaException(
- Messages.getFormattedString("fileSource_excelFileNotFound", //$NON-NLS-1$
- new Object[]{homeDir} ));
+ try
+ {
+ ResourceLocatorUtil.validateFileURI( uri );
+ }
+ catch (Exception e)
+ {
+ throw new OdaException( Messages.getFormattedString( "fileSource_excelFileNotFound", //$NON-NLS-1$
+ new Object[]{
+ uriPath
+ } ) );
+ }
}
@@ -199,17 +201,12 @@ public class ExcelFileSource {
int count;
try {
- String dataFilePath = findDataFileAbsolutePath();
- FileInputStream fis = new FileInputStream(dataFilePath);
- //ExcelFileReader excelreader = new ExcelFileReader(fis,
- // fileExtension, sheetNameList);
initialiseReader();
List<String> columnLine;
while (isEmptyRow(columnLine = this.excelFileReader.readLine())) {
continue;
}
count = columnLine.size();
- fis.close();
} catch (IOException e) {
throw new OdaException(Messages.getString("query_IO_EXCEPTION") //$NON-NLS-1$
+ findDataFileAbsolutePath());
@@ -228,21 +225,22 @@ public class ExcelFileSource {
* if the table name cannot be found
*/
public String findDataFileAbsolutePath() throws OdaException {
- String filePath = this.homeDir + File.separator
- + this.currentTableName.trim();
- URI uri = ResourceLocatorUtil.resolvePath(resourceIdentifiers, filePath);
if (uri == null)
{
- throw new OdaException(
- Messages.getFormattedString("fileSource_excelFileNotFound", //$NON-NLS-1$
- new Object[]{filePath} ));
+ throw new OdaException( Messages.getFormattedString( "fileSource_excelFileNotFound", //$NON-NLS-1$
+ new Object[]{
+ uriPath
+ } ) );
}
- File file = new File(uri);
+ try {
+ ResourceLocatorUtil.validateFileURI(uri);
+ } catch (Exception e) {
+ throw new OdaException( Messages.getString( "query_invalidTableName" ) //$NON-NLS-1$
+ + this.uriPath );
+ }
+
+ return uri.toString();
- if (!file.exists())
- throw new OdaException(Messages.getString("query_invalidTableName") //$NON-NLS-1$
- + this.homeDir + File.separator + this.currentTableName);
- return file.getAbsolutePath();
}
/**
@@ -447,16 +445,10 @@ public class ExcelFileSource {
*/
private void initialiseReader() throws OdaException, IOException {
- try {
- if (this.excelFileReader == null) {
- String dataFilePath = findDataFileAbsolutePath();
- this.excelFileReader = new ExcelFileReader(new FileInputStream(
- dataFilePath), this.fileExtension, this.sheetNameList, this.statementMaxRows);
- }
+ this.fileExtension = ExcelFileReader.getExtensionName( uri );
+ this.excelFileReader = new ExcelFileReader(ResourceLocatorUtil.getURIStream( uri ), this.fileExtension,
+ this.sheetNameList, this.statementMaxRows);
- } catch (IOException e) {
- throw new OdaException(e.getMessage());
- }
}
/**
diff --git a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ResourceLocatorUtil.java b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ResourceLocatorUtil.java
index 81f3339..12d729b 100644
--- a/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ResourceLocatorUtil.java
+++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ResourceLocatorUtil.java
@@ -7,13 +7,16 @@
*
* Contributors:
* Actuate Corporation - added support of relative file path
- *
+ * Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
*************************************************************************
*/
package org.eclipse.birt.report.data.oda.excel.impl.util;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
@@ -31,8 +34,15 @@ public class ResourceLocatorUtil
public static URI resolvePath( Object resourceIdentifiers, String path ) throws OdaException
{
URI uri = null;
- File f = new File( path );
- if( f.isAbsolute( ) && f.exists( ) )
+ File f = null;
+ try
+ {
+ f = new File( path );
+ }
+ catch ( Exception ignore )
+ {
+ }
+ if (f != null && f.isAbsolute() && f.exists() )
{
uri = f.toURI();
logger.log( Level.FINER, "Excel source folder exists on local file system. Using path: " + uri );
@@ -79,4 +89,48 @@ public class ResourceLocatorUtil
}
}
+ public static void validateFileURI( Object obj )
+ throws Exception
+ {
+
+ InputStream stream = null;
+ try
+ {
+ stream = getURIStream( obj );
+ }
+ catch (Exception e)
+ {
+ throw e ;
+ }
+ finally
+ {
+ if ( stream != null )
+ {
+ try
+ {
+ stream.close( );
+ }
+ catch ( IOException ignore )
+ {
+ }
+ }
+
+ }
+ }
+
+ public static InputStream getURIStream( Object obj ) throws IOException
+ {
+ if ( obj instanceof File )
+ {
+ return new FileInputStream( (File) obj );
+ }
+
+ else if ( obj instanceof URI )
+ {
+ return ( (URI) obj ).toURL( ).openStream( );
+ }
+
+ return null;
+ }
+
}
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 333755b..912388d 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
@@ -9,11 +9,11 @@
* 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
+ * Actuate Corporation - support defining an Excel input file path or URI as part of the data source definition
*******************************************************************************/
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;
@@ -55,7 +55,7 @@ public class XlsxFileReader {
STATIC
}
- public XlsxFileReader(FileInputStream fis) throws IOException,
+ public XlsxFileReader(InputStream fis) throws IOException,
OpenXML4JException {
OPCPackage pkg = OPCPackage.open(fis);
reader = new XSSFReader(pkg);