List of usage examples for org.apache.commons.vfs2 FileObject toString
public String toString()
From source file:org.wso2.carbon.inbound.endpoint.protocol.file.FilePollingConsumer.java
/** * Do the post processing actions/* w ww .jav a 2 s .co m*/ * * @param fileObject * @throws synapseException */ private void moveOrDeleteAfterProcessing(FileObject fileObject) throws SynapseException { String moveToDirectoryURI = null; try { switch (lastCycle) { case 1: if ("MOVE".equals(vfsProperties.getProperty(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_PROCESS))) { moveToDirectoryURI = vfsProperties.getProperty(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_PROCESS); //Postfix the date given timestamp format String strSubfoldertimestamp = vfsProperties.getProperty(VFSConstants.SUBFOLDER_TIMESTAMP); if (strSubfoldertimestamp != null) { try { SimpleDateFormat sdf = new SimpleDateFormat(strSubfoldertimestamp); String strDateformat = sdf.format(new Date()); int iIndex = moveToDirectoryURI.indexOf("?"); if (iIndex > -1) { moveToDirectoryURI = moveToDirectoryURI.substring(0, iIndex) + strDateformat + moveToDirectoryURI.substring(iIndex, moveToDirectoryURI.length()); } else { moveToDirectoryURI += strDateformat; } } catch (Exception e) { log.warn("Error generating subfolder name with date", e); } } } break; case 2: if ("MOVE".equals(vfsProperties.getProperty(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_FAILURE))) { moveToDirectoryURI = vfsProperties.getProperty(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILURE); } break; default: return; } if (moveToDirectoryURI != null) { FileObject moveToDirectory = fsManager.resolveFile(moveToDirectoryURI, fso); String prefix; if (vfsProperties.getProperty(VFSConstants.TRANSPORT_FILE_MOVE_TIMESTAMP_FORMAT) != null) { prefix = new SimpleDateFormat( vfsProperties.getProperty(VFSConstants.TRANSPORT_FILE_MOVE_TIMESTAMP_FORMAT)) .format(new Date()); } else { prefix = ""; } //Forcefully create the folder(s) if does not exists String strForceCreateFolder = vfsProperties.getProperty(VFSConstants.FORCE_CREATE_FOLDER); if (strForceCreateFolder != null && strForceCreateFolder.toLowerCase().equals("true") && !moveToDirectory.exists()) { moveToDirectory.createFolder(); } FileObject dest = moveToDirectory.resolveFile(prefix + fileObject.getName().getBaseName()); if (log.isDebugEnabled()) { log.debug("Moving to file :" + VFSUtils.maskURLPassword(dest.getName().getURI())); } try { fileObject.moveTo(dest); if (VFSUtils.isFailRecord(fsManager, fileObject)) { VFSUtils.releaseFail(fsManager, fileObject); } } catch (FileSystemException e) { if (!VFSUtils.isFailRecord(fsManager, fileObject)) { VFSUtils.markFailRecord(fsManager, fileObject); } log.error("Error moving file : " + VFSUtils.maskURLPassword(fileObject.toString()) + " to " + VFSUtils.maskURLPassword(moveToDirectoryURI), e); } } else { try { if (log.isDebugEnabled()) { log.debug("Deleting file :" + VFSUtils.maskURLPassword(fileObject.toString())); } fileObject.close(); if (!fileObject.delete()) { String msg = "Cannot delete file : " + VFSUtils.maskURLPassword(fileObject.toString()); log.error(msg); throw new SynapseException(msg); } } catch (FileSystemException e) { log.error("Error deleting file : " + VFSUtils.maskURLPassword(fileObject.toString()), e); } } } catch (FileSystemException e) { if (!VFSUtils.isFailRecord(fsManager, fileObject)) { VFSUtils.markFailRecord(fsManager, fileObject); log.error("Error resolving directory to move after processing : " + VFSUtils.maskURLPassword(moveToDirectoryURI), e); } } }
From source file:org.wso2.carbon.transport.filesystem.connector.server.FileSystemConsumer.java
/** * Do the post processing actions./* w w w .j av a 2 s. c om*/ * * @param file The file object which needs to be post processed * @param processFailed Whether processing of file failed */ synchronized void postProcess(FileObject file, boolean processFailed) throws FileSystemServerConnectorException { String moveToDirectoryURI = null; FileType fileType = getFileType(file); if (!processFailed) { if (postProcessAction.equals(Constants.ACTION_MOVE)) { moveToDirectoryURI = fileProperties.get(Constants.MOVE_AFTER_PROCESS); } } else { if (postFailureAction.equals(Constants.ACTION_MOVE)) { moveToDirectoryURI = fileProperties.get(Constants.MOVE_AFTER_FAILURE); } } if (moveToDirectoryURI != null) { try { if (getFileType(fsManager.resolveFile(moveToDirectoryURI, fso)) == FileType.FILE) { moveToDirectoryURI = null; if (processFailed) { postFailureAction = Constants.ACTION_NONE; } else { postProcessAction = Constants.ACTION_NONE; } if (log.isDebugEnabled()) { log.debug( "Cannot move file because provided location is not a folder. File is kept at source"); } } } catch (FileSystemException e) { errorHandler .handleError( new FileSystemServerConnectorException( "Error occurred when resolving move destination file: " + FileTransportUtils.maskURLPassword(listeningDirURI), e), null, null); } } try { if (!(moveToDirectoryURI == null || fileType == FileType.FOLDER)) { FileObject moveToDirectory; String relativeName = file.getName().getURI().split(listeningDir.getName().getURI())[1]; int index = relativeName.lastIndexOf(File.separator); moveToDirectoryURI += relativeName.substring(0, index); moveToDirectory = fsManager.resolveFile(moveToDirectoryURI, fso); String prefix; if (fileProperties.get(Constants.MOVE_TIMESTAMP_FORMAT) != null) { prefix = new SimpleDateFormat(fileProperties.get(Constants.MOVE_TIMESTAMP_FORMAT)) .format(new Date()); } else { prefix = ""; } //Forcefully create the folder(s) if does not exists String strForceCreateFolder = fileProperties.get(Constants.FORCE_CREATE_FOLDER); if (strForceCreateFolder != null && strForceCreateFolder.equalsIgnoreCase("true") && !moveToDirectory.exists()) { moveToDirectory.createFolder(); } FileObject dest = moveToDirectory.resolveFile(prefix + file.getName().getBaseName()); if (log.isDebugEnabled()) { log.debug("Moving to file :" + FileTransportUtils.maskURLPassword(dest.getName().getURI())); } if (log.isInfoEnabled()) { log.info("Moving file :" + FileTransportUtils.maskURLPassword(file.getName().getBaseName())); } try { file.moveTo(dest); if (isFailRecord(file)) { releaseFail(file); } } catch (FileSystemException e) { if (!isFailRecord(file)) { markFailRecord(file); } errorHandler.handleError( new FileSystemServerConnectorException( "Error moving file : " + FileTransportUtils.maskURLPassword(file.toString()) + " to " + FileTransportUtils.maskURLPassword(moveToDirectoryURI), e), null, null); } } else { if (log.isDebugEnabled()) { log.debug("Deleting file :" + FileTransportUtils.maskURLPassword(file.getName().getBaseName())); } if (log.isInfoEnabled()) { log.info("Deleting file :" + FileTransportUtils.maskURLPassword(file.getName().getBaseName())); } try { if (!file.delete()) { if (log.isDebugEnabled()) { log.debug("Could not delete file : " + FileTransportUtils.maskURLPassword(file.getName().getBaseName())); } } else { if (isFailRecord(file)) { releaseFail(file); } } } catch (FileSystemException e) { errorHandler.handleError( new FileSystemServerConnectorException("Could not delete file : " + FileTransportUtils.maskURLPassword(file.getName().getBaseName()), e), null, null); } } } catch (FileSystemException e) { if (!isFailRecord(file)) { markFailRecord(file); errorHandler.handleError( new FileSystemServerConnectorException("Error resolving directory to move file : " + FileTransportUtils.maskURLPassword(moveToDirectoryURI), e), null, null); } } }
From source file:org.wso2.carbon.transport.remotefilesystem.server.RemoteFileSystemConsumer.java
/** * Do the post processing actions./*from ww w. j av a2 s .c om*/ * * @param file The file object which needs to be post processed * @param processSucceed Whether processing of file passed or not. */ synchronized void postProcess(FileObject file, boolean processSucceed) throws RemoteFileSystemConnectorException { String moveToDirectoryURI = null; FileType fileType = getFileType(file); if (processSucceed) { if (postProcessAction.equals(Constants.ACTION_MOVE)) { moveToDirectoryURI = fileProperties.get(Constants.MOVE_AFTER_PROCESS); } } else { if (postFailureAction.equals(Constants.ACTION_MOVE)) { moveToDirectoryURI = fileProperties.get(Constants.MOVE_AFTER_FAILURE); } } if (moveToDirectoryURI != null) { try { if (getFileType(fsManager.resolveFile(moveToDirectoryURI, fso)) == FileType.FILE) { moveToDirectoryURI = null; if (processSucceed) { postProcessAction = Constants.ACTION_NONE; } else { postFailureAction = Constants.ACTION_NONE; } log.warn("[" + serviceName + "] Cannot move file because provided location is not a folder." + " File is kept at source."); } } catch (FileSystemException e) { remoteFileSystemListener.onError(new RemoteFileSystemConnectorException( "Error occurred when resolving move destination file: " + FileTransportUtils.maskURLPassword(listeningDirURI), e)); } } if (postProcessAction.equals(Constants.ACTION_NONE) && fileType == FileType.FOLDER) { return; } try { if (!(moveToDirectoryURI == null || fileType == FileType.FOLDER)) { FileObject moveToDirectory; String relativeName = file.getName().getURI().split(listeningDir.getName().getURI())[1]; int index = relativeName.lastIndexOf(File.separator); moveToDirectoryURI += relativeName.substring(0, index); moveToDirectory = fsManager.resolveFile(moveToDirectoryURI, fso); String prefix; if (fileProperties.get(Constants.MOVE_TIMESTAMP_FORMAT) != null) { prefix = new SimpleDateFormat(fileProperties.get(Constants.MOVE_TIMESTAMP_FORMAT)) .format(new Date()); } else { prefix = ""; } //Forcefully create the folder(s) if does not exists String strForceCreateFolder = fileProperties.get(Constants.FORCE_CREATE_FOLDER); if (strForceCreateFolder != null && strForceCreateFolder.equalsIgnoreCase("true") && !moveToDirectory.exists()) { moveToDirectory.createFolder(); } FileObject destination = moveToDirectory.resolveFile(prefix + file.getName().getBaseName()); if (log.isDebugEnabled()) { log.debug("Moving file: " + FileTransportUtils.maskURLPassword(file.getName().getBaseName())); } try { file.moveTo(destination); if (isFailRecord(file)) { releaseFail(file); } } catch (FileSystemException e) { if (!isFailRecord(file)) { markFailRecord(file); } remoteFileSystemListener.onError(new RemoteFileSystemConnectorException("[" + serviceName + "] Error moving file: " + FileTransportUtils.maskURLPassword(file.toString()) + " to " + FileTransportUtils.maskURLPassword(moveToDirectoryURI), e)); } } else { if (log.isDebugEnabled()) { log.debug("Deleting file: " + FileTransportUtils.maskURLPassword(file.getName().getBaseName())); } try { if (!file.delete()) { if (log.isDebugEnabled()) { log.debug("Could not delete file: " + FileTransportUtils.maskURLPassword(file.getName().getBaseName())); } } else { if (isFailRecord(file)) { releaseFail(file); } } } catch (FileSystemException e) { remoteFileSystemListener.onError( new RemoteFileSystemConnectorException("[" + serviceName + "] Could not delete file: " + FileTransportUtils.maskURLPassword(file.getName().getBaseName()), e)); } } } catch (FileSystemException e) { if (!isFailRecord(file)) { markFailRecord(file); remoteFileSystemListener.onError(new RemoteFileSystemConnectorException( "[" + serviceName + "] Error resolving directory to move file : " + FileTransportUtils.maskURLPassword(moveToDirectoryURI), e)); } } }
From source file:sf.net.experimaestro.manager.ValueType.java
static public Json wrap(FileObject value) { return wrapString(value.toString(), XP_FILE); }