org.modeshape.webdav.fromcatalina

## Class RequestUtil

- java.lang.Object
- - org.modeshape.webdav.fromcatalina.RequestUtil

-     public final class RequestUtil
      extends Object

  General purpose request parsing and encoding utility methods.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RequestUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `encodeCookie(Cookie cookie)` Encode a cookie as per RFC 2109.
    `static String` | `filter(String message)` Filter the specified message string for characters that are sensitive in HTML.
    `static String` | `normalize(String path)` Normalize a relative URI path that may have relative values ("/./", "/../", and so on ) it it.
    `static String` | `parseCharacterEncoding(String contentType)` Parse the character encoding from the specified content type header.
    `static Cookie[]` | `parseCookieHeader(String header)` Parse a cookie header into an array of cookies according to RFC 2109.
    `static void` | `parseParameters(Map<String,String[]> map, byte[] data, String encoding)` Append request parameters from the specified String to the specified Map.
    `static void` | `parseParameters(Map<String,String[]> map, String data, String encoding)` Append request parameters from the specified String to the specified Map.
    `static boolean` | `streamNotConsumed(HttpServletRequest request)` Checks if the input stream of the given request is nor isn't consumed.
    `static String` | `URLDecode(byte[] bytes)` Decode and return the specified URL-encoded byte array.
    `static String` | `URLDecode(byte[] bytes, String enc)` Decode and return the specified URL-encoded byte array.
    `static String` | `URLDecode(String str)` Decode and return the specified URL-encoded String.
    `static String` | `URLDecode(String str, String enc)` Decode and return the specified URL-encoded String.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RequestUtil

          public RequestUtil()

  - ### Method Detail

    - #### encodeCookie

          public static String encodeCookie(Cookie cookie)

      Encode a cookie as per RFC 2109. The resulting string can be used as the value for a `Set-Cookie` header.
      Parameters:
        `cookie` - The cookie to encode.
      Returns:
        A string following RFC 2109.

    - #### filter

          public static String filter(String message)

      Filter the specified message string for characters that are sensitive in HTML. This avoids potential attacks caused by including JavaScript codes in the request URL that is often reported in error messages.
      Parameters:
        `message` - The message string to be filtered
      Returns:
        the filtered message

    - #### normalize

          public static String normalize(String path)

      Normalize a relative URI path that may have relative values ("/./", "/../", and so on ) it it. WARNING - This method is useful only for normalizing application-generated paths. It does not try to perform security checks for malicious input.
      Parameters:
        `path` - Relative path to be normalized
      Returns:
        the normalized path

    - #### parseCharacterEncoding

          public static String parseCharacterEncoding(String contentType)

      Parse the character encoding from the specified content type header. If the content type is null, or there is no explicit character encoding, `null` is returned.
      Parameters:
        `contentType` - a content type header
      Returns:
        the character encoding

    - #### parseCookieHeader

          public static Cookie[] parseCookieHeader(String header)

      Parse a cookie header into an array of cookies according to RFC 2109.
      Parameters:
        `header` - Value of an HTTP "Cookie" header
      Returns:
        the cookies

    - #### parseParameters

          public static void parseParameters(Map<String,String[]> map,
                             String data,
                             String encoding)
                                      throws UnsupportedEncodingException

      Append request parameters from the specified String to the specified Map. It is presumed that the specified Map is not accessed from any other thread, so no synchronization is performed.

      IMPLEMENTATION NOTE: URL decoding is performed individually on the parsed name and value elements, rather than on the entire query string ahead of time, to properly deal with the case where the name or value includes an encoded "=" or "&" character that would otherwise be interpreted as a delimiter.

      Parameters:
        `map` - Map that accumulates the resulting parameters
        `data` - Input string containing request parameters
        `encoding` -
      Throws:
        `UnsupportedEncodingException` - if the data is malformed

    - #### URLDecode

          public static String URLDecode(String str)

      Decode and return the specified URL-encoded String. When the byte array is converted to a string, the system default character encoding is used... This may be different than some other servers.
      Parameters:
        `str` - The url-encoded string
      Returns:
        the decoded URL
      Throws:
        `IllegalArgumentException` - if a '%' character is not followed by a valid 2-digit hexadecimal number

    - #### URLDecode

          public static String URLDecode(String str,
                         String enc)

      Decode and return the specified URL-encoded String.
      Parameters:
        `str` - The url-encoded string
        `enc` - The encoding to use; if null, the default encoding is used
      Returns:
        the decoded URL
      Throws:
        `IllegalArgumentException` - if a '%' character is not followed by a valid 2-digit hexadecimal number

    - #### URLDecode

          public static String URLDecode(byte[] bytes)

      Decode and return the specified URL-encoded byte array.
      Parameters:
        `bytes` - The url-encoded byte array
      Returns:
        the decoded URL
      Throws:
        `IllegalArgumentException` - if a '%' character is not followed by a valid 2-digit hexadecimal number

    - #### URLDecode

          public static String URLDecode(byte[] bytes,
                         String enc)

      Decode and return the specified URL-encoded byte array.
      Parameters:
        `bytes` - The url-encoded byte array
        `enc` - The encoding to use; if null, the default encoding is used
      Returns:
        the decoded URL
      Throws:
        `IllegalArgumentException` - if a '%' character is not followed by a valid 2-digit hexadecimal number

    - #### parseParameters

          public static void parseParameters(Map<String,String[]> map,
                             byte[] data,
                             String encoding)
                                      throws UnsupportedEncodingException

      Append request parameters from the specified String to the specified Map. It is presumed that the specified Map is not accessed from any other thread, so no synchronization is performed.

      IMPLEMENTATION NOTE: URL decoding is performed individually on the parsed name and value elements, rather than on the entire query string ahead of time, to properly deal with the case where the name or value includes an encoded "=" or "&" character that would otherwise be interpreted as a delimiter. NOTE: byte array data is modified by this method. Caller beware.

      Parameters:
        `map` - Map that accumulates the resulting parameters
        `data` - Input string containing request parameters
        `encoding` - Encoding to use for converting hex
      Throws:
        `UnsupportedEncodingException` - if the data is malformed

    - #### streamNotConsumed

          public static boolean streamNotConsumed(HttpServletRequest request)

      Checks if the input stream of the given request is nor isn't consumed. This method is backwards-compatible with Servlet 2.x, as in Servlet 3.x there is a "isFinished" method.
      Parameters:
        `request` - a `HttpServletRequest`, never `null`
      Returns:
        `true` if the request stream has been consumed, `false` otherwise.

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.