use of org.apache.commons.vfs2.FileSystemManager in project pentaho-kettle by pentaho.
the class KettleVFS method startsWithScheme.
/**
* Check if filename starts with one of the known protocols like file: zip: ram: smb: jar: etc.
* If yes, return true otherwise return false
*
* @param vfsFileName
* @return boolean
*/
public static boolean startsWithScheme(String vfsFileName) {
FileSystemManager fsManager = getInstance().getFileSystemManager();
boolean found = false;
String[] schemes = fsManager.getSchemes();
for (int i = 0; i < schemes.length; i++) {
if (vfsFileName.startsWith(schemes[i] + ":")) {
found = true;
break;
}
}
return found;
}
use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.
the class VFSUtils method attachFileSystemOptions.
public static FileSystemOptions attachFileSystemOptions(Map<String, String> options, FileSystemManager fsManager) throws FileSystemException {
if (options == null) {
return null;
}
FileSystemOptions opts = new FileSystemOptions();
DelegatingFileSystemOptionsBuilder delegate = new DelegatingFileSystemOptionsBuilder(fsManager);
// sftp configs
for (Map.Entry<String, String> entry : options.entrySet()) {
for (VFSConstants.SFTP_FILE_OPTION option : VFSConstants.SFTP_FILE_OPTION.values()) {
if (entry.getKey().equals(option.toString()) && entry.getValue() != null) {
delegate.setConfigString(opts, VFSConstants.SCHEME_SFTP, entry.getKey().toLowerCase(), entry.getValue());
}
}
}
FtpsFileSystemConfigBuilder configBuilder = FtpsFileSystemConfigBuilder.getInstance();
// ftp and ftps configs
String passiveMode = options.get(PASSIVE_MODE);
if (passiveMode != null) {
configBuilder.setPassiveMode(opts, Boolean.parseBoolean(passiveMode));
}
// ftps configs
String implicitMode = options.get(IMPLICIT_MODE);
if (implicitMode != null) {
if (Boolean.parseBoolean(implicitMode)) {
configBuilder.setFtpsMode(opts, FtpsMode.IMPLICIT);
} else {
configBuilder.setFtpsMode(opts, FtpsMode.EXPLICIT);
}
}
String protectionMode = options.get(PROTECTION_MODE);
if ("P".equalsIgnoreCase(protectionMode)) {
configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.P);
} else if ("C".equalsIgnoreCase(protectionMode)) {
configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.C);
} else if ("S".equalsIgnoreCase(protectionMode)) {
configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.S);
} else if ("E".equalsIgnoreCase(protectionMode)) {
configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.E);
}
String keyStore = options.get(KEY_STORE);
if (keyStore != null) {
configBuilder.setKeyStore(opts, keyStore);
}
String trustStore = options.get(TRUST_STORE);
if (trustStore != null) {
configBuilder.setTrustStore(opts, trustStore);
}
String keyStorePassword = options.get(KS_PASSWD);
if (keyStorePassword != null) {
configBuilder.setKeyStorePW(opts, keyStorePassword);
}
String trustStorePassword = options.get(TS_PASSWD);
if (trustStorePassword != null) {
configBuilder.setTrustStorePW(opts, trustStorePassword);
}
String keyPassword = options.get(KEY_PASSWD);
if (keyPassword != null) {
configBuilder.setKeyPW(opts, keyPassword);
}
if (options.get(VFSConstants.FILE_TYPE) != null) {
delegate.setConfigString(opts, options.get(VFSConstants.SCHEME), VFSConstants.FILE_TYPE, options.get(VFSConstants.FILE_TYPE));
}
return opts;
}
use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.
the class VFSUtils method releaseLock.
/**
* Release a file item lock acquired either by the VFS listener or a sender
*
* @param fsManager which is used to resolve the processed file
* @param fo representing the processed file
* @param fso represents file system options used when resolving file from file system manager.
*/
public static void releaseLock(FileSystemManager fsManager, FileObject fo, FileSystemOptions fso) {
String fullPath = fo.getName().getURI();
try {
int pos = fullPath.indexOf('?');
if (pos > -1) {
fullPath = fullPath.substring(0, pos);
}
FileObject lockObject = fsManager.resolveFile(fullPath + LOCK_FILE_SUFFIX, fso);
if (lockObject.exists()) {
lockObject.delete();
}
} catch (FileSystemException e) {
log.error("Couldn't release the lock for the file : " + maskURLPassword(fo.getName().getURI()) + " after processing");
}
}
use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.
the class VFSUtils method releaseFail.
public static void releaseFail(FileSystemManager fsManager, FileObject fo, FileSystemOptions fso) {
try {
String fullPath = fo.getName().getURI();
int pos = fullPath.indexOf('?');
if (pos > -1) {
fullPath = fullPath.substring(0, pos);
}
FileObject failObject = fsManager.resolveFile(fullPath + FAIL_FILE_SUFFIX, fso);
if (failObject.exists()) {
failObject.delete();
}
} catch (FileSystemException e) {
log.error("Couldn't release the fail for the file : " + maskURLPassword(fo.getName().getURI()));
}
}
use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.
the class VFSUtils method markFailRecord.
public static synchronized void markFailRecord(FileSystemManager fsManager, FileObject fo, FileSystemOptions fso) {
// generate a random fail value to ensure that there are no two parties
// processing the same file
byte[] failValue = (Long.toString((new Date()).getTime())).getBytes();
try {
String fullPath = getFullPath(fo);
FileObject failObject = fsManager.resolveFile(fullPath + FAIL_FILE_SUFFIX, fso);
if (!failObject.exists()) {
failObject.createFile();
}
// write a lock file before starting of the processing, to ensure that the
// item is not processed by any other parties
OutputStream stream = failObject.getContent().getOutputStream();
try {
stream.write(failValue);
stream.flush();
} catch (IOException e) {
failObject.delete();
log.error("Couldn't create the fail file before processing the file " + maskURLPassword(fullPath), e);
} finally {
try {
stream.close();
} catch (IOException e) {
log.debug("Error closing stream", e);
}
failObject.close();
}
} catch (FileSystemException fse) {
log.error("Cannot get the lock for the file : " + maskURLPassword(fo.getName().getURI()) + " before processing");
}
}
Aggregations