Example usage for org.apache.commons.vfs2.provider UriParser extractScheme

List of usage examples for org.apache.commons.vfs2.provider UriParser extractScheme

Introduction

In this page you can find the example usage for org.apache.commons.vfs2.provider UriParser extractScheme.

Prototype

public static String extractScheme(final String uri) 

Source Link

Document

Extracts the scheme from a URI.

Usage

From source file:net.sf.jabb.util.vfs.VfsUtility.java

/**
 * Extracts the scheme from a URI./*from   w ww.  j ava 2 s  . com*/
 *
 * @param uri The URI.
 * @return The scheme name. Returns null if there is no scheme.
 */
static public String extractScheme(String uri) {
    return UriParser.extractScheme(uri);
}

From source file:com.sonicle.webtop.vfs.VfsManager.java

private StoreFileSystem createFileSystem(Store store) throws URISyntaxException {
    String uri = null;//www.j a  v a  2s.co m

    if (store.getBuiltIn()) {
        VfsSettings.MyDocumentsUriTemplateValues tpl = new VfsSettings.MyDocumentsUriTemplateValues();
        //tpl.HOME_PATH = WT.getHomePath();
        //TODO: gestire variabili per HOME_PATH, SERVICE_HOME_PATH
        tpl.SERVICE_ID = SERVICE_ID;
        tpl.DOMAIN_ID = store.getDomainId();
        tpl.USER_ID = store.getUserId();

        VfsServiceSettings vus = new VfsServiceSettings(SERVICE_ID, store.getDomainId());
        uri = vus.getMyDocumentsUri(tpl);
        if (StringUtils.isBlank(uri)) {
            uri = WT.getServiceHomePath(SERVICE_ID) + "mydocuments/" + store.getUserId() + "/";
        }
        return new DefaultSFS(uri, null, true);

    } else {
        uri = store.getUri();
        String scheme = UriParser.extractScheme(uri);
        switch (scheme) {
        case "ftp":
            return new FtpSFS(uri, store.getParameters());
        case "sftp":
            return new SftpSFS(uri, store.getParameters());
        case "ftps":
            return new FtpsSFS(uri, store.getParameters());
        case "dropbox":
            return new DropboxSFS(uri, store.getParameters());
        case "googledrive":
            return new GoogleDriveSFS(uri, store.getParameters());
        default:
            return new DefaultSFS(uri, store.getParameters());
        }
    }
}

From source file:com.sonicle.webtop.vfs.VfsManager.java

private void checkRightsOnStoreSchema(String uri) {
    String scheme = UriParser.extractScheme(uri);
    switch (scheme) {
    case "file":
        RunContext.ensureIsPermitted(SERVICE_ID, "STORE_FILE", "CREATE");
        break;//  w  w  w . j  a  va 2s . c  om
    case "dropbox":
    case "googledrive":
        RunContext.ensureIsPermitted(SERVICE_ID, "STORE_CLOUD", "CREATE");
        break;
    default:
        RunContext.ensureIsPermitted(SERVICE_ID, "STORE_OTHER", "CREATE");
    }
}

From source file:org.apache.synapse.commons.vfs.VFSOutTransportInfo.java

/**
 * Constructs the VFSOutTransportInfo containing the information about the file to which the
 * response has to be submitted to.//from  ww  w.j  av a2s.co  m
 * 
 * @param outFileURI URI of the file to which the message is delivered
 */
