Search in sources :

Example 1 with DelegatingFileSystemOptionsBuilder

use of org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder in project jackrabbit by apache.

the class VFSDataStore method createFileSystemOptions.

/**
 * Builds and returns {@link FileSystemOptions} instance which is used when resolving the {@link #baseFolder}
 * during the initialization.
 * If {@link #fileSystemOptionsProperties} is available, this scans all the property key names starting with {@link #FILE_SYSTEM_OPTIONS_PROP_PREFIX}
 * and uses the rest of the key name after the {@link #FILE_SYSTEM_OPTIONS_PROP_PREFIX} as the combination of scheme and property name
 * when building a {@link FileSystemOptions} using {@link DelegatingFileSystemOptionsBuilder}.
 * @return {@link FileSystemOptions} instance which is used when resolving the {@link #baseFolder} during the initialization
 * @throws RepositoryException if any file system exception occurs
 */
protected FileSystemOptions createFileSystemOptions() throws RepositoryException {
    FileSystemOptions fso = null;
    if (fileSystemOptionsProperties != null) {
        try {
            fso = new FileSystemOptions();
            DelegatingFileSystemOptionsBuilder delegate = new DelegatingFileSystemOptionsBuilder(getFileSystemManager());
            String key;
            String schemeDotPropName;
            String scheme;
            String propName;
            String value;
            int offset;
            for (Enumeration<?> e = fileSystemOptionsProperties.propertyNames(); e.hasMoreElements(); ) {
                key = (String) e.nextElement();
                if (key.startsWith(FILE_SYSTEM_OPTIONS_PROP_PREFIX)) {
                    value = fileSystemOptionsProperties.getProperty(key);
                    schemeDotPropName = key.substring(FILE_SYSTEM_OPTIONS_PROP_PREFIX.length());
                    offset = schemeDotPropName.indexOf('.');
                    if (offset > 0) {
                        scheme = schemeDotPropName.substring(0, offset);
                        propName = schemeDotPropName.substring(offset + 1);
                        delegate.setConfigString(fso, scheme, propName, value);
                    } else {
                        LOG.warn("Ignoring an FileSystemOptions property in invalid format. Key: {}, Value: {}", key, value);
                    }
                }
            }
        } catch (FileSystemException e) {
            throw new RepositoryException("Could not create File System Options.", e);
        }
    }
    return fso;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DelegatingFileSystemOptionsBuilder(org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder) RepositoryException(javax.jcr.RepositoryException) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 2 with DelegatingFileSystemOptionsBuilder

use of org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder in project wso2-synapse by wso2.

the class VFSUtils method attachFileSystemOptions.

public static FileSystemOptions attachFileSystemOptions(Map<String, String> options, FileSystemManager fsManager) throws FileSystemException, InstantiationException, IllegalAccessException {
    if (options == null) {
        return null;
    }
    FileSystemOptions opts = new FileSystemOptions();
    DelegatingFileSystemOptionsBuilder delegate = new DelegatingFileSystemOptionsBuilder(fsManager);
    if (VFSConstants.SCHEME_SFTP.equals(options.get(VFSConstants.SCHEME))) {
        for (String key : options.keySet()) {
            for (VFSConstants.SFTP_FILE_OPTION o : VFSConstants.SFTP_FILE_OPTION.values()) {
                if (key.equals(o.toString()) && null != options.get(key)) {
                    delegate.setConfigString(opts, VFSConstants.SCHEME_SFTP, key.toLowerCase(), options.get(key));
                }
            }
        }
    }
    if (options.get(VFSConstants.FILE_TYPE) != null) {
        delegate.setConfigString(opts, options.get(VFSConstants.SCHEME), VFSConstants.FILE_TYPE, options.get(VFSConstants.FILE_TYPE));
    }
    return opts;
}
Also used : DelegatingFileSystemOptionsBuilder(org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 3 with DelegatingFileSystemOptionsBuilder

use of org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder in project jackrabbit by apache.

the class VFSFileSystem method createFileSystemOptions.

/**
 * Builds and returns {@link FileSystemOptions} instance which is used when resolving the {@link #baseFolder}
 * during the initialization.
 * If {@link #fileSystemOptionsProperties} is available, this scans all the property key names starting with {@link #FILE_SYSTEM_OPTIONS_PROP_PREFIX}
 * and uses the rest of the key name after the {@link #FILE_SYSTEM_OPTIONS_PROP_PREFIX} as the combination of scheme and property name
 * when building a {@link FileSystemOptions} using {@link DelegatingFileSystemOptionsBuilder}.
 * @return {@link FileSystemOptions} instance which is used when resolving the {@link #baseFolder} during the initialization
 * @throws FileSystemException if any file system exception occurs
 */
protected FileSystemOptions createFileSystemOptions() throws FileSystemException {
    FileSystemOptions fso = null;
    if (fileSystemOptionsProperties != null) {
        try {
            fso = new FileSystemOptions();
            DelegatingFileSystemOptionsBuilder delegate = new DelegatingFileSystemOptionsBuilder(getFileSystemManager());
            String key;
            String schemeDotPropName;
            String scheme;
            String propName;
            String value;
            int offset;
            for (Enumeration<?> e = fileSystemOptionsProperties.propertyNames(); e.hasMoreElements(); ) {
                key = (String) e.nextElement();
                if (key.startsWith(FILE_SYSTEM_OPTIONS_PROP_PREFIX)) {
                    value = fileSystemOptionsProperties.getProperty(key);
                    schemeDotPropName = key.substring(FILE_SYSTEM_OPTIONS_PROP_PREFIX.length());
                    offset = schemeDotPropName.indexOf('.');
                    if (offset > 0) {
                        scheme = schemeDotPropName.substring(0, offset);
                        propName = schemeDotPropName.substring(offset + 1);
                        delegate.setConfigString(fso, scheme, propName, value);
                    } else {
                        log.warn("Ignoring an FileSystemOptions property in invalid format. Key: {}, Value: {}", key, value);
                    }
                }
            }
        } catch (org.apache.commons.vfs2.FileSystemException e) {
            throw new FileSystemException("Could not create File System Options.", e);
        }
    }
    return fso;
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) DelegatingFileSystemOptionsBuilder(org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Aggregations

FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)3 DelegatingFileSystemOptionsBuilder (org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder)3 RepositoryException (javax.jcr.RepositoryException)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)1