List of usage examples for org.apache.commons.vfs FileSystemException getMessage
public String getMessage()
From source file:org.pentaho.di.job.entries.copyfiles.JobEntryCopyFiles.java
private boolean ProcessFileFolder(String sourcefilefoldername, String destinationfilefoldername, String wildcard, Job parentJob, Result result) { boolean entrystatus = false; FileObject sourcefilefolder = null; FileObject destinationfilefolder = null; // Clear list files to remove after copy process // This list is also added to result files name list_files_remove.clear();//from w ww .java2s .c o m list_add_result.clear(); // Get real source, destination file and wildcard String realSourceFilefoldername = environmentSubstitute(sourcefilefoldername); String realDestinationFilefoldername = environmentSubstitute(destinationfilefoldername); String realWildcard = environmentSubstitute(wildcard); try { sourcefilefolder = KettleVFS.getFileObject(realSourceFilefoldername, this); destinationfilefolder = KettleVFS.getFileObject(realDestinationFilefoldername, this); if (sourcefilefolder.exists()) { // Check if destination folder/parent folder exists ! // If user wanted and if destination folder does not exist // PDI will create it if (CreateDestinationFolder(destinationfilefolder)) { // Basic Tests if (sourcefilefolder.getType().equals(FileType.FOLDER) && destination_is_a_file) { // Source is a folder, destination is a file // WARNING !!! CAN NOT COPY FOLDER TO FILE !!! logError(BaseMessages.getString(PKG, "JobCopyFiles.Log.CanNotCopyFolderToFile", realSourceFilefoldername, realDestinationFilefoldername)); NbrFail++; } else { if (destinationfilefolder.getType().equals(FileType.FOLDER) && sourcefilefolder.getType().equals(FileType.FILE)) { // Source is a file, destination is a folder // Copy the file to the destination folder destinationfilefolder.copyFrom(sourcefilefolder.getParent(), new TextOneFileSelector(sourcefilefolder.getParent().toString(), sourcefilefolder.getName().getBaseName(), destinationfilefolder.toString())); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobCopyFiles.Log.FileCopied", sourcefilefolder.getName().toString(), destinationfilefolder.getName().toString())); } } else if (sourcefilefolder.getType().equals(FileType.FILE) && destination_is_a_file) { // Source is a file, destination is a file destinationfilefolder.copyFrom(sourcefilefolder, new TextOneToOneFileSelector(destinationfilefolder)); } else { // Both source and destination are folders if (isDetailed()) { logDetailed(" "); logDetailed(BaseMessages.getString(PKG, "JobCopyFiles.Log.FetchFolder", sourcefilefolder.toString())); } TextFileSelector textFileSelector = new TextFileSelector(sourcefilefolder, destinationfilefolder, realWildcard, parentJob); try { destinationfilefolder.copyFrom(sourcefilefolder, textFileSelector); } finally { textFileSelector.shutdown(); } } // Remove Files if needed if (remove_source_files && !list_files_remove.isEmpty()) { String sourceFilefoldername = sourcefilefolder.toString(); int trimPathLength = sourceFilefoldername.length() + 1; FileObject removeFile; for (Iterator<String> iter = list_files_remove.iterator(); iter.hasNext() && !parentJob.isStopped();) { String fileremoventry = iter.next(); removeFile = null; // re=null each iteration // Try to get the file relative to the existing connection if (fileremoventry.startsWith(sourceFilefoldername)) { if (trimPathLength < fileremoventry.length()) { removeFile = sourcefilefolder .getChild(fileremoventry.substring(trimPathLength)); } } // Unable to retrieve file through existing connection; Get the file through a new VFS connection if (removeFile == null) { removeFile = KettleVFS.getFileObject(fileremoventry, this); } // Remove ONLY Files if (removeFile.getType() == FileType.FILE) { boolean deletefile = removeFile.delete(); logBasic(" ------ "); if (!deletefile) { logError(" " + BaseMessages.getString(PKG, "JobCopyFiles.Error.Exception.CanRemoveFileFolder", fileremoventry)); } else { if (isDetailed()) { logDetailed(" " + BaseMessages.getString(PKG, "JobCopyFiles.Log.FileFolderRemoved", fileremoventry)); } } } } } // Add files to result files name if (add_result_filesname && !list_add_result.isEmpty()) { String destinationFilefoldername = destinationfilefolder.toString(); int trimPathLength = destinationFilefoldername.length() + 1; FileObject addFile; for (Iterator<String> iter = list_add_result.iterator(); iter.hasNext();) { String fileaddentry = iter.next(); addFile = null; // re=null each iteration // Try to get the file relative to the existing connection if (fileaddentry.startsWith(destinationFilefoldername)) { if (trimPathLength < fileaddentry.length()) { addFile = destinationfilefolder .getChild(fileaddentry.substring(trimPathLength)); } } // Unable to retrieve file through existing connection; Get the file through a new VFS connection if (addFile == null) { addFile = KettleVFS.getFileObject(fileaddentry, this); } // Add ONLY Files if (addFile.getType() == FileType.FILE) { ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, addFile, parentJob.getJobname(), toString()); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); if (isDetailed()) { logDetailed(" ------ "); logDetailed(" " + BaseMessages.getString(PKG, "JobCopyFiles.Log.FileAddedToResultFilesName", fileaddentry)); } } } } } entrystatus = true; } else { // Destination Folder or Parent folder is missing logError(BaseMessages.getString(PKG, "JobCopyFiles.Error.DestinationFolderNotFound", realDestinationFilefoldername)); } } else { logError(BaseMessages.getString(PKG, "JobCopyFiles.Error.SourceFileNotExists", realSourceFilefoldername)); } } catch (FileSystemException fse) { logError(BaseMessages.getString(PKG, "JobCopyFiles.Error.Exception.CopyProcessFileSystemException", fse.getMessage())); Throwable throwable = fse.getCause(); while (throwable != null) { logError(BaseMessages.getString(PKG, "JobCopyFiles.Log.CausedBy", throwable.getMessage())); throwable = throwable.getCause(); } } catch (Exception e) { logError(BaseMessages.getString(PKG, "JobCopyFiles.Error.Exception.CopyProcess", realSourceFilefoldername, realDestinationFilefoldername, e.getMessage()), e); } finally { if (sourcefilefolder != null) { try { sourcefilefolder.close(); sourcefilefolder = null; } catch (IOException ex) { /* Ignore */ } } if (destinationfilefolder != null) { try { destinationfilefolder.close(); destinationfilefolder = null; } catch (IOException ex) { /* Ignore */ } } } return entrystatus; }
From source file:org.pentaho.di.trans.steps.gpload.GPLoad.java
/** * Returns the path to the pathToFile. It should be the same as what was passed but this method will check the file * system to see if the path is valid.//from w ww . jav a 2s. c om * * @param pathToFile * Path to the file to verify. * @param exceptionMessage * The message to use when the path is not provided. * @param checkExistence * When true the path's existence will be verified. * @return * @throws KettleException */ private String getPath(String pathToFile, String exceptionMessage, boolean checkExistenceOfFile) throws KettleException { // Make sure the path is not empty if (Const.isEmpty(pathToFile)) { throw new KettleException(exceptionMessage); } // make sure the variable substitution is not empty pathToFile = environmentSubstitute(pathToFile).trim(); if (Const.isEmpty(pathToFile)) { throw new KettleException(exceptionMessage); } FileObject fileObject = KettleVFS.getFileObject(pathToFile, getTransMeta()); try { // we either check the existence of the file if (checkExistenceOfFile) { if (!fileObject.exists()) { throw new KettleException( BaseMessages.getString(PKG, "GPLoad.Execption.FileDoesNotExist", pathToFile)); } } else { // if the file does not have to exist, the parent, or source folder, does. FileObject parentFolder = fileObject.getParent(); if (parentFolder.exists()) { return KettleVFS.getFilename(fileObject); } else { throw new KettleException(BaseMessages.getString(PKG, "GPLoad.Exception.DirectoryDoesNotExist", parentFolder.getURL().getPath())); } } // if Windows is the OS if (Const.getOS().startsWith("Windows")) { return addQuotes(pathToFile); } else { return KettleVFS.getFilename(fileObject); } } catch (FileSystemException fsex) { throw new KettleException( BaseMessages.getString(PKG, "GPLoad.Exception.GPLoadCommandBuild", fsex.getMessage())); } }
From source file:org.pentaho.di.ui.vfs.hadoopvfsfilechooserdialog.HadoopVfsFileChooserDialog.java
private void initializeConnectionPanel() { if (initialFile != null && initialFile.getName().getScheme().equals(HadoopSpoonPlugin.HDFS_SCHEME)) { // populate the server and port fields try {/*from www. j a v a2s . c o m*/ GenericFileName genericFileName = (GenericFileName) initialFile.getFileSystem().getRoot().getName(); wUrl.setText(genericFileName.getHostName()); wPort.setText(String.valueOf(genericFileName.getPort())); wUserID.setText(genericFileName.getUserName() == null ? "" : genericFileName.getUserName()); //$NON-NLS-1$ wPassword.setText(genericFileName.getPassword() == null ? "" : genericFileName.getPassword()); //$NON-NLS-1$ } catch (FileSystemException fse) { showMessageAndLog(BaseMessages.getString(PKG, "HadoopVfsFileChooserDialog.error"), BaseMessages.getString(PKG, "HadoopVfsFileChooserDialog.FileSystem.error"), fse.getMessage()); } } handleConnectionButton(); }
From source file:org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogHelper.java
public MondrianCatalogHelper(boolean useLegacyDbName) { super();/*from w w w .j a v a2 s . c o m*/ this.useLegacyDbName = useLegacyDbName; try { DefaultFileSystemManager dfsm = (DefaultFileSystemManager) VFS.getManager(); dfsm.addProvider("mondrian", new MondrianVfs()); //$NON-NLS-1$ } catch (FileSystemException e) { logger.error(e.getMessage()); } }
From source file:org.pentaho.platform.web.servlet.PentahoXmlaServlet.java
public PentahoXmlaServlet() { super();/*from ww w . j a va 2s . com*/ if (!cacheMgr.cacheEnabled(CACHE_REGION)) { cacheMgr.addCacheRegion(CACHE_REGION); } repo = PentahoSystem.get(IUnifiedRepository.class); mondrianCatalogService = (MondrianCatalogHelper) PentahoSystem.get(IMondrianCatalogService.class); try { DefaultFileSystemManager dfsm = (DefaultFileSystemManager) VFS.getManager(); if (!dfsm.hasProvider("mondrian")) { dfsm.addProvider("mondrian", new MondrianVfs()); } } catch (FileSystemException e) { logger.error(e.getMessage()); } }
From source file:org.pentaho.platform.web.servlet.PentahoXmlaServlet.java
@Override protected CatalogLocator makeCatalogLocator(ServletConfig servletConfig) { return new ServletContextCatalogLocator(servletConfig.getServletContext()) { @Override/* w ww . ja v a 2 s . c om*/ public String locate(String catalogPath) { if (catalogPath.startsWith("mondrian:")) { //$NON-NLS-1$ try { FileSystemManager fsManager = VFS.getManager(); SolutionRepositoryVfsFileObject catalog = (SolutionRepositoryVfsFileObject) fsManager .resolveFile(catalogPath); catalogPath = "solution:" + catalog.getFileRef(); } catch (FileSystemException e) { logger.error(e.getMessage()); } } else { catalogPath = super.locate(catalogPath); } return catalogPath; } }; }
From source file:plugin.games.data.trans.step.hadoopfileoutput.HadoopVfsFileChooserDialog.java
private void initializeConnectionPanel() { if (initialFile != null && initialFile instanceof HDFSFileObject) { // populate the server and port fields try {//from w w w.j a va2s .c o m GenericFileName genericFileName = (GenericFileName) initialFile.getFileSystem().getRoot().getName(); wUrl.setText(genericFileName.getHostName()); wPort.setText(String.valueOf(genericFileName.getPort())); wUserID.setText(genericFileName.getUserName() == null ? "" : genericFileName.getUserName()); //$NON-NLS-1$ wPassword.setText(genericFileName.getPassword() == null ? "" : genericFileName.getPassword()); //$NON-NLS-1$ } catch (FileSystemException fse) { showMessageAndLog("HadoopVfsFileChooserDialog.error", "HadoopVfsFileChooserDialog.FileSystem.error", fse.getMessage()); } } handleConnectionButton(); }
From source file:rsc.backend.connections.sshConnection.SSHConnection.java
public void connect() throws ConnectionException { if (isConnected()) { return;/*w w w . j a v a 2s .c o m*/ } if (fs == null) { try { fs = VFS.getManager() .resolveFile("sftp://" + username + ":" + password + "@" + hostname + ":" + port + "/") .getFileSystem(); } catch (FileSystemException ex) { RSC.log(Level.SEVERE, "error connecting ssh-filesystem", ex); if (fs != null) { fs.getFileSystemManager().closeFileSystem(fs); fs = null; } session = null; throw new ConnectionException(); } } if (session == null) { createSession(); } UserInfo ui = new MyUserInfo(); session.setUserInfo(ui); try { session.connect(30000); } catch (JSchException ex) { RSC.log(Level.SEVERE, "error connecting ssh", ex); if (fs != null) { fs.getFileSystemManager().closeFileSystem(fs); fs = null; } session = null; System.out.println("cant connect: " + ex.getMessage()); throw new ConnectionException(); } for (ConnectionListener l : cListener) { l.connectionConnect(); } }