| author | pshi | 2012-04-10 23:04:41 (EDT) |
|---|---|---|
| committer | xgu | 2012-05-03 04:48:45 (EDT) |
| commit | b380e4675336b4ac897edfe93eca6e4cde9bf2a3 (patch) (side-by-side diff) | |
| tree | dbe499485b63d68a22eb736ea9487648ecf48269 | |
| parent | afca3b4801d2720c40ce5d789b0c7dc936ec88ea (diff) | |
| download | org.eclipse.birt-b380e4675336b4ac897edfe93eca6e4cde9bf2a3.zip org.eclipse.birt-b380e4675336b4ac897edfe93eca6e4cde9bf2a3.tar.gz org.eclipse.birt-b380e4675336b4ac897edfe93eca6e4cde9bf2a3.tar.bz2 | |
improve fix for 48282 Support Relative File Path for the input file in Excel ODA Designer add short-cut key for browse button, clean code
9 files changed, 221 insertions, 86 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 add5e30..dde1755 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 @@ -14,7 +14,7 @@ wizard.defaultMessage.selectFolder=Select the folder that contains Excel data source file(s). wizard.defaultMessage.selectFile=Select the file, worksheet and the columns for the data set. connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR=Cannot open Excel file database under directory - +ui.ExcelFileNotFound=Could not found excel file label.selectFolder=S&elect folder: label.selectFile=Select f&ile: label.selectworksheet=Worksheet: @@ -53,7 +53,7 @@ error.selectFolder=Please select a valid folder. error.emptyPath=Please enter a path. error.unexpectedError=An unexpected error occurred. error.invalidConnectionFilePath=The specified connection profile source path, "{0}", does not exist. -error.invalidFlatFilePath=Invalid Excel data source folder 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.invalidFilePath=The file path is invalid. Would you like to continue? 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 4765f8c..5e04307 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 @@ -17,6 +17,7 @@ import java.net.URISyntaxException; import java.util.Properties; import org.eclipse.birt.report.data.oda.excel.ExcelODAConstants; +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; @@ -55,6 +56,7 @@ public class ExcelDataSourcePageHelper { private WizardPage wizardPage; private PreferencePage propertyPage; + private String errorMsg = Messages.getString( "connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR" ); private transient Text folderLocation = null; private transient Button typeLineCheckBox = null; @@ -120,9 +122,9 @@ public class ExcelDataSourcePageHelper { }); - browseFolderButton = new MenuButton( composite, SWT.NONE ); - browseFolderButton.setText( Messages.getString( "button.selectFolder.browse" ) ); //$NON-NLS-1$ - + browseFolderButton = new MenuButton( composite, + SWT.NONE, + Messages.getString( "button.selectFolder.browse" ) ); Menu menu = new Menu( composite.getShell( ), SWT.POP_UP ); SelectionAdapter action = new SelectionAdapter( ) { @@ -415,7 +417,7 @@ public class ExcelDataSourcePageHelper { int verify = verifyFileLocation( ); if ( verify == ERROR_FOLDER ) { - throw new OdaException( Messages.getString( "connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR" ) );//$NON-NLS-1$ + throw new OdaException( errorMsg );//$NON-NLS-1$ } } catch ( Exception ex ) @@ -431,24 +433,36 @@ public class ExcelDataSourcePageHelper { * * @return */ - private int verifyFileLocation( ) { + private int verifyFileLocation( ) { int result = CORRECT_FOLDER; String folderLocationValue = getFolderLocationString().trim(); if ( folderLocationValue.length( ) > 0 ) { - File f = new File( folderLocationValue ); - if ( !f.isAbsolute( ) ) + URI uri = null; + try + { + uri = ResourceLocatorUtil.resolvePath( ri, folderLocationValue ); + } + catch ( OdaException e ) + { + setMessage( e.getMessage( ), IMessageProvider.ERROR ); + setPageComplete( false ); + return ERROR_FOLDER; + } + if ( uri == null ) { - folderLocationValue = getResourceFolder( ) - + File.separator + folderLocationValue; - f = new File( folderLocationValue.trim( ) ); + setMessage( Messages.getString( "ui.ExcelFileNotFound" ), IMessageProvider.ERROR ); //$NON-NLS-1$ + setPageComplete( false ); + return ERROR_FOLDER; } + File f = new File( uri ); if ( f.exists( ) ) { - if (f.isDirectory() ) { - File[] files = f.getAbsoluteFile().listFiles( - new ExcelFileFilter()); - if (files.length == 0) + 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 ); @@ -480,7 +494,7 @@ public class ExcelDataSourcePageHelper { if (wizardPage == null) { setPageComplete(true); setMessage( - Messages.getString("error.invalidFlatFilePath"), IMessageProvider.ERROR); //$NON-NLS-1$ + Messages.getString("error.invalidExcelFilePath"), IMessageProvider.ERROR); //$NON-NLS-1$ } return result; } @@ -511,6 +525,7 @@ public class ExcelDataSourcePageHelper { wizardPage.setMessage(newMessage, newType); else if (propertyPage != null) propertyPage.setMessage(newMessage, newType); + errorMsg = newMessage; } private Control getControl() { 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 641d978..bc1d436 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 @@ -15,6 +15,7 @@ package org.eclipse.birt.report.data.oda.excel.ui.wizards; import java.io.File; import java.io.FilenameFilter; +import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -22,6 +23,7 @@ import java.util.Map; import org.eclipse.birt.report.data.oda.excel.ExcelODAConstants; import org.eclipse.birt.report.data.oda.excel.impl.Driver; import org.eclipse.birt.report.data.oda.excel.impl.util.ExcelFileReader; +import org.eclipse.birt.report.data.oda.excel.impl.util.ResourceLocatorUtil; import org.eclipse.birt.report.data.oda.excel.impl.util.querytextutil.ColumnsInfoUtil; import org.eclipse.birt.report.data.oda.excel.impl.util.querytextutil.QueryTextUtil; import org.eclipse.birt.report.data.oda.excel.ui.i18n.Messages; @@ -144,7 +146,6 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements private java.util.List<String[]> originalFileColumnsInfoList = new ArrayList<String[]>(); private java.util.List<String[]> savedSelectedColumnsInfoList = new ArrayList<String[]>(); - private ResourceIdentifiers ri; /** * @param pageName */ @@ -153,7 +154,6 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements setTitle(pageName); createColumnTypeMap(); setMessage(DEFAULT_MESSAGE); - setPageComplete(false); } @@ -881,12 +881,25 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements String sourcePath = dataSourceProps .getProperty(ConnectionProfileProperty.PROFILE_STORE_FILE_PATH_PROP_KEY); if (sourcePath != null) { - File cpFile = new File(sourcePath); - if ( !cpFile.isAbsolute( ) ) + + URI uri = null; + try { + ResourceIdentifiers ri = DesignSessionUtil.createRuntimeResourceIdentifiers( getHostResourceIdentifiers( ) ); + uri = ResourceLocatorUtil.resolvePath(ri, sourcePath); + } catch (OdaException e) { + setMessage(Messages + .getFormattedString( + e.getMessage( ), new Object[] { sourcePath })); //$NON-NLS-1$ + return; + } + if (uri == null) { - cpFile = new File( getResourceFolder( ) - + File.separator + cpFile ); + setMessage(Messages + .getFormattedString( + "ui.ExcelFileNotFound", new Object[] { sourcePath })); //$NON-NLS-1$ + return; } + File cpFile = new File(uri); if (!cpFile.exists()) { setMessage( Messages.getFormattedString( @@ -912,22 +925,6 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements } } - private String getResourceFolder( ) - { - if ( ri == null ) - { - ri = DesignSessionUtil.createRuntimeResourceIdentifiers( getHostResourceIdentifiers( ) ); - } - if ( ri != null ) - { - if ( ri.getApplResourceBaseURI( ) != null ) - { - return new File( ri.getApplResourceBaseURI( ) ).getAbsolutePath( ); - } - } - return null; - } - static class ExcelFileFilter implements FilenameFilter { @Override public boolean accept(File dir, String fileName) { @@ -954,12 +951,28 @@ public class ExcelFileSelectionWizardPage extends DataSetWizardPage implements return; } - File folder = new File(odaHome); - if ( !folder.isAbsolute( ) ) + URI uri = null; + try + { + ResourceIdentifiers ri = DesignSessionUtil.createRuntimeResourceIdentifiers( getHostResourceIdentifiers( ) ); + uri = ResourceLocatorUtil.resolvePath( ri, odaHome ); + } + catch ( OdaException e ) { - folder = new File( getResourceFolder( ) - + File.separator + folder ); + setMessage( Messages.getFormattedString( "ui.ExcelFileNotFound", new Object[]{odaHome} ) ); //$NON-NLS-1$ + disableAll( ); + return; } + if (uri == null) + { + setMessage(Messages + .getFormattedString( + "ui.ExcelFileNotFound", new Object[] { odaHome })); //$NON-NLS-1$ + disableAll(); + return; + } + + File folder = new File(uri); if (folder.isDirectory() && folder.exists()) { File[] files = folder.getAbsoluteFile().listFiles( new ExcelFileFilter()); diff --git a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/MenuButton.java b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/MenuButton.java index 64f50c5..74fff6e 100644 --- a/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/MenuButton.java +++ b/data/org.eclipse.birt.report.data.oda.excel.ui/src/org/eclipse/birt/report/data/oda/excel/ui/wizards/MenuButton.java @@ -69,11 +69,6 @@ public class MenuButton extends Composite private static final int WIDTH_MORE = 2 * MARGIN_GAP + TRIANGLE_WIDTH + 1; - public void setText( String text ) - { - this.text = text; - layoutControl( ); - } public void setToolTipText( String string ) { @@ -95,6 +90,7 @@ public class MenuButton extends Composite int height; Button tmp = new Button( this, button.getStyle( ) ); + String text = button.getText( ); if ( text != null ) { tmp.setText( text ); @@ -169,16 +165,16 @@ public class MenuButton extends Composite button.redraw( ); } - public MenuButton( Composite parent, int style ) + public MenuButton( Composite parent, int style, String text ) { - this( parent, style, false ); + this( parent, style, false, text ); } private boolean isFixed = true; private boolean mouseSelection = false; - public MenuButton( Composite parent, int style, boolean fixed ) + public MenuButton( Composite parent, int style, boolean fixed, String text ) { super( parent, SWT.NONE ); isFixed = fixed; @@ -187,6 +183,8 @@ public class MenuButton extends Composite this.setLayout( layout ); button = new Button( this, style ); + button.setText( text ); + layoutControl( ); GridData gd = new GridData( GridData.FILL_BOTH ); button.setLayoutData( gd ); button.addPaintListener( new PaintListener( ) { @@ -264,12 +262,33 @@ public class MenuButton extends Composite if ( listeners == null ) return; - e.widget = MenuButton.this; + // separate the mouse click from the key press event on the button + boolean keyPress = false; + if( e.widget instanceof Button ) + { + if( ((Button)e.widget).getParent() instanceof MenuButton ) + { + if ( menu != null ) + { + keyPress = true; + Rectangle size = button.getBounds( ); + menu.setLocation( button.toDisplay( new Point( 0, + size.height - 1 ) ) ); + menu.setVisible( true ); + } + } + } + + if( !keyPress ) + { + e.widget = MenuButton.this; + + for ( int i = 0; i < listeners.size( ); i++ ) + { + ( (SelectionListener) listeners.get( i ) ).widgetSelected( new SelectionEvent( e ) ); + } + } - for ( int i = 0; i < listeners.size( ); i++ ) - { - ( (SelectionListener) listeners.get( i ) ).widgetSelected( new SelectionEvent( e ) ); - } } } ); 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 39a2cd3..686e338 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 @@ -106,8 +106,9 @@ public class Connection implements IConnection { if (!isOpen()) throw new OdaException( Messages.getString("common_CONNECTION_HAS_NOT_OPEN")); //$NON-NLS-1$ - - return new ExcelFileQuery(connProperties, this); + ExcelFileQuery excelFileQuery = new ExcelFileQuery(connProperties, this); + excelFileQuery.setAppContext( appContext ); + return excelFileQuery; } public ResourceIdentifiers getResourceIdentifiers( ) 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 27318b8..7c80e82 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 @@ -21,6 +21,7 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Vector; @@ -82,6 +83,8 @@ public class ExcelFileQuery implements IQuery { private boolean isInvalidQuery; + private Map appContext = null; + public ExcelFileQuery(Properties connProperties, Connection connection) throws OdaException { if (connProperties == null @@ -194,7 +197,7 @@ public class ExcelFileQuery implements IQuery { // from a xlsx file ExcelFileSource excelFileReader = new ExcelFileSource(connProperties, currentTableName, worksheetNames, maxRowsToRead, null, - null, connection); + null, appContext); String[] allColumnNames; String[] allColumnTypes; @@ -490,7 +493,7 @@ public class ExcelFileQuery implements IQuery { // from a xlsx file ExcelFileSource excelFileSource = new ExcelFileSource( this.connProperties, tableName, worksheetNames, - maxRowsToRead, null, null, connection); + maxRowsToRead, null, null, appContext); try { if (!(metaDataType.trim().equalsIgnoreCase(NAME_LITERAL) || metaDataType .trim().equalsIgnoreCase(TYPE_LITERAL))) @@ -624,7 +627,7 @@ public class ExcelFileQuery implements IQuery { * .Object) */ public void setAppContext(Object context) throws OdaException { - // do nothing; assumes no support for pass-through context + this.appContext = (Map) context; } /* @@ -656,7 +659,7 @@ public class ExcelFileQuery implements IQuery { return new ResultSet(new ExcelFileSource(this.connProperties, this.currentTableName, worksheetNames, this.maxRows, this.resultSetMetaData, - this.resultSetMetaDataHelper, connection), this.resultSetMetaData); + this.resultSetMetaDataHelper, appContext), this.resultSetMetaData); } /* 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 082ae82..67e5fde 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,6 +2,11 @@ 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=Missing required connection properties: home folder for local excel file and URI for remote excel file. +ui.ExcelFileNotFound=Could not found excel file: + +Connection.InvalidSource=The excel source folder cannot be found or the URL is malformed. +Connection.InvalidRelativePath=Failed resolving excel source folder, because it is not an absolute path and no resource identifier provided. query_COMMAND_IS_EMPTY=Query command is empty. query_DO_NOT_SUPPORT_CROSS_TABLE_QUERY=Cross-table query is not supported. 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 5e05013..c155581 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 @@ -17,15 +17,16 @@ 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; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import org.eclipse.birt.report.data.oda.excel.ExcelODAConstants; import org.eclipse.birt.report.data.oda.excel.ResultSetMetaDataHelper; import org.eclipse.birt.report.data.oda.excel.impl.i18n.Messages; -import org.eclipse.datatools.connectivity.oda.IConnection; import org.eclipse.datatools.connectivity.oda.IResultSetMetaData; import org.eclipse.datatools.connectivity.oda.OdaException; import org.eclipse.datatools.connectivity.oda.util.ResourceIdentifiers; @@ -51,7 +52,7 @@ public class ExcelFileSource { private String[] originalColumnNames; private boolean isFirstTimeToReadSourceData = true; private List<String> nextDataLine; - private IConnection connection; + private ResourceIdentifiers ri; /** * Constructor * @@ -70,13 +71,13 @@ public class ExcelFileSource { public ExcelFileSource(Properties connProperties, String currentTableName, String workSheetNames, int statementMaxRows, IResultSetMetaData rsmd, - ResultSetMetaDataHelper rsmdHelper, IConnection connection) throws OdaException { + ResultSetMetaDataHelper rsmdHelper, Map appContext) throws OdaException { this.rsmd = rsmd; this.rsmdHelper = rsmdHelper; this.statementMaxRows = statementMaxRows; this.currentTableName = currentTableName; - this.connection = connection; this.fileExtension = extractFileExtension(currentTableName); + this.ri = (ResourceIdentifiers) appContext.get( ResourceIdentifiers.ODA_APP_CONTEXT_KEY_CONSUMER_RESOURCE_IDS ); Properties properties = getCopyOfConnectionProperties(connProperties); populateHomeDir(properties); populateHasColumnNames(properties); @@ -124,29 +125,24 @@ public class ExcelFileSource { private void populateHomeDir(Properties connProperties) throws OdaException { this.homeDir = connProperties .getProperty(ExcelODAConstants.CONN_HOME_DIR_PROP); - File file = new File(this.homeDir); - if ( !file.isAbsolute( ) ) + + URI uri = ResourceLocatorUtil.resolvePath(ri, homeDir); + if (uri == null) { - file = new File( getAbsoluteFile( ) + File.separator + homeDir ); + throw new OdaException( + Messages.getString("ui.ExcelFileNotFound") //$NON-NLS-1$ + + this.homeDir); } + + + File file = new File(uri); if (!file.exists()) throw new OdaException( - Messages.getString("connection_CANNOT_OPEN_EXCEL_FILE_DB_DIR") //$NON-NLS-1$ + Messages.getString("ui.ExcelFileNotFound") //$NON-NLS-1$ + this.homeDir); } - private String getAbsoluteFile( ) - { - ResourceIdentifiers ri = ( (org.eclipse.birt.report.data.oda.excel.impl.Connection) connection ).getResourceIdentifiers( ); - if ( ri.getApplResourceBaseURI( ) != null ) - { - return new File( ri.getApplResourceBaseURI( ) ).getAbsolutePath( ); - } - - return null; - } - /** * * @param connProperties @@ -227,14 +223,16 @@ public class ExcelFileSource { * if the table name cannot be found */ public String findDataFileAbsolutePath() throws OdaException { - File file = new File(this.homeDir + File.separator + URI uri = ResourceLocatorUtil.resolvePath(ri, this.homeDir + File.separator + this.currentTableName.trim()); - if ( !file.isAbsolute( ) ) + if (uri == null) { - file = new File( getAbsoluteFile( ) - + File.separator + this.homeDir + File.separator - + this.currentTableName.trim( ) ); + throw new OdaException( + Messages.getString("ui.ExcelFileNotFound") //$NON-NLS-1$ + + this.homeDir); } + File file = new File(uri); + if (!file.exists()) throw new OdaException(Messages.getString("query_invalidTableName") //$NON-NLS-1$ + this.homeDir + File.separator + this.currentTableName); 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 new file mode 100644 index 0000000..d5bf26b --- a/dev/null +++ b/data/org.eclipse.birt.report.data.oda.excel/src/org/eclipse/birt/report/data/oda/excel/impl/util/ResourceLocatorUtil.java @@ -0,0 +1,81 @@ +/************************************************************************* + * 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 - added support of relative file path + * + ************************************************************************* + */ + +package org.eclipse.birt.report.data.oda.excel.impl.util; + +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.eclipse.birt.report.data.oda.excel.impl.i18n.Messages; +import org.eclipse.datatools.connectivity.oda.OdaException; +import org.eclipse.datatools.connectivity.oda.util.ResourceIdentifiers; + + +public class ResourceLocatorUtil +{ + private static Logger logger = Logger.getLogger(ResourceLocatorUtil.class.getName( )); + + public static URI resolvePath( Object resourceIdentifiers, String path ) throws OdaException + { + URI uri = null; + File f = new File( path ); + if( f.isAbsolute( ) && f.exists( ) ) + { + uri = f.toURI(); + logger.log( Level.FINER, "Excel source folder exists on local file system. Using path: " + uri ); + return uri; + } + + logger.log( Level.FINER, "Try resolving URI and relative path: " + path ); + try + { + try + { + uri = new URI( path ); + } + catch ( URISyntaxException ex ) + { + uri = new URI( null, null, path, null ); + } + + logger.log( Level.FINER, "Resolved excel source URI: " + uri ); + + if ( uri.isAbsolute() ) + { + logger.log( Level.FINER, "Excel source folder URI is resolved as the absolute path: " + uri ); + return uri; + } + else if ( !uri.isAbsolute( ) && resourceIdentifiers != null ) + { + uri = ResourceIdentifiers.resolveApplResource( resourceIdentifiers, uri ); + logger.log( Level.FINER, "Relative URI resolved as the absolute path: " + uri ); + return uri; + } + else + { + logger.log( Level.SEVERE, + Messages.getString("Connection.InvalidRelativePath") + + uri ); + throw new OdaException( Messages.getString( "Connection.InvalidSource" ) ); + } + } + catch ( URISyntaxException e1 ) + { + throw new OdaException( Messages.getString( "Connection.InvalidSource" ) ); //$NON-NLS-1$ + } + } + +} |

