public static String percentEncodeUrl ( final String urlStr ) { if ( Util . empty ( urlStr ) ) { return urlStr ; } try { // Avoid double encoding String decode = URIUtil . decode ( urlStr ) ; URI uri = new URI ( decode , false ) ; return uri . getEscapedURIReference ( ) ; } catch ( Exception e ) { return urlStr ; } }
Percent encode a URL to include in HTML .