46
46
import java .nio .charset .StandardCharsets ;
47
47
import java .text .DecimalFormat ;
48
48
import 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 .*;
56
50
import java .util .Map .Entry ;
57
- import java .util .Optional ;
58
- import java .util .TreeMap ;
59
51
import java .util .function .IntConsumer ;
60
52
import java .util .logging .Level ;
61
53
import java .util .logging .Logger ;
@@ -1443,13 +1435,17 @@ private static String generatePageLink(int page, int offset, int limit, long siz
1443
1435
* @return true if it is HTTP URL, false otherwise
1444
1436
*/
1445
1437
public static boolean isHttpUri (String string ) {
1446
- URL url ;
1438
+ URI uri ;
1447
1439
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 )) {
1450
1446
return false ;
1451
1447
}
1452
- return url . getProtocol ().equals ("http" ) || url . getProtocol ().equals ("https" );
1448
+ return uri . getScheme ().equals ("http" ) || uri . getScheme ().equals ("https" );
1453
1449
}
1454
1450
1455
1451
protected static final String REDACTED_USER_INFO = "redacted_by_OpenGrok" ;
@@ -1461,14 +1457,14 @@ public static boolean isHttpUri(String string) {
1461
1457
* or string representation of the URL with the user-info part removed
1462
1458
*/
1463
1459
public static String redactUrl (String path ) {
1464
- URL url ;
1460
+ URI uri ;
1465
1461
try {
1466
- url = new URI (path ). toURL ( );
1467
- } catch (MalformedURLException | URISyntaxException e ) {
1462
+ uri = new URI (path );
1463
+ } catch (URISyntaxException e ) {
1468
1464
return path ;
1469
1465
}
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 );
1472
1468
} else {
1473
1469
return path ;
1474
1470
}
@@ -1536,7 +1532,7 @@ public static String buildLink(String name, Map<String, String> attrs)
1536
1532
buffer .append ("=\" " );
1537
1533
String value = attr .getValue ();
1538
1534
if (attr .getKey ().equals ("href" )) {
1539
- value = new URI (value ).toString ();
1535
+ value = new URI (value ).toURL (). toString ();
1540
1536
}
1541
1537
buffer .append (value );
1542
1538
buffer .append ("\" " );
0 commit comments