SK.gnome.dwarf.http
Class HTTPUtils

java.lang.Object
  extended bySK.gnome.dwarf.http.HTTPUtils

public class HTTPUtils
extends java.lang.Object

Provides various HTTP-related utilities.

Can be used instead of the javax.servlet.http.HttpUtils class.


Constructor Summary
HTTPUtils()
           
 
Method Summary
static java.lang.String encodeTags(java.lang.String s)
          Encodes the < and > tags to HTML entities.
static java.lang.String escapeURL(java.lang.String s, java.lang.String enc)
          Escapes the given URL.
static java.lang.StringBuffer getRequestURL(Request request)
          Reconstructs the URL from the given request object.
static void parseMultipartData(java.util.Map parameters, java.util.Map attributes, int len, java.io.InputStream in, java.lang.String contentType)
          Parses the data obtained from the multipart POST request body.
static void parsePostData(java.util.Map parameters, int len, java.io.InputStream in, java.lang.String enc)
          Parses the data obtained from the POST request.
static void parseQueryString(java.util.Map parameters, java.lang.String s, java.lang.String enc)
          Parses the query string.
static java.lang.String unescapeURL(java.lang.String s, java.lang.String enc)
          Unescapes the given URL.
static java.lang.String urlDecode(java.lang.String s, java.lang.String enc)
          Decodes a MIME format called x-www-form-urlencoded to string.
static java.lang.String urlEncode(java.lang.String s, java.lang.String enc)
          Encodes a string into a MIME format called x-www-form-urlencoded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTTPUtils

public HTTPUtils()
Method Detail

getRequestURL

public static java.lang.StringBuffer getRequestURL(Request request)
Reconstructs the URL from the given request object.

The returned URL consists of a protocol, server name, port number and URI path, but it does not include the query string parameters. It is encoded according to the x-www-form-urlencoded format.

Parameters:
request - the request
Returns:
the URL

urlDecode

public static java.lang.String urlDecode(java.lang.String s,
                                         java.lang.String enc)
                                  throws java.io.IOException
Decodes a MIME format called x-www-form-urlencoded to string.

The decoded ocets are converted to Java string using the given encoding.

Parameters:
s - the encoded string
enc - the encoding
Returns:
the decoded string
Throws:
java.io.IOException - if the encoding is not valid

unescapeURL

public static java.lang.String unescapeURL(java.lang.String s,
                                           java.lang.String enc)
                                    throws java.io.IOException
Unescapes the given URL.

The unescaped octets are converted to characters using the given encoding.

Parameters:
s - the escaped string
enc - the encoding
Returns:
the unescaped string
Throws:
java.io.IOException - if the encoding is not valid

urlEncode

public static java.lang.String urlEncode(java.lang.String s,
                                         java.lang.String enc)
                                  throws java.io.IOException
Encodes a string into a MIME format called x-www-form-urlencoded.

String is converted to octets using the given encoding.

Parameters:
s - the string
enc - the encoding
Returns:
the encoded string
Throws:
java.io.IOException - if the encoding is not valid or an error occured

escapeURL

public static java.lang.String escapeURL(java.lang.String s,
                                         java.lang.String enc)
                                  throws java.io.IOException
Escapes the given URL.

Characters are converted to octets using the given encoding.

Parameters:
s - the string
enc - the encoding
Returns:
the escaped string
Throws:
java.io.IOException - if the encoding is not valid or an error occured

encodeTags

public static java.lang.String encodeTags(java.lang.String s)
Encodes the < and > tags to HTML entities.

Parameters:
s - the input string
Returns:
encoded string

parseQueryString

public static void parseQueryString(java.util.Map parameters,
                                    java.lang.String s,
                                    java.lang.String enc)
                             throws java.io.IOException
Parses the query string.

The parsed parameters will be appended to the given Map. The query string must be in the x-www-form-urlencoded format. The decoded data is converted to string according to the given encoding.

Parameters:
parameters - the parameters
s - the query string
enc - the encoding
Throws:
java.io.IOException - if the encoding is not valid

parsePostData

public static void parsePostData(java.util.Map parameters,
                                 int len,
                                 java.io.InputStream in,
                                 java.lang.String enc)
                          throws java.io.IOException
Parses the data obtained from the POST request.

The parsed parameters will be appended to the given Map. The decoded parameters are converted to strings according to the given encoding.

Parameters:
parameters - the parameters
len - the length of the POST body
in - the input stream
enc - the encoding
Throws:
java.io.IOException - if an error occured during the parsing
java.io.UnsupportedEncodingException - if the encoding ist no supported

parseMultipartData

public static void parseMultipartData(java.util.Map parameters,
                                      java.util.Map attributes,
                                      int len,
                                      java.io.InputStream in,
                                      java.lang.String contentType)
                               throws java.io.IOException
Parses the data obtained from the multipart POST request body.

Multipart data are typically used by HTML forms for file-uploading via the PUT method. The parsed parameters will be appended to the given Map.

Parameters:
parameters - the parameters
len - the length of the POST body
in - the input stream
contentType - the content-type of data
Throws:
java.io.IOException - if an error occured during the parsing


Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.