Class UrlUtil


public class UrlUtil extends Object
  • Method Details

    • sanitizeHeaderValue

      public static String sanitizeHeaderValue(String theHeader)
      Cleans up a value that will be serialized as an HTTP header. This method:

      - Strips any newline (\r or \n) characters

    • sanitizeBaseUrl

      public static String sanitizeBaseUrl(String theBaseUrl)
    • constructAbsoluteUrl

      public static String constructAbsoluteUrl(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.
    • constructRelativeUrl

      public static String constructRelativeUrl(String theParentExtensionUrl, String theExtensionUrl)
    • 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

      public static String escapeUrlParam(String theUnescaped)
      URL encode a value according to RFC 3986

      This method is intended to be applied to an individual parameter name or value. For example, if you are creating the URL 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.

    • escapeUrlParams

      public static List<String> escapeUrlParams(@Nonnull Collection<String> theUnescaped)
      Applies the same encodong as escapeUrlParam(String) but against all values in a collection
    • isAbsolute

      public static boolean isAbsolute(String theValue)
    • isNeedsSanitization

      public static boolean isNeedsSanitization(CharSequence theString)
    • isValid

      public static boolean isValid(String theUrl)
    • parseUrlResourceType

    • parseQueryString

      @Nonnull public static Map<String,String[]> parseQueryString(String theQueryString)
    • parseQueryStrings

      public static Map<String,String[]> parseQueryStrings(String... theQueryString)
    • normalizeCanonicalUrlForComparison

      Normalizes canonical URLs for comparison. Trailing "/" is stripped, and any version identifiers or fragment hash is removed
    • parseUrl

      public static UrlUtil.UrlParts parseUrl(String theUrl)
      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

      public static String sanitizeUrlPart(IPrimitiveType<?> theString)
      This method specifically HTML-encodes the " and < characters in order to prevent injection attacks
    • sanitizeUrlPart

      public static String sanitizeUrlPart(CharSequence theString)
      This method specifically HTML-encodes the " and < characters in order to prevent injection attacks.

      The following characters are escaped:

      • '
      • "
      • <
      • >
      • \n (newline)
    • sanitizeUrlPart

      public static String[] sanitizeUrlPart(String[] theParameterValues)
      Applies the same logic as sanitizeUrlPart(CharSequence) but against an array, returning an array with the same strings as the input but with sanitization applied
    • unescape

      public static String unescape(String theString)
    • translateMatchUrl

      public static List<org.apache.http.NameValuePair> translateMatchUrl(String theMatchUrl)
    • getAboveUriCandidates

      public static List<String> getAboveUriCandidates(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]
      theUri - String URI parameter
      List of URI candidates