Class UrlUtil
For internal use only. May be renamed or removed in a future release.
- Since:
- 2.0
- Author:
- Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringdecodeURIComponent(String encoded) Decodes a percent-encoded string according to RFC 3986.static StringEncodes a full URI.static StringencodeURIComponent(String path) Encodes a path segment of a URI.static StringgetServletPathRelative(String absolutePath, jakarta.servlet.http.HttpServletRequest request) Returns the given absolute path as a path relative to the servlet path.static booleanisExternal(String url) checks if the given url is an external URL (e.g.
-
Method Details
-
isExternal
checks if the given url is an external URL (e.g. staring with http:// or https://) or not.- Parameters:
url- is the url to be checked.- Returns:
- true if the url is external otherwise false.
-
encodeURI
Encodes a full URI.Corresponds to encodeURI in JavaScript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
The path can contain
/and other special URL characters as these will not be encoded. SeeencodeURIComponent(String)if you want to encode all special characters.The following characters are not escaped: A-Za-z0-9;,/?:@&=+$-_.!~*'()#
- Parameters:
uri- the uri to encode- Returns:
- the encoded URI
-
encodeURIComponent
Encodes a path segment of a URI.Corresponds to encodeURIComponent in JavaScript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
The following characters are not escaped: A-Za-z0-9-_.!~*'()
- Parameters:
path- the path to encode- Returns:
- the encoded path
-
decodeURIComponent
Decodes a percent-encoded string according to RFC 3986.Corresponds to decodeURIComponent in JavaScript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent
Unlike
URLDecoder, this method does not treat '+' as a space character, making it suitable for decoding strings encoded with JavaScript'sencodeURIComponent()orencodeURIComponent(String).- Parameters:
encoded- the percent-encoded string- Returns:
- the decoded string
-
getServletPathRelative
public static String getServletPathRelative(String absolutePath, jakarta.servlet.http.HttpServletRequest request) Returns the given absolute path as a path relative to the servlet path.- Parameters:
absolutePath- the path to make relativerequest- a request with information about the servlet path- Returns:
- a relative path that when applied to the servlet path, refers to the absolute path without containing the context path or servlet path
-