Skip to content

Commit 743cff7

Browse files
committed
adjust javadocs, rename
1 parent 57ec3fd commit 743cff7

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java

+25-18
Original file line numberDiff line numberDiff line change
@@ -1438,10 +1438,10 @@ private static String generatePageLink(int page, int offset, int limit, long siz
14381438

14391439

14401440
/**
1441-
* Check if the string is an HTTP URL.
1441+
* Check if the string is an HTTP URI (i.e. allows for relative identifiers).
14421442
*
14431443
* @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
14451445
*/
14461446
public static boolean isHttpUri(String string) {
14471447
URI uri;
@@ -1460,12 +1460,12 @@ public static boolean isHttpUri(String string) {
14601460
static final String REDACTED_USER_INFO = "redacted_by_OpenGrok";
14611461

14621462
/**
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.
14641464
* @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)
14661466
* or string representation of the URL with the user-info part removed
14671467
*/
1468-
public static String redactUrl(String path) {
1468+
public static String redactUri(String path) {
14691469
URI uri;
14701470
try {
14711471
uri = new URI(path);
@@ -1520,9 +1520,9 @@ public static String linkify(String url, boolean newTab) {
15201520
}
15211521

15221522
/**
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.
15261526
*
15271527
* @param name displayed name of the anchor
15281528
* @param attrs map of attributes for the html element
@@ -1553,9 +1553,9 @@ public static String buildLink(String name, Map<String, String> attrs)
15531553
}
15541554

15551555
/**
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.
15591559
*
15601560
* @param name displayed name of the anchor
15611561
* @param url anchor's URL
@@ -1564,17 +1564,16 @@ public static String buildLink(String name, Map<String, String> attrs)
15641564
* @throws URISyntaxException URI syntax
15651565
* @throws MalformedURLException bad URL
15661566
*/
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 {
15691568
Map<String, String> attrs = new TreeMap<>();
15701569
attrs.put("href", url);
15711570
return buildLink(name, attrs);
15721571
}
15731572

15741573
/**
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.
15781577
*
15791578
* @param name displayed name of the anchor
15801579
* @param url anchor's URL
@@ -1595,6 +1594,15 @@ public static String buildLink(String name, String url, boolean newTab)
15951594
return buildLink(name, attrs);
15961595
}
15971596

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+
*/
15981606
private static String buildLinkReplacer(MatchResult result, String text, String url) {
15991607
final String group1 = result.group(1);
16001608
final String appendedUrl = url + uriEncode(group1);
@@ -1612,8 +1620,7 @@ private static String buildLinkReplacer(MatchResult result, String text, String
16121620

16131621
/**
16141622
* 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.
16171624
*
16181625
* @param text text to replace all patterns
16191626
* @param pattern the pattern to match

opengrok-indexer/src/test/java/org/opengrok/indexer/web/UtilTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,13 @@ void testIsUrl() {
376376
}
377377

378378
@Test
379-
void testRedactUrl() {
380-
assertEquals("/foo/bar", Util.redactUrl("/foo/bar"));
381-
assertEquals("http://foo/bar?r=xxx", Util.redactUrl("http://foo/bar?r=xxx"));
379+
void testRedactUri() {
380+
assertEquals("/foo/bar", Util.redactUri("/foo/bar"));
381+
assertEquals("http://foo/bar?r=xxx", Util.redactUri("http://foo/bar?r=xxx"));
382382
assertEquals("http://" + Util.REDACTED_USER_INFO + "@foo/bar?r=xxx",
383-
Util.redactUrl("http://user@foo/bar?r=xxx"));
383+
Util.redactUri("http://user@foo/bar?r=xxx"));
384384
assertEquals("http://" + Util.REDACTED_USER_INFO + "@foo/bar?r=xxx",
385-
Util.redactUrl("http://user:pass@foo/bar?r=xxx"));
385+
Util.redactUri("http://user:pass@foo/bar?r=xxx"));
386386
}
387387

388388
@Test

opengrok-web/src/main/webapp/WEB-INF/tags/repository.tag

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Portions Copyright (c) 2019, Krystof Tulinger <[email protected]>.
6969
</c:if>
7070
</td>
7171
<td>${Util.htmlize(ObjectUtils.defaultIfNull(repositoryInfo.type, "N/A"))}:
72-
${Util.linkify(ObjectUtils.defaultIfNull(Util.redactUrl(repositoryInfo.parent), "N/A"))}
72+
${Util.linkify(ObjectUtils.defaultIfNull(Util.redactUri(repositoryInfo.parent), "N/A"))}
7373
(${Util.htmlize(ObjectUtils.defaultIfNull(repositoryInfo.branch, "N/A"))})
7474
</td>
7575
<td>

0 commit comments

Comments
 (0)