
Class UrlUtil
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconstructAbsoluteUrl(String theBase, String theEndpoint) Resolve a relative URL - THIS METHOD WILL NOT FAIL but will log a warning and return theEndpoint if the input is invalid.static StringconstructRelativeUrl(String theParentExtensionUrl, String theExtensionUrl) static StringdetermineResourceTypeInResourceUrl(FhirContext theFhirContext, String theUrl) Given a FHIR resource URL, extracts the associated resource type.static StringescapeUrlParam(String theUnescaped) URL encode a value according to RFC 3986, except for the following characters:-_static StringescapeUrlParam(String theUnescaped, boolean theEscapeSlash) URL encode a value according to RFC 3986, except for the following characters:-_escapeUrlParams(Collection<String> theUnescaped) Applies the same encodong asescapeUrlParam(String)but against all values in a collectiongetAboveUriCandidates(String theUri) Creates list of sub URIs candidates for search with :above modifier Example input: http://[host]/[pathPart1]/[pathPart2] Example output: http://[host], http://[host]/[pathPart1], http://[host]/[pathPart1]/[pathPart2]static booleanisAbsolute(String theValue) static booleanisNeedsSanitization(CharSequence theString) static booleanstatic StringNormalizes canonical URLs for comparison.parseQueryString(String theQueryString) parseQueryStrings(String... theQueryString) static UrlUtil.UrlPartsParse a URL in one of the following forms: [Resource Type]?static RuntimeResourceDefinitionparseUrlResourceType(FhirContext theCtx, String theUrl) static StringsanitizeBaseUrl(String theBaseUrl) static StringsanitizeHeaderValue(String theHeader) Cleans up a value that will be serialized as an HTTP header.static StringsanitizeUrlPart(CharSequence theString) This method specifically HTML-encodes the " and < characters in order to prevent injection attacks.static String[]sanitizeUrlPart(String[] theParameterValues) Applies the same logic assanitizeUrlPart(CharSequence)but against an array, returning an array with the same strings as the input but with sanitization appliedstatic StringsanitizeUrlPart(IPrimitiveType<?> theString) This method specifically HTML-encodes the " and < characters in order to prevent injection attacksstatic String
-
Method Details
-
sanitizeHeaderValue
Cleans up a value that will be serialized as an HTTP header. This method:- Strips any newline (\r or \n) characters
- Since:
- 6.2.0
-
sanitizeBaseUrl
-
constructAbsoluteUrl
Resolve a relative URL - THIS METHOD WILL NOT FAIL but will log a warning and return theEndpoint if the input is invalid. -
constructRelativeUrl
-
determineResourceTypeInResourceUrl
@Nullable public static String determineResourceTypeInResourceUrl(FhirContext theFhirContext, String theUrl) Given a FHIR resource URL, extracts the associated resource type. Supported formats include the following inputs, all of which will return Patient. If no resource type can be determined, null will be returned.- Patient
- Patient?
- Patient?identifier=foo
- /Patient
- /Patient?
- /Patient?identifier=foo
- http://foo/base/Patient?identifier=foo
- http://foo/base/Patient/1
- http://foo/base/Patient/1/_history/2
- Patient/1
- Patient/1/_history/2
- /Patient/1
- /Patient/1/_history/2
-
escapeUrlParam
URL encode a value according to RFC 3986, except for the following characters:-_.*.This method is intended to be applied to an individual parameter name or value. For example, if you are creating the URL
http://example.com/fhir/Patient?key=føøit would be appropriate to pass the string "føø" to this method, but not appropriate to pass the entire URL since characters such as "/" and "?" would also be escaped.- See Also:
-
escapeUrlParam
URL encode a value according to RFC 3986, except for the following characters:-_.*, and optionally/.This method is intended to be applied to an individual parameter name or value. For example, if you are creating the URL
http://example.com/fhir/Patient?key=føøit would be appropriate to pass the string "føø" to this method, but not appropriate to pass the entire URL since characters such as "?" and possibly "/" would also be escaped.- Parameters:
theEscapeSlash- Iftrue, the slash character will be percent-escaped. Set this to false if you are escaping a query parameter value, since slashes will be more readable in the URL than the percent-encoded version. If you aren't sure where the escaped version will appear, always set this tofalse, or just callescapeUrlParam(String)instead.- Since:
- 8.6.0
-
escapeUrlParams
Applies the same encodong asescapeUrlParam(String)but against all values in a collection -
isAbsolute
-
isNeedsSanitization
-
isValid
-
parseUrlResourceType
public static RuntimeResourceDefinition parseUrlResourceType(FhirContext theCtx, String theUrl) throws DataFormatException - Throws:
DataFormatException
-
parseQueryString
-
parseQueryStrings
-
normalizeCanonicalUrlForComparison
Normalizes canonical URLs for comparison. Trailing "/" is stripped, and any version identifiers or fragment hash is removed -
parseUrl
Parse a URL in one of the following forms:- [Resource Type]?[Search Params]
- [Resource Type]/[Resource ID]
- [Resource Type]/[Resource ID]/_history/[Version ID]
-
sanitizeUrlPart
This method specifically HTML-encodes the " and < characters in order to prevent injection attacks -
sanitizeUrlPart
This method specifically HTML-encodes the " and < characters in order to prevent injection attacks.The following characters are escaped:
- '
- "
- <
- >
- \n (newline)
-
sanitizeUrlPart
Applies the same logic assanitizeUrlPart(CharSequence)but against an array, returning an array with the same strings as the input but with sanitization applied -
unescape
-
getAboveUriCandidates
Creates list of sub URIs candidates for search with :above modifier Example input: http://[host]/[pathPart1]/[pathPart2] Example output: http://[host], http://[host]/[pathPart1], http://[host]/[pathPart1]/[pathPart2]- Parameters:
theUri- String URI parameter- Returns:
- List of URI candidates
-