Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.util

public Class URLUtil

extends Object
Class Inheritance
Imports
java.net.MalformedURLException, .URI, .URISyntaxException, .URL, .URLDecoder, java.nio.charset.StandardCharsets, java.util.regex.Pattern, org.jabref.logic.util.strings.StringUtil, org.apache.hc.core5.net.URIBuilder, org.jspecify.annotations.NonNull

URL utilities for URLs in the JabRef logic.

For GUI-oriented URL utilities see org.jabref.gui.fieldeditors.URLUtil

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
public static final Pattern
URL_PATTERN

Pattern matches a string containing a URL with a protocol

private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the cleaned Google URL or url if no search URL was detected
cleanGoogleSearchURL
(@NonNull String
the Google search URL string
url
)

Cleans URLs returned by Google search.

public static @NonNull URL

Returns:

the URL object created from the string URL.
create
(@NonNull String
the URL string to be converted into a URL.
url
)

Creates a URL object from the given string URL.

public static URI

Returns:

the URI object created from the string URL.
createUri
(String
the URL string to be converted into a URI.
url
)

Creates a URI object from the given string URL.

public static boolean

Returns:

true if url contains a valid URL
isURL
(String
the String to check for a URL
url
)

Checks whether the given String is a URL.

public static boolean
isValidHttpUrl(String url)

Validates that a constructed URL is valid and conforms to RFC 3986 URI syntax (updated RFC 2396).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

GOOGLE_SEARCH_EXPback to summary
private static final String GOOGLE_SEARCH_EXP
URL_EXPback to summary
private static final String URL_EXP
URL_PATTERNback to summary
public static final Pattern URL_PATTERN

Pattern matches a string containing a URL with a protocol

URL_REGEXback to summary
private static final String URL_REGEX

Constructor Detail

URLUtilback to summary
public URLUtil()

Method Detail

cleanGoogleSearchURLback to summary
public static String cleanGoogleSearchURL(@NonNull String url)

Cleans URLs returned by Google search.

Example

```text If you copy links from search results from Google, all links will be enriched with search meta data, e.g. https://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&&url=http%3A%2F%2Fwww.inrg.csie.ntu.edu.tw%2Falgorithm2014%2Fhomework%2FWagner-74.pdf&ei=DifeVYHkDYWqU5W0j6gD&usg=AFQjCNFl638rl5KVta1jIMWLyb4CPSZidg&sig2=0hSSMw9XZXL3HJWwEcJtOg ```
Parameters
url:@NonNull String

the Google search URL string

Returns:String

the cleaned Google URL or url if no search URL was detected

createback to summary
public static @NonNull URL create(@NonNull String url) throws MalformedURLException

Creates a URL object from the given string URL.

Parameters
url:@NonNull String

the URL string to be converted into a URL.

Returns:@NonNull URL

the URL object created from the string URL.

Exceptions
MalformedURLException:
if the URL is malformed and cannot be converted to a URL.
createUriback to summary
public static URI createUri(String url)

Creates a URI object from the given string URL. This method attempts to convert the given URL string into a URI object. The pipe character ('|') is replaced with its percent-encoded equivalent ("%7C") because the pipe character is only a valid character according to RFC3986. However, JDK's URI implementation is implementing RFC2396 and RFC2732, but not RFC3986.

Parameters
url:String

the URL string to be converted into a URI.

Returns:URI

the URI object created from the string URL.

Exceptions
IllegalArgumentException:
if the string URL is not a valid URI or if the URI format is incorrect.
isURLback to summary
public static boolean isURL(String url)

Checks whether the given String is a URL.

Currently only checks for a protocol String.

Parameters
url:String

the String to check for a URL

Returns:boolean

true if url contains a valid URL

isValidHttpUrlback to summary
public static boolean isValidHttpUrl(String url)

Validates that a constructed URL is valid and conforms to RFC 3986 URI syntax (updated RFC 2396). And also validates that it has an HTTP or HTTPS scheme to prevent injection attacks. Does not perform complex checks such as opening connections.