Example usage for org.apache.commons.vfs2.provider.url UrlFileNameParser UrlFileNameParser

List of usage examples for org.apache.commons.vfs2.provider.url UrlFileNameParser UrlFileNameParser

Introduction

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

Prototype

public UrlFileNameParser() 

Source Link

Usage

From source file:org.pentaho.big.data.impl.cluster.NamedClusterImpl.java

private String processURLsubstitution(String incomingURL, String hdfsScheme, IMetaStore metastore,
        VariableSpace variableSpace) {/*www . j  av  a 2s .  co m*/

    String outgoingURL = null;
    String clusterURL = null;
    if (!hdfsScheme.equals(MAPRFS_SCHEME)) {
        clusterURL = generateURL(hdfsScheme, metastore, variableSpace);
    }
    try {
        if (clusterURL == null || isHdfsHostEmpty(variableSpace)) {
            outgoingURL = incomingURL;
        } else if (incomingURL.equals("/")) {
            outgoingURL = clusterURL;
        } else if (clusterURL != null) {
            String noVariablesURL = incomingURL.replaceAll("[${}]", "/");

            String fullyQualifiedIncomingURL = incomingURL;
            if (!incomingURL.startsWith(hdfsScheme) && !incomingURL.startsWith(NC_SCHEME)) {
                fullyQualifiedIncomingURL = clusterURL + incomingURL;
                noVariablesURL = clusterURL + incomingURL.replaceAll("[${}]", "/");
            }

            UrlFileNameParser parser = new UrlFileNameParser();
            FileName fileName = parser.parseUri(null, null, noVariablesURL);
            String root = fileName.getRootURI();
            String path = fullyQualifiedIncomingURL.substring(root.length() - 1);
            StringBuffer buffer = new StringBuffer();
            // Check for a special case where a fully qualified path (one that has the protocol in it).
            // This can only happen through variable replacement. See BACKLOG-15849. When this scenario
            // occurs we do not prepend the cluster uri to the url.
            boolean prependCluster = true;
            if (variableSpace != null) {
                String filePath = variableSpace.environmentSubstitute(path);
                StringBuilder pattern = new StringBuilder();
                pattern.append("^(").append(HDFS_SCHEME).append("|").append(WASB_SCHEME).append("|")
                        .append(MAPRFS_SCHEME).append("|").append(NC_SCHEME).append("):\\/\\/");
                Pattern r = Pattern.compile(pattern.toString());
                Matcher m = r.matcher(filePath);
                prependCluster = !m.find();
            }
            if (prependCluster) {
                buffer.append(clusterURL);
            }
            buffer.append(path);
            outgoingURL = buffer.toString();
        }
    } catch (Exception e) {
        outgoingURL = null;
    }
    return outgoingURL;
}

From source file:org.pentaho.di.core.namedcluster.NamedClusterManager.java

/**
 * This method performs the root URL substitution with the URL of the specified NamedCluster
 *
 * @param clusterName/*w w  w .  jav a2 s  . co  m*/
 *          the NamedCluster to use to generate the URL for the substitution
 * @param incomingURL
 *          the URL whose root will be replaced
 * @param scheme
 *          the scheme to be used to generate the URL of the specified NamedCluster
 * @return the generated URL or the incoming URL if an error occurs
 */
public String processURLsubstitution(String clusterName, String incomingURL, String scheme,
        IMetaStore metastore, VariableSpace variableSpace) {
    String outgoingURL = null;
    String clusterURL = null;
    if (!scheme.equals(NamedCluster.MAPRFS_SCHEME)) {
        clusterURL = generateURL(scheme, clusterName, metastore, variableSpace);
    }
    try {
        if (clusterURL == null) {
            outgoingURL = incomingURL;
        } else if (incomingURL.equals("/")) {
            outgoingURL = clusterURL;
        } else if (clusterURL != null) {
            String noVariablesURL = incomingURL.replaceAll("[${}]", "/");

            String fullyQualifiedIncomingURL = incomingURL;
            if (!incomingURL.startsWith(scheme)) {
                fullyQualifiedIncomingURL = clusterURL + incomingURL;
                noVariablesURL = clusterURL + incomingURL.replaceAll("[${}]", "/");
            }

            UrlFileNameParser parser = new UrlFileNameParser();
            FileName fileName = parser.parseUri(null, null, noVariablesURL);
            String root = fileName.getRootURI();
            String path = fullyQualifiedIncomingURL.substring(root.length() - 1);
            StringBuffer buffer = new StringBuffer();
            buffer.append(clusterURL);
            buffer.append(path);
            outgoingURL = buffer.toString();
        }
    } catch (Exception e) {
        outgoingURL = null;
    }
    return outgoingURL;
}