Java URI to extractLocalName(String uri)

Here you can find the source of extractLocalName(String uri)

Description

extract Local Name

License

Open Source License

Declaration

public static String extractLocalName(String uri) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.URI;

public class Main {
    private static final String GRID = "#";
    private static final String SLASH = "/";
    private static final String PROTOCOL_DELIMITER = "://";

    public static String extractLocalName(String uri) {
        return extractLocalName(URI.create(uri));
    }//from w ww  .j av  a 2  s  . c om

    public static String extractLocalName(URI uri) {
        String uriString = uri.toASCIIString().replace(uri.getScheme() + PROTOCOL_DELIMITER + uri.getHost(), "");
        int index;
        if (uriString.contains(GRID)) {
            index = uriString.indexOf(GRID) + 1;
        } else if (uriString.contains(SLASH)) {
            index = uriString.lastIndexOf(SLASH) + 1;
        } else {
            return null;
        }

        if (uriString.length() > index) {
            return uriString.substring(index);
        } else {
            return null;
        }
    }
}

Related

  1. extractContentDigest(URI contentDigest)
  2. extractForwardURIFrom(URI requestURI)
  3. extractFromURIParams(String paramsRule, String uri)
  4. extractHostAddress(String uri)
  5. extractHostname(String uri)
  6. extractOntologyNameUriFromRDF(String rdfString, boolean generateURI)
  7. extractParamsFromURI(String uri)
  8. extractS3Key(URI uri)
  9. extractTargetSystemFromUri(URI uri)