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:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.java2s.com");
    System.out.println("URI      : " + uri);
    System.out.println("Fragment : " + uri.getFragment());
}

From source file:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.example.org");
    System.out.println("URI      : " + uri);
    System.out.println("Raw Authority : " + uri.getRawAuthority());
    System.out.println("Raw Fragment : " + uri.getRawFragment());
    System.out.println("Fragment : " + uri.getFragment());
    System.out.println("Authority : " + uri.getAuthority());
    System.out.println("Authority : " + uri.getRawPath());
    System.out.println("RawQuery : " + uri.getRawQuery());
    System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart());
    System.out.println("RawUserInfo : " + uri.getRawUserInfo());

}

From source file:IRIDemo.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://r%C3%A9sum%C3%A9.example.org");
    System.out.println("URI      : " + uri);
    System.out.println("Raw Authority : " + uri.getRawAuthority());
    System.out.println("Raw Fragment : " + uri.getRawFragment());
    System.out.println("Fragment : " + uri.getFragment());
    System.out.println("Authority : " + uri.getAuthority());
    System.out.println("Authority : " + uri.getRawPath());
    System.out.println("RawQuery : " + uri.getRawQuery());
    System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart());
    System.out.println("RawUserInfo : " + uri.getRawUserInfo());

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    URI u = new URI("http://www.java2s.com");
    System.out.println("The URI is " + u);
    if (u.isOpaque()) {
        System.out.println("This is an opaque URI.");
        System.out.println("The scheme is " + u.getScheme());
        System.out.println("The scheme specific part is " + u.getSchemeSpecificPart());
        System.out.println("The fragment ID is " + u.getFragment());
    } else {/* w  ww  .  j av  a  2s. c om*/
        System.out.println("This is a hierarchical URI.");
        System.out.println("The scheme is " + u.getScheme());

        u = u.parseServerAuthority();
        System.out.println("The host is " + u.getUserInfo());
        System.out.println("The user info is " + u.getUserInfo());
        System.out.println("The port is " + u.getPort());
        System.out.println("The path is " + u.getPath());
        System.out.println("The query string is " + u.getQuery());
        System.out.println("The fragment ID is " + u.getFragment());
    }

}

From source file:com.openshift.internal.util.URIUtils.java

public static Map<String, String> splitFragment(URI uri) {
    return splitQuery(uri.getFragment());
}

From source file:org.eclipse.buckminster.p2.remote.client.RemoteRepositoryFactory.java

protected static String getRepositoryName(URI repoURI) {
    return repoURI.getFragment();
}

From source file:org.mrgeo.utils.FileUtils.java

public static String resolveURI(final String path) {
    try {/*from w  w w  . j a  v  a2s  .  c o  m*/
        URI uri = new URI(path);
        if (uri.getScheme() == null) {
            String fragment = uri.getFragment();
            URI part = new File(uri.getPath()).toURI();

            uri = new URI(part.getScheme(), part.getPath(), fragment);
        }
        return uri.toString();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    return path;
}

From source file:org.mrgeo.utils.FileUtils.java

public static String resolveURL(final String path) {
    try {/*from   w  w w.  ja v  a  2 s  .  c o  m*/
        URI uri = new URI(path);
        if (uri.getScheme() == null) {
            String fragment = uri.getFragment();
            URI part = new File(uri.getPath()).toURI();

            uri = new URI(part.getScheme(), part.getPath(), fragment);
        }
        return uri.toURL().toString();
    } catch (URISyntaxException e) {
    } catch (MalformedURLException e) {
    }

    return path;
}

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

public static URI getMandatoryUrlParameter(final String name, final Map<String, List<String>> parameters) {
    final String value = getMandatoryStringParameter(name, parameters);

    try {/*from   www  . j  ava  2 s .  c om*/
        final URI uri = new URI(value);

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

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

From source file:at.bitfire.davdroid.URIUtils.java

/**
 * Parse a received absolute/relative URL and generate a normalized URI that can be compared.
 * @param original       URI to be parsed, may be absolute or relative
  * @param mustBePath    true if it's known that original is a path (may contain ":") and not an URI, i.e. ":" is not the scheme separator
 * @return             normalized URI//from  w  ww .ja  v  a  2s  .c om
 * @throws URISyntaxException
 */
public static URI parseURI(String original, boolean mustBePath) throws URISyntaxException {
    if (mustBePath) {
        // may contain ":"
        // case 1: "my:file"        won't be parsed by URI correctly because it would consider "my" as URI scheme
        // case 2: "path/my:file"   will be parsed by URI correctly
        // case 3: "my:path/file"   won't be parsed by URI correctly because it would consider "my" as URI scheme
        int idxSlash = original.indexOf('/'), idxColon = original.indexOf(':');
        if (idxColon != -1) {
            // colon present
            if ((idxSlash != -1) && idxSlash < idxColon) // There's a slash, and it's before the colon  everything OK
                ;
            else // No slash before the colon; we have to put it there
                original = "./" + original;
        }
    }

    // escape some common invalid characters  servers keep sending unescaped crap like "my calendar.ics" or "{guid}.vcf"
    // this is only a hack, because for instance, "[" may be valid in URLs (IPv6 literal in host name)
    String repaired = original.replaceAll(" ", "%20").replaceAll("\\{", "%7B").replaceAll("\\}", "%7D");
    if (!repaired.equals(original))
        Log.w(TAG, "Repaired invalid URL: " + original + " -> " + repaired);

    URI uri = new URI(repaired);
    URI normalized = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(),
            uri.getFragment());
    Log.v(TAG, "Normalized URL " + original + " -> " + normalized.toASCIIString());
    return normalized;
}