4646import java .nio .charset .StandardCharsets ;
4747import java .text .DecimalFormat ;
4848import java .text .NumberFormat ;
49- import java .util .Arrays ;
50- import java .util .Collection ;
51- import java .util .HashMap ;
52- import java .util .LinkedList ;
53- import java .util .List ;
54- import java .util .Locale ;
55- import java .util .Map ;
49+ import java .util .*;
5650import java .util .Map .Entry ;
57- import java .util .Optional ;
58- import java .util .TreeMap ;
5951import java .util .function .IntConsumer ;
6052import java .util .logging .Level ;
6153import java .util .logging .Logger ;
@@ -1443,13 +1435,17 @@ private static String generatePageLink(int page, int offset, int limit, long siz
14431435 * @return true if it is HTTP URL, false otherwise
14441436 */
14451437 public static boolean isHttpUri (String string ) {
1446- URL url ;
1438+ URI uri ;
14471439 try {
1448- url = new URI (string ).toURL ();
1449- } catch (MalformedURLException | URISyntaxException ex ) {
1440+ uri = new URI (string );
1441+ } catch (URISyntaxException ex ) {
1442+ return false ;
1443+ }
1444+ String scheme = uri .getScheme ();
1445+ if (Objects .isNull (scheme )) {
14501446 return false ;
14511447 }
1452- return url . getProtocol ().equals ("http" ) || url . getProtocol ().equals ("https" );
1448+ return uri . getScheme ().equals ("http" ) || uri . getScheme ().equals ("https" );
14531449 }
14541450
14551451 protected static final String REDACTED_USER_INFO = "redacted_by_OpenGrok" ;
@@ -1461,14 +1457,14 @@ public static boolean isHttpUri(String string) {
14611457 * or string representation of the URL with the user-info part removed
14621458 */
14631459 public static String redactUrl (String path ) {
1464- URL url ;
1460+ URI uri ;
14651461 try {
1466- url = new URI (path ). toURL ( );
1467- } catch (MalformedURLException | URISyntaxException e ) {
1462+ uri = new URI (path );
1463+ } catch (URISyntaxException e ) {
14681464 return path ;
14691465 }
1470- if (url .getUserInfo () != null ) {
1471- return url .toString ().replace (url .getUserInfo (), REDACTED_USER_INFO );
1466+ if (uri .getUserInfo () != null ) {
1467+ return uri .toString ().replace (uri .getUserInfo (), REDACTED_USER_INFO );
14721468 } else {
14731469 return path ;
14741470 }
@@ -1536,7 +1532,7 @@ public static String buildLink(String name, Map<String, String> attrs)
15361532 buffer .append ("=\" " );
15371533 String value = attr .getValue ();
15381534 if (attr .getKey ().equals ("href" )) {
1539- value = new URI (value ).toString ();
1535+ value = new URI (value ).toURL (). toString ();
15401536 }
15411537 buffer .append (value );
15421538 buffer .append ("\" " );
0 commit comments