public VFSOutTransportInfo(String outFileURI, boolean fileLocking) {

    if (outFileURI.startsWith(VFSConstants.VFS_PREFIX)) {
        String vfsURI = outFileURI.substring(VFSConstants.VFS_PREFIX.length());
        String queryParams = UriParser.extractQueryString(new StringBuilder(vfsURI));

        //Lets get rid of unwanted query params and clean the URI
        if (null != queryParams && !"".equals(queryParams) && vfsURI.contains(VFSConstants.APPEND)) {
            this.outFileURI = cleanURI(vfsURI, queryParams, outFileURI);
        } else {
            this.outFileURI = vfsURI;
        }
    } else {
        this.outFileURI = outFileURI;
    }

    Map<String, String> properties = BaseUtils.getEPRProperties(outFileURI);

    String scheme = UriParser.extractScheme(this.outFileURI);
    properties.put(VFSConstants.SCHEME, scheme);
    setOutFileSystemOptionsMap(properties);

    if (properties.containsKey(VFSConstants.SUBFOLDER_TIMESTAMP)) {
        String strSubfolderFormat = properties.get(VFSConstants.SUBFOLDER_TIMESTAMP);
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(strSubfolderFormat);
            String strDateformat = sdf.format(new Date());
            int iIndex = this.outFileURI.indexOf("?");
            if (iIndex > -1) {
                this.outFileURI = this.outFileURI.substring(0, iIndex) + strDateformat
                        + this.outFileURI.substring(iIndex, this.outFileURI.length());
            } else {
                this.outFileURI += strDateformat;
            }
        } catch (Exception e) {
            log.warn("Error generating subfolder name with date", e);
        }
    }

    if (properties.containsKey(VFSConstants.MAX_RETRY_COUNT)) {
        String strMaxRetryCount = properties.get(VFSConstants.MAX_RETRY_COUNT);
        maxRetryCount = Integer.parseInt(strMaxRetryCount);
    } else {
        maxRetryCount = VFSConstants.DEFAULT_MAX_RETRY_COUNT;
    }

    forceCreateFolder = false;
    if (properties.containsKey(VFSConstants.FORCE_CREATE_FOLDER)) {
        String strForceCreateFolder = properties.get(VFSConstants.FORCE_CREATE_FOLDER);
        if (strForceCreateFolder != null && strForceCreateFolder.toLowerCase().equals("true")) {
            forceCreateFolder = true;
        }
    }

    if (properties.containsKey(VFSConstants.RECONNECT_TIMEOUT)) {
        String strReconnectTimeout = properties.get(VFSConstants.RECONNECT_TIMEOUT);
        reconnectTimeout = Long.parseLong(strReconnectTimeout) * 1000;
    } else {
        reconnectTimeout = VFSConstants.DEFAULT_RECONNECT_TIMEOUT;
    }

    if (properties.containsKey(VFSConstants.TRANSPORT_FILE_LOCKING)) {
        String strFileLocking = properties.get(VFSConstants.TRANSPORT_FILE_LOCKING);
        if (VFSConstants.TRANSPORT_FILE_LOCKING_ENABLED.equals(strFileLocking)) {
            fileLocking = true;
        } else if (VFSConstants.TRANSPORT_FILE_LOCKING_DISABLED.equals(strFileLocking)) {
            fileLocking = false;
        }
    } else {
        this.fileLocking = fileLocking;
    }

    if (properties.containsKey(VFSConstants.TRANSPORT_FILE_SEND_FILE_LOCKING)) {
        String strSendLocking = properties.get(VFSConstants.TRANSPORT_FILE_SEND_FILE_LOCKING);
        sendFileSynchronously = Boolean.parseBoolean(strSendLocking);
    } else {
        sendFileSynchronously = false;
    }

    if (properties.containsKey(VFSConstants.APPEND)) {
        String strAppend = properties.get(VFSConstants.APPEND);
        append = Boolean.parseBoolean(strAppend);
    }

    if (log.isDebugEnabled()) {
        log.debug("Using the fileURI        : " + this.outFileURI);
        log.debug("Using the maxRetryCount  : " + maxRetryCount);
        log.debug("Using the reconnectionTimeout : " + reconnectTimeout);
        log.debug("Using the append         : " + append);
        log.debug("File locking             : " + (this.fileLocking ? "ON" : "OFF"));
    }
}

From source file:org.apache.synapse.commons.vfs.VFSUtils.java

public static Map<String, String> parseSchemeFileOptions(String fileURI, ParameterInclude params) {
    String scheme = UriParser.extractScheme(fileURI);
    if (scheme == null) {
        return null;
    }//from w ww . ja  va  2 s .  c  o m

    HashMap<String, String> schemeFileOptions = new HashMap<String, String>();
    schemeFileOptions.put(VFSConstants.SCHEME, scheme);

    try {
        addOptions(scheme, schemeFileOptions, params);
    } catch (AxisFault axisFault) {
        log.error("Error while loading VFS parameter. " + axisFault.getMessage());
    }

    return schemeFileOptions;
}

From source file:org.pentaho.big.data.kettle.plugins.formats.impl.avro.BaseAvroStepDialog.java

protected void updateLocation() {
    String pathText = wPath.getText();
    String scheme = pathText.isEmpty() ? HDFS_SCHEME : UriParser.extractScheme(pathText);
    if (scheme != null) {
        try {/*w  ww.  j a  va 2 s.  c  o m*/
            List<VFSScheme> availableVFSSchemes = getAvailableVFSSchemes();
            for (int i = 0; i < availableVFSSchemes.size(); i++) {
                VFSScheme s = availableVFSSchemes.get(i);
                if (scheme.equals(s.getScheme())) {
                    wLocation.select(i);
                    selectedVFSScheme = s;
                }
            }
        } catch (KettleFileException ex) {
            log.logError(getBaseMsg("AvroInputDialog.FileBrowser.KettleFileException"));
        } catch (FileSystemException ex) {
            log.logError(getBaseMsg("AvroInputDialog.FileBrowser.FileSystemException"));
        }
    }
    // do we have preview button?
    if (wPreview != null) {
        //update preview button
        wPreview.setEnabled(!pathText.isEmpty());
    }
}

