Class UriParser


  • public final class UriParser
    extends java.lang.Object
    Utilities for dealing with URIs. See RFC 2396 for details.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char TRANS_SEPARATOR
      The set of valid separators.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void appendEncoded​(java.lang.StringBuilder buffer, java.lang.String unencodedValue, char[] reserved)
      Encodes and appends a string to a StringBuilder.
      static void canonicalizePath​(java.lang.StringBuilder buffer, int offset, int length, FileNameParser fileNameParser)
      Canonicalizes a path.
      static void checkUriEncoding​(java.lang.String uri)
      Decodes the String.
      static java.lang.String decode​(java.lang.String encodedStr)
      Removes %nn encodings from a string.
      static void decode​(java.lang.StringBuilder buffer, int offset, int length)
      Removes %nn encodings from a string.
      static java.lang.String encode​(java.lang.String decodedStr)
      Converts "special" characters to their %nn value.
      static java.lang.String[] encode​(java.lang.String[] strings)
      Encode an array of Strings.
      static void encode​(java.lang.StringBuilder buffer, int offset, int length, char[] reserved)
      Encodes a set of reserved characters in a StringBuilder, using the URI %nn encoding.
      static java.lang.String encode​(java.lang.String decodedStr, char[] reserved)
      Converts "special" characters to their %nn value.
      static java.lang.String extractFirstElement​(java.lang.StringBuilder name)
      Extracts the first element of a path.
      static java.lang.String extractQueryString​(java.lang.StringBuilder name)
      Extract the query String from the URI.
      static java.lang.String extractScheme​(java.lang.String uri)
      Deprecated.
      static java.lang.String extractScheme​(java.lang.String[] schemes, java.lang.String uri)
      Extracts the scheme from a URI.
      static java.lang.String extractScheme​(java.lang.String[] schemes, java.lang.String uri, java.lang.StringBuilder buffer)
      Extracts the scheme from a URI.
      static java.lang.String extractScheme​(java.lang.String uri, java.lang.StringBuilder buffer)
      Deprecated.
      static boolean fixSeparators​(java.lang.StringBuilder name)
      Normalises the separators in a name.
      static FileType normalisePath​(java.lang.StringBuilder path)
      Normalises a path.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TRANS_SEPARATOR

        public static final char TRANS_SEPARATOR
        The set of valid separators. These are all converted to the normalized one. Does not contain the normalized separator
        See Also:
        Constant Field Values
    • Method Detail

      • appendEncoded

        public static void appendEncoded​(java.lang.StringBuilder buffer,
                                         java.lang.String unencodedValue,
                                         char[] reserved)
        Encodes and appends a string to a StringBuilder.
        Parameters:
        buffer - The StringBuilder to append to.
        unencodedValue - The String to encode and append.
        reserved - characters to encode.
      • canonicalizePath

        public static void canonicalizePath​(java.lang.StringBuilder buffer,
                                            int offset,
                                            int length,
                                            FileNameParser fileNameParser)
                                     throws FileSystemException
        Canonicalizes a path.
        Parameters:
        buffer - Source data.
        offset - Where to start reading.
        length - How much to read.
        fileNameParser - Now to encode and decode.
        Throws:
        FileSystemException - If an I/O error occurs.
      • checkUriEncoding

        public static void checkUriEncoding​(java.lang.String uri)
                                     throws FileSystemException
        Decodes the String.
        Parameters:
        uri - The String to decode.
        Throws:
        FileSystemException - if an error occurs.
      • decode

        public static java.lang.String decode​(java.lang.String encodedStr)
                                       throws FileSystemException
        Removes %nn encodings from a string.
        Parameters:
        encodedStr - The encoded String.
        Returns:
        The decoded String.
        Throws:
        FileSystemException - if an error occurs.
      • decode

        public static void decode​(java.lang.StringBuilder buffer,
                                  int offset,
                                  int length)
                           throws FileSystemException
        Removes %nn encodings from a string.
        Parameters:
        buffer - StringBuilder containing the string to decode.
        offset - The position in the string to start decoding.
        length - The number of characters to decode.
        Throws:
        FileSystemException - if an error occurs.
      • encode

        public static java.lang.String encode​(java.lang.String decodedStr)
        Converts "special" characters to their %nn value.
        Parameters:
        decodedStr - The decoded String.
        Returns:
        The encoded String.
      • encode

        public static java.lang.String encode​(java.lang.String decodedStr,
                                              char[] reserved)
        Converts "special" characters to their %nn value.
        Parameters:
        decodedStr - The decoded String.
        reserved - Characters to encode.
        Returns:
        The encoded String
      • encode

        public static java.lang.String[] encode​(java.lang.String[] strings)
        Encode an array of Strings.
        Parameters:
        strings - The array of Strings to encode.
        Returns:
        An array of encoded Strings.
      • encode

        public static void encode​(java.lang.StringBuilder buffer,
                                  int offset,
                                  int length,
                                  char[] reserved)
        Encodes a set of reserved characters in a StringBuilder, using the URI %nn encoding. Always encodes % characters.
        Parameters:
        buffer - The StringBuilder to append to.
        offset - The position in the buffer to start encoding at.
        length - The number of characters to encode.
        reserved - characters to encode.
      • extractFirstElement

        public static java.lang.String extractFirstElement​(java.lang.StringBuilder name)
        Extracts the first element of a path.
        Parameters:
        name - StringBuilder containing the path.
        Returns:
        The first element of the path.
      • extractQueryString

        public static java.lang.String extractQueryString​(java.lang.StringBuilder name)
        Extract the query String from the URI.
        Parameters:
        name - StringBuilder containing the URI.
        Returns:
        The query string, if any. null otherwise.
      • extractScheme

        @Deprecated
        public static java.lang.String extractScheme​(java.lang.String uri)
        Deprecated.
        Use instead extractScheme(java.lang.String). Will be removed in 3.0.
        Extracts the scheme from a URI.
        Parameters:
        uri - The URI.
        Returns:
        The scheme name. Returns null if there is no scheme.
      • extractScheme

        @Deprecated
        public static java.lang.String extractScheme​(java.lang.String uri,
                                                     java.lang.StringBuilder buffer)
        Deprecated.
        Use instead extractScheme(java.lang.String). Will be removed in 3.0.
        Extracts the scheme from a URI. Removes the scheme and ':' delimiter from the front of the URI.
        Parameters:
        uri - The URI.
        buffer - Returns the remainder of the URI.
        Returns:
        The scheme name. Returns null if there is no scheme.
      • extractScheme

        public static java.lang.String extractScheme​(java.lang.String[] schemes,
                                                     java.lang.String uri)
        Extracts the scheme from a URI. Removes the scheme and ':' delimiter from the front of the URI.

        The scheme is extracted based on the currently supported schemes in the system. That is to say the schemes supported by the registered providers.

        This allows us to handle varying scheme's without making assumptions based on the ':' character. Specifically handle scheme extraction calls for URI parameters that are not actually uri's, but may be names with ':' in them.

        Parameters:
        schemes - The schemes to check.
        uri - The potential URI. May also be a name.
        Returns:
        The scheme name. Returns null if there is no scheme.
        Since:
        2.3
      • extractScheme

        public static java.lang.String extractScheme​(java.lang.String[] schemes,
                                                     java.lang.String uri,
                                                     java.lang.StringBuilder buffer)
        Extracts the scheme from a URI. Removes the scheme and ':' delimiter from the front of the URI.

        The scheme is extracted based on the given set of schemes. Normally, that is to say the schemes supported by the registered providers.

        This allows us to handle varying scheme's without making assumptions based on the ':' character. Specifically handle scheme extraction calls for URI parameters that are not actually URI's, but may be names with ':' in them.

        Parameters:
        schemes - The schemes to check.
        uri - The potential URI. May also just be a name.
        buffer - Returns the remainder of the URI.
        Returns:
        The scheme name. Returns null if there is no scheme.
        Since:
        2.3
      • fixSeparators

        public static boolean fixSeparators​(java.lang.StringBuilder name)
        Normalises the separators in a name.
        Parameters:
        name - The StringBuilder containing the name
        Returns:
        true if the StringBuilder was modified.
      • normalisePath

        public static FileType normalisePath​(java.lang.StringBuilder path)
                                      throws FileSystemException
        Normalises a path. Does the following:
        • Removes empty path elements.
        • Handles '.' and '..' elements.
        • Removes trailing separator.
        Its assumed that the separators are already fixed.
        Parameters:
        path - The path to normalize.
        Returns:
        The FileType.
        Throws:
        FileSystemException - if an error occurs.
        See Also:
        fixSeparators(java.lang.StringBuilder)