@@ -1438,10 +1438,10 @@ private static String generatePageLink(int page, int offset, int limit, long siz
1438
1438
1439
1439
1440
1440
/**
1441
- * Check if the string is an HTTP URL .
1441
+ * Check if the string is an HTTP URI (i.e. allows for relative identifiers) .
1442
1442
*
1443
1443
* @param string the string to check
1444
- * @return true if it is HTTP URL , false otherwise
1444
+ * @return true if it is HTTP URI , false otherwise
1445
1445
*/
1446
1446
public static boolean isHttpUri (String string ) {
1447
1447
URI uri ;
@@ -1460,12 +1460,12 @@ public static boolean isHttpUri(String string) {
1460
1460
static final String REDACTED_USER_INFO = "redacted_by_OpenGrok" ;
1461
1461
1462
1462
/**
1463
- * If given path is a URL , return the string representation with the user-info part filtered out.
1463
+ * If given path is a URI , return the string representation with the user-info part filtered out.
1464
1464
* @param path path to object
1465
- * @return either the original string (if the URL is not valid)
1465
+ * @return either the original string (if the URI is not valid)
1466
1466
* or string representation of the URL with the user-info part removed
1467
1467
*/
1468
- public static String redactUrl (String path ) {
1468
+ public static String redactUri (String path ) {
1469
1469
URI uri ;
1470
1470
try {
1471
1471
uri = new URI (path );
@@ -1520,9 +1520,9 @@ public static String linkify(String url, boolean newTab) {
1520
1520
}
1521
1521
1522
1522
/**
1523
- * Build an anchor with given name and a pack of attributes. Automatically
1524
- * escapes href attributes and automatically escapes the name into HTML
1525
- * entities.
1523
+ * Build an anchor with given name and a pack of attributes.
1524
+ * Assumes the <code> href</code> attribute value is URI encoded.
1525
+ * Automatically escapes the name into HTML entities.
1526
1526
*
1527
1527
* @param name displayed name of the anchor
1528
1528
* @param attrs map of attributes for the html element
@@ -1553,9 +1553,9 @@ public static String buildLink(String name, Map<String, String> attrs)
1553
1553
}
1554
1554
1555
1555
/**
1556
- * Build an anchor with given name and a pack of attributes. Automatically
1557
- * escapes href attributes and automatically escapes the name into HTML
1558
- * entities.
1556
+ * Build an anchor with given name and a pack of attributes.
1557
+ * Assumes the <code> href</code> attribute value is URI encoded.
1558
+ * Automatically escapes the name into HTML entities.
1559
1559
*
1560
1560
* @param name displayed name of the anchor
1561
1561
* @param url anchor's URL
@@ -1564,17 +1564,16 @@ public static String buildLink(String name, Map<String, String> attrs)
1564
1564
* @throws URISyntaxException URI syntax
1565
1565
* @throws MalformedURLException bad URL
1566
1566
*/
1567
- public static String buildLink (String name , String url )
1568
- throws URISyntaxException , MalformedURLException {
1567
+ public static String buildLink (String name , String url ) throws URISyntaxException , MalformedURLException {
1569
1568
Map <String , String > attrs = new TreeMap <>();
1570
1569
attrs .put ("href" , url );
1571
1570
return buildLink (name , attrs );
1572
1571
}
1573
1572
1574
1573
/**
1575
- * Build an anchor with given name and a pack of attributes. Automatically
1576
- * escapes href attributes and automatically escapes the name into HTML
1577
- * entities.
1574
+ * Build an anchor with given name and a pack of attributes.
1575
+ * Assumes the <code> href</code> attribute value is URI encoded.
1576
+ * Automatically escapes the name into HTML entities.
1578
1577
*
1579
1578
* @param name displayed name of the anchor
1580
1579
* @param url anchor's URL
@@ -1595,6 +1594,15 @@ public static String buildLink(String name, String url, boolean newTab)
1595
1594
return buildLink (name , attrs );
1596
1595
}
1597
1596
1597
+ /**
1598
+ * Callback function to provide replacement value for pattern match.
1599
+ * It replaces the first group of the pattern and retains the rest of the pattern.
1600
+ *
1601
+ * @param result {@link MatchResult} object representing pattern match
1602
+ * @param text original text containing the match
1603
+ * @param url URL to be used for the replacement
1604
+ * @return replacement for the first group in the pattern
1605
+ */
1598
1606
private static String buildLinkReplacer (MatchResult result , String text , String url ) {
1599
1607
final String group1 = result .group (1 );
1600
1608
final String appendedUrl = url + uriEncode (group1 );
@@ -1612,8 +1620,7 @@ private static String buildLinkReplacer(MatchResult result, String text, String
1612
1620
1613
1621
/**
1614
1622
* Replace all occurrences of pattern in the incoming text with the link
1615
- * named name pointing to a URL. It is possible to use the regexp pattern
1616
- * groups in name and URL when they are specified in the pattern.
1623
+ * named name pointing to a URL.
1617
1624
*
1618
1625
* @param text text to replace all patterns
1619
1626
* @param pattern the pattern to match
0 commit comments