public static URI buildNewURI ( URI referenceUri , String uriSuffix ) throws URISyntaxException { if ( uriSuffix == null ) throw new IllegalArgumentException ( "The URI suffix cannot be null." ) ; uriSuffix = uriSuffix . replaceAll ( "\\\\" , "/" ) ; URI importUri = null ; try { // Absolute URL ? importUri = urlToUri ( new URL ( uriSuffix ) ) ; } catch ( Exception e ) { try { // Relative URL ? if ( ! referenceUri . toString ( ) . endsWith ( "/" ) && ! uriSuffix . startsWith ( "/" ) ) referenceUri = new URI ( referenceUri . toString ( ) + "/" ) ; importUri = referenceUri . resolve ( new URI ( null , uriSuffix , null ) ) ; } catch ( Exception e2 ) { String msg = "An URI could not be built from the URI " + referenceUri . toString ( ) + " and the suffix " + uriSuffix + "." ; throw new URISyntaxException ( msg , e2 . getMessage ( ) ) ; } } return importUri . normalize ( ) ; }
Builds an URI from an URI and a suffix .