Example usage for java.net URI getFragment

List of usage examples for java.net URI getFragment

Introduction

In this page you can find the example usage for java.net URI getFragment.

Prototype

public String getFragment() 

Source Link

Document

Returns the decoded fragment component of this URI.

Usage

From source file:io.gravitee.gateway.standalone.DynamicRoutingGatewayTest.java

private static URI create(URI uri, int port) {
    try {/*from w w w.j  a  va  2  s.  c  om*/
        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), port, uri.getPath(), uri.getQuery(),
                uri.getFragment());
    } catch (URISyntaxException e) {
        return uri;
    }
}

From source file:org.mule.module.pubsubhubbub.Utils.java

public static List<URI> getMandatoryUrlParameters(final String name,
        final Map<String, List<String>> parameters) {

    final List<String> values = parameters.get(name);

    if ((values == null) || (values.isEmpty())) {
        throw new IllegalArgumentException("Missing mandatory parameter: " + name);
    }/*from w  w  w.j a  va 2s  . com*/

    try {
        final List<URI> uris = new ArrayList<URI>();

        for (final String value : values) {
            if (StringUtils.isBlank(value)) {
                continue;
            }

            final URI uri = new URI(value);

            if (StringUtils.isNotEmpty(uri.getFragment())) {
                throw new IllegalArgumentException("Fragment found in URL parameter: " + name);
            }

            uris.add(uri);
        }

        if (uris.isEmpty()) {
            throw new IllegalArgumentException("No value found for: " + name);
        }

        return uris;
    } catch (final URISyntaxException use) {
        use.printStackTrace();
        throw new IllegalArgumentException("Invalid URL parameter: " + name, use);
    }
}

From source file:org.attribyte.util.URIEncoder.java

/**
 * Recodes a URI.// w  ww  .  j a  v  a  2  s .  c  o  m
 * @param uri The uri.
 * @return The recoded URI as a string.
 */
public static String recode(URI uri) {
    return encode(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment());
}

From source file:Main.java

public static void printURIDetails(URI uri) {
    System.out.println("URI:" + uri);
    System.out.println("Normalized:" + uri.normalize());
    String parts = "[Scheme=" + uri.getScheme() + ", Authority=" + uri.getAuthority() + ", Path="
            + uri.getPath() + ", Query:" + uri.getQuery() + ", Fragment:" + uri.getFragment() + "]";
    System.out.println(parts);/*from w  w w  . j  a va  2 s.c  om*/
    System.out.println();
}

From source file:Main.java

public static final String dereference(String idRef) {
    URI uri = URI.create(idRef);
    String part = uri.getSchemeSpecificPart();
    if (part != null && part.length() > 0) {
        throw new UnsupportedOperationException(
                "modlur does not support external sources (" + uri.toString() + ")");
    }//from www . jav a  2  s .co  m
    return uri.getFragment();
}

From source file:com.ibm.jaggr.core.util.PathUtil.java

public static URI appendToPath(URI uri, String append) throws URISyntaxException {
    return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath() + append, uri.getQuery(),
            uri.getFragment());
}

From source file:org.gradle.caching.http.internal.HttpBuildCache.java

/**
 * Create a safe URI from the given one by stripping out user info.
 *
 * @param uri Original URI//from  w  w w .j  a v  a 2s.c  o  m
 * @return a new URI with no user info
 */
private static URI safeUri(URI uri) {
    try {
        return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(),
                uri.getFragment());
    } catch (URISyntaxException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}

From source file:org.springframework.data.hadoop.fs.DistributedCacheFactoryBean.java

private static String getPathWithFragment(URI uri) {
    String path = uri.getPath();// w  ww .  ja v a 2s.c  o  m
    String fragment = uri.getFragment();
    if (StringUtils.hasText(fragment)) {
        path = path + "#" + fragment;
    }
    return path;
}

From source file:URIUtil.java

/**
 * Get the parent URI of the supplied URI
 * @param uri The input URI for which the parent URI is being requrested.
 * @return The parent URI.  Returns a URI instance equivalent to "../" if
 * the supplied URI path has no parent.//from   w w w.  j  av a 2s .  c  om
 * @throws URISyntaxException Failed to reconstruct the parent URI.
 */
public static URI getParent(URI uri) throws URISyntaxException {

    String parentPath = new File(uri.getPath()).getParent();

    if (parentPath == null) {
        return new URI("../");
    }

    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
            parentPath.replace('\\', '/'), uri.getQuery(), uri.getFragment());
}

From source file:org.apache.tez.mapreduce.task.MRRuntimeTask.java

/**
 * Set up the DistributedCache related configs to make
 * {@link DistributedCache#getLocalCacheFiles(Configuration)} and
 * {@link DistributedCache#getLocalCacheArchives(Configuration)} working.
 * //  ww  w  .  j  a  v  a2  s  .  com
 * @param job
 * @throws IOException
 */
private static void setupDistributedCacheConfig(final JobConf job) throws IOException {

    String localWorkDir = (job.get(TezJobConfig.TASK_LOCAL_RESOURCE_DIR));
    // ^ ^ all symlinks are created in the current work-dir

    // Update the configuration object with localized archives.
    URI[] cacheArchives = DistributedCache.getCacheArchives(job);
    if (cacheArchives != null) {
        List<String> localArchives = new ArrayList<String>();
        for (int i = 0; i < cacheArchives.length; ++i) {
            URI u = cacheArchives[i];
            Path p = new Path(u);
            Path name = new Path((null == u.getFragment()) ? p.getName() : u.getFragment());
            String linkName = name.toUri().getPath();
            localArchives.add(new Path(localWorkDir, linkName).toUri().getPath());
        }
        if (!localArchives.isEmpty()) {
            job.set(MRJobConfig.CACHE_LOCALARCHIVES,
                    StringUtils.arrayToString(localArchives.toArray(new String[localArchives.size()])));
        }
    }

    // Update the configuration object with localized files.
    URI[] cacheFiles = DistributedCache.getCacheFiles(job);
    if (cacheFiles != null) {
        List<String> localFiles = new ArrayList<String>();
        for (int i = 0; i < cacheFiles.length; ++i) {
            URI u = cacheFiles[i];
            Path p = new Path(u);
            Path name = new Path((null == u.getFragment()) ? p.getName() : u.getFragment());
            String linkName = name.toUri().getPath();
            localFiles.add(new Path(localWorkDir, linkName).toUri().getPath());
        }
        if (!localFiles.isEmpty()) {
            job.set(MRJobConfig.CACHE_LOCALFILES,
                    StringUtils.arrayToString(localFiles.toArray(new String[localFiles.size()])));
        }
    }
}