Java URI to Local Name getLocalPart(String uri)

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

Description

Get the local part of the uri, if possible.

License

GNU General Public License

Parameter

Parameter Description
uri the uri to crop

Return

the local part of the uri

Declaration

public static String getLocalPart(String uri) 

Method Source Code

//package com.java2s;
/***************************************
 *            ViPER                    *
 *  The Video Processing               *
 *         Evaluation Resource         *
 *                                     *
 *  Distributed under the GPL license  *
 *        Terms available at gnu.org.  *
 *                                     *
 *  Copyright University of Maryland,  *
 *                      College Park.  *
 ***************************************/

import java.net.*;

public class Main {
    /**//from w ww .  j  a  v a2 s  .co m
     * Get the local part of the uri, if possible. Otherwise,
     * returns the whole uri.
     * @param uri the uri to crop
     * @return the local part of the uri
     */
    public static String getLocalPart(String uri) {
        try {
            URI u = new URI(uri);
            String lname = u.getFragment();
            if (lname == null) {
                lname = u.getPath();
            }
            return lname;
        } catch (URISyntaxException e) {
            return uri;
        }
    }
}

Related

  1. getLocalDomainURI(String originalHost, String dirPath, String childUri)
  2. getLocalName(String uri)
  3. getLocalName(URI uri)
  4. getLocalName(URI uri)
  5. getName(URI uri)
  6. getName(URI uri)
  7. getName(URI uri)
  8. getName(URI uri)