Class URISupport


  • public final class URISupport
    extends Object
    Copied from org.apache.camel.util.URISupport
    • Field Detail

      • RAW_TOKEN_START

        public static final char[] RAW_TOKEN_START
      • RAW_TOKEN_END

        public static final char[] RAW_TOKEN_END
    • Method Detail

      • normalizeUri

        public static URI normalizeUri​(String uri)
                                throws URISyntaxException
        Normalizes the URI so unsafe characters is encoded
        Parameters:
        uri - the input uri
        Returns:
        as URI instance
        Throws:
        URISyntaxException - is thrown if syntax error in the input uri
      • stripQuery

        public static String stripQuery​(String uri)
        Strips the query parameters from the uri
        Parameters:
        uri - the uri
        Returns:
        the uri without the query parameter
      • parseParameters

        public static Map<String,​Object> parseParameters​(URI uri)
                                                        throws URISyntaxException
        Parses the query parameters of the uri (eg the query part).
        Parameters:
        uri - the uri
        Returns:
        the parameters, or an empty map if no parameters (eg never null)
        Throws:
        URISyntaxException - is thrown if uri has invalid syntax.
      • stripPrefix

        public static String stripPrefix​(String value,
                                         String prefix)
        Strips the prefix from the value.

        Returns the value as-is if not starting with the prefix.

        Parameters:
        value - the value
        prefix - the prefix to remove from value
        Returns:
        the value without the prefix
      • parseQuery

        public static Map<String,​Object> parseQuery​(String uri)
                                                   throws URISyntaxException
        Parses the query part of the uri (eg the parameters).

        The URI parameters will by default be URI encoded. However you can define a parameter values with the syntax: key=RAW(value) which tells Camel to not encode the value, and use the value as is (eg key=value) and the value has not been encoded.

        Parameters:
        uri - the uri
        Returns:
        the parameters, or an empty map if no parameters (eg never null)
        Throws:
        URISyntaxException - is thrown if uri has invalid syntax.
        See Also:
        RAW_TOKEN_START, RAW_TOKEN_END
      • parseQuery

        public static Map<String,​Object> parseQuery​(String uri,
                                                          boolean useRaw)
                                                   throws URISyntaxException
        Parses the query part of the uri (eg the parameters).

        The URI parameters will by default be URI encoded. However you can define a parameter values with the syntax: key=RAW(value) which tells Camel to not encode the value, and use the value as is (eg key=value) and the value has not been encoded.

        Parameters:
        uri - the uri
        useRaw - whether to force using raw values
        Returns:
        the parameters, or an empty map if no parameters (eg never null)
        Throws:
        URISyntaxException - is thrown if uri has invalid syntax.
        See Also:
        RAW_TOKEN_START, RAW_TOKEN_END
      • isRaw

        public static boolean isRaw​(int index,
                                    List<Pair<Integer>> pairs)
      • createQueryString

        public static String createQueryString​(Map<String,​String> options,
                                               String ampersand,
                                               boolean encode)
                                        throws URISyntaxException
        Assembles a query from the given map.
        Parameters:
        options - the map with the options (eg key/value pairs)
        ampersand - to use & for Java code, and & for XML
        Returns:
        a query string with key1=value&key2=value2&..., or an empty string if there is no options.
        Throws:
        URISyntaxException - is thrown if uri has invalid syntax.
      • isEmpty

        public static boolean isEmpty​(Object value)
        Tests whether the value is null or an empty string.
        Parameters:
        value - the value, if its a String it will be tested for text length as well
        Returns:
        true if empty
      • isNotEmpty

        public static boolean isNotEmpty​(Object value)
        Tests whether the value is not null or an empty string.
        Parameters:
        value - the value, if its a String it will be tested for text length as well
        Returns:
        true if not empty