From source file:org.pentaho.big.data.kettle.plugins.formats.impl.avro.input.AvroInputDialog.java

protected void updateSchemaLocation() {
    String schemaPath = wSchemaPath.getText();
    String scheme = schemaPath.isEmpty() ? HDFS_SCHEME : UriParser.extractScheme(schemaPath);
    if (scheme != null) {
        try {//from  ww  w.j  av a 2s.co  m
            List<VFSScheme> availableVFSSchemes = getAvailableVFSSchemes();
            for (int i = 0; i < availableVFSSchemes.size(); i++) {
                VFSScheme s = availableVFSSchemes.get(i);
                if (scheme.equals(s.getScheme())) {
                    wSchemaLocation.select(i);
                    selectedSchemaVFSScheme = s;
                }
            }
        } catch (KettleFileException ex) {
            log.logError(getBaseMsg("AvroInputDialog.FileBrowser.KettleFileException"));
        } catch (FileSystemException ex) {
            log.logError(getBaseMsg("AvroInputDialog.FileBrowser.FileSystemException"));
        }
    }
    // do we have preview button?
    if (wPreview != null) {
        //update preview button
        wPreview.setEnabled(!wPath.getText().isEmpty());
    }
}

From source file:org.pentaho.big.data.kettle.plugins.formats.impl.orc.BaseOrcStepDialog.java

private void updateLocation() {
    String pathText = wPath.getText();
    String scheme = pathText.isEmpty() ? HDFS_SCHEME : UriParser.extractScheme(pathText);
    if (scheme != null) {
        try {//from w  w w . j a va2 s  .  c o m
            List<VFSScheme> availableVFSSchemes = getAvailableVFSSchemes();
            for (int i = 0; i < availableVFSSchemes.size(); i++) {
                VFSScheme s = availableVFSSchemes.get(i);
                if (scheme.equals(s.getScheme())) {
                    wLocation.select(i);
                    selectedVFSScheme = s;
                }
            }
        } catch (KettleFileException ex) {
            log.logError(getBaseMsg("OrcDialog.FileBrowser.KettleFileException"));
        } catch (FileSystemException ex) {
            log.logError(getBaseMsg("OrcDialog.FileBrowser.FileSystemException"));
        }
    }
    // do we have preview button?
    if (wPreview != null) {
        //update preview button
        wPreview.setEnabled(!pathText.isEmpty());
    }
}

From source file:org.pentaho.big.data.kettle.plugins.formats.impl.parquet.BaseParquetStepDialog.java

private void updateLocation() {
    String pathText = wPath.getText();
    String scheme = pathText.isEmpty() ? HDFS_SCHEME : UriParser.extractScheme(pathText);
    if (scheme != null) {
        try {// ww w .j  a v a 2 s .co m
            List<VFSScheme> availableVFSSchemes = getAvailableVFSSchemes();
            for (int i = 0; i < availableVFSSchemes.size(); i++) {
                VFSScheme s = availableVFSSchemes.get(i);
                if (scheme.equals(s.getScheme())) {
                    wLocation.select(i);
                    selectedVFSScheme = s;
                }
            }
        } catch (KettleFileException ex) {
            log.logError(getBaseMsg("ParquetInputDialog.FileBrowser.KettleFileException"));
        } catch (FileSystemException ex) {
            log.logError(getBaseMsg("ParquetDialog.FileBrowser.FileSystemException"));
        }
    }
    // do we have preview button?
    if (wPreview != null) {
        //update preview button
        wPreview.setEnabled(!pathText.isEmpty());
    }
}

From source file:org.pentaho.di.ui.core.widget.VfsFileChooserControls.java

private void updateLocation() {
    String pathText = wPath.getText();
    String scheme = pathText.isEmpty() ? HDFS_SCHEME : UriParser.extractScheme(pathText);
    if (scheme != null) {
        List<VFSScheme> availableVFSSchemes = getAvailableVFSSchemes();
        for (int i = 0; i < availableVFSSchemes.size(); i++) {
            VFSScheme s = availableVFSSchemes.get(i);
            if (scheme.equals(s.scheme)) {
                wLocation.select(i);/* ww  w .j  a  v  a  2s .c  om*/
                selectedVFSScheme = s;
            }
        }
    }
}