public static String getClassPathElement ( final URL anURL , final String encoding ) throws IllegalArgumentException { // Check sanity Validate . notNull ( anURL , "anURL" ) ; final String protocol = anURL . getProtocol ( ) ; String toReturn = null ; if ( FILE . supports ( protocol ) ) { final String originalPath = anURL . getPath ( ) ; try { return URLDecoder . decode ( anURL . getPath ( ) , encoding ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( "Could not URLDecode path [" + originalPath + "] using encoding [" + encoding + "]" , e ) ; } } else if ( JAR . supports ( protocol ) ) { toReturn = anURL . getPath ( ) ; } else if ( HTTP . supports ( protocol ) || HTTPS . supports ( protocol ) ) { toReturn = anURL . toString ( ) ; } else if ( BUNDLERESOURCE . supports ( protocol ) ) { // e.g. when used in Eclipse/m2e toReturn = anURL . toString ( ) ; } else { throw new IllegalArgumentException ( "Unknown protocol [" + protocol + "]; could not handle URL [" + anURL + "]" ) ; } return toReturn ; }
Converts the supplied URL to a class path element .