public class UrlHelper extends Object
Modifier and Type | Field and Description |
---|---|
static Pattern |
URL_PATTERN
Pattern for recognition of URLs.
|
Modifier and Type | Method and Description |
---|---|
static void |
assertIsValidUrl(String url)
Checks if url is well formed.
|
static String |
convertAnchorsToString(String content)
Parses a string for HTML anchor elements and replaces a shortened URL (suffixed by ...)
within the the anchor with the href value.
|
static String |
getProtocolHostPort(String url,
boolean stripUserInfo)
Get a substring of an absolute URL from beginning up to the path, excluding the path and
without a trailing slash.
|
static String |
insertSessionIdInUrl(String url,
String sessionId)
Insert the session ID in the URL in the form ";jessionid=SESSION_ID".
|
static boolean |
isAbsoluteHttpUrl(String url)
Test whether the given URL is an absolute URL using the HTTP or HTTPS protocol.
|
static boolean |
isAbsoluteUrl(String url)
Test whether the provided URL is absolute.
|
static String |
shortenUrl(String protocolHostPart,
String pathPart,
String queryPart,
String fragmentIdentifier)
Shortens a URL.
|
static String |
urlEncodeUrlPath(String path)
URL encode (application/x-www-form-urlencoded format) the path component of a URL.
|
public static final Pattern URL_PATTERN
public static void assertIsValidUrl(String url)
IllegalArgumentException
is thrownurl
- the url to checkpublic static String convertAnchorsToString(String content)
content
- the content to parsepublic static String getProtocolHostPort(String url, boolean stripUserInfo)
url
- the absolute URL to processstripUserInfo
- whether to remove the user info if containedpublic static String insertSessionIdInUrl(String url, String sessionId)
url
- the url to modifysessionId
- the sessionId to insertpublic static boolean isAbsoluteHttpUrl(String url)
url
- the URL to checkpublic static boolean isAbsoluteUrl(String url)
url
- the URL to testpublic static String shortenUrl(String protocolHostPart, String pathPart, String queryPart, String fragmentIdentifier)
protocolHostPart
- the protocol and host part of the URL including the portpathPart
- the path part of the URL; can be nullqueryPart
- the query part of the URL; can be nullfragmentIdentifier
- the fragment identifier of the URL; can be nullpublic static String urlEncodeUrlPath(String path)
URL encode (application/x-www-form-urlencoded format) the path component of a URL. The method uses the UTF-8 encoding scheme.
Note: the application/x-www-form-urlencoded format encodes spaces with the plus character. For proper URI encoding better useUriUtils.encodeUriComponent(String)
!path
- the path component of a URL. If parts of the path are already URL encoded these
will be omittedCopyright © 2019 Communote team. All rights reserved.