com.caucho.portal.generic
Class HttpUtil

java.lang.Object
  extended by com.caucho.portal.generic.HttpUtil

public class HttpUtil
extends java.lang.Object

HTTP utilities. Encoding and decoding is for utf strings encoded with the rules defined for the "application/x-www-form-urlencoded" MIME format.


Constructor Summary
HttpUtil()
           
 
Method Summary
static java.lang.String decode(java.lang.String source)
          Decode a string.
static void decode(java.lang.StringBuffer source, int beginIndex, int endIndex, java.lang.StringBuffer dest)
          Extract and decode an encoded portion of a StringBuffer.
static void decode(java.lang.String source, int beginIndex, int endIndex, java.lang.StringBuffer dest)
          Extract and decode an encoded portion of a string.
static void decode(java.lang.String source, java.lang.StringBuffer dest)
          Decode a string.
static java.lang.String encode(java.lang.String source)
          Encode a string.
static void encode(java.lang.StringBuffer source, int beginIndex, int endIndex, java.lang.StringBuffer dest)
          Extract and encode a portion of a StringBuffer.
static void encode(java.lang.StringBuffer source, int beginIndex, int endIndex, java.io.Writer dest)
          Extract and encode a portion of a StringBuffer.
static void encode(java.lang.String source, int beginIndex, int endIndex, java.lang.StringBuffer dest)
          Extract and encode a portion of a String.
static void encode(java.lang.String source, int beginIndex, int endIndex, java.io.Writer dest)
          Extract and encode a portion of a String.
static void encode(java.lang.String source, java.lang.StringBuffer dest)
          Encode a string.
static void encode(java.lang.String source, java.io.Writer dest)
          Encode a string.
static void encodeUri(java.lang.CharSequence source, int beginIndex, int endIndex, java.lang.StringBuffer dest)
           
static void encodeUri(java.lang.CharSequence source, int beginIndex, int endIndex, java.io.Writer dest)
           
static java.lang.String extractParameters(java.util.Map<java.lang.String,java.lang.String[]> map, java.lang.String url)
          Extract and decode parameters out of the query string portion of the path and add them to the map.
static java.lang.String extractParameters(java.util.Map<java.lang.String,java.lang.String[]> map, java.lang.String url, int beginIndex)
          Extract and decode parameters out of the query string portion of the path and add them to the map.
static java.lang.String getFirstHeaderElement(java.lang.String headerValue)
          Return only the first header element, null if headerValue is null or there are no header elements.
static java.util.Set<java.lang.String> getHeaderElements(java.lang.String headerValue)
          Return an ordered Set of header elements from an http header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpUtil

public HttpUtil()
Method Detail

getHeaderElements

public static java.util.Set<java.lang.String> getHeaderElements(java.lang.String headerValue)
Return an ordered Set of header elements from an http header. If there are no header elements found, null is returned.
  text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.8, image/*; q=0.5
 
returns: Note that the qs value is ignored.

Returns:
null or a Set with at least one elemement

getFirstHeaderElement

public static java.lang.String getFirstHeaderElement(java.lang.String headerValue)
Return only the first header element, null if headerValue is null or there are no header elements. A headerValue with a String like "text/html; charset=xxx" returns "text/html". A headerValue with a String like " en; q=1.0, fr; q=0.8 " returns "en".


extractParameters

public static java.lang.String extractParameters(java.util.Map<java.lang.String,java.lang.String[]> map,
                                                 java.lang.String url)
Extract and decode parameters out of the query string portion of the path and add them to the map. The parameters are found by looking for the '?' character.

Parameters:
map - the Map to put the parameters in
url - the url

extractParameters

public static java.lang.String extractParameters(java.util.Map<java.lang.String,java.lang.String[]> map,
                                                 java.lang.String url,
                                                 int beginIndex)
Extract and decode parameters out of the query string portion of the path and add them to the map.

Parameters:
map - the Map to put the parameters in
url - the url
beginIndex - the index of the character that follows the '?' character

encode

public static java.lang.String encode(java.lang.String source)
Encode a string.

Parameters:
source - the String to encode
Returns:
the encoded String

encode

public static void encode(java.lang.String source,
                          java.lang.StringBuffer dest)
Encode a string.

Parameters:
source - the String to encode
dest - a StringBuffer that receives the encoded result

encode

public static void encode(java.lang.String source,
                          int beginIndex,
                          int endIndex,
                          java.lang.StringBuffer dest)
Extract and encode a portion of a String.

Parameters:
source - the String to encode
beginIndex - the begin index, inclusive
endIndex - the end index, exclusive
dest - a StringBuffer that receives the encoded result

encode

public static void encode(java.lang.StringBuffer source,
                          int beginIndex,
                          int endIndex,
                          java.lang.StringBuffer dest)
Extract and encode a portion of a StringBuffer.

Parameters:
source - the StringBuffer to encode
beginIndex - the begin index, inclusive
endIndex - the end index, exclusive
dest - a StringBuffer that receives the encoded result

encodeUri

public static void encodeUri(java.lang.CharSequence source,
                             int beginIndex,
                             int endIndex,
                             java.lang.StringBuffer dest)

encode

public static void encode(java.lang.String source,
                          java.io.Writer dest)
                   throws java.io.IOException
Encode a string.

Parameters:
source - the String to encode
dest - a Writer that receives the encoded result
Throws:
java.io.IOException

encode

public static void encode(java.lang.String source,
                          int beginIndex,
                          int endIndex,
                          java.io.Writer dest)
                   throws java.io.IOException
Extract and encode a portion of a String.

Parameters:
source - the String to encode
beginIndex - the begin index, inclusive
endIndex - the end index, exclusive
dest - a Writer that receives the encoded result
Throws:
java.io.IOException

encode

public static void encode(java.lang.StringBuffer source,
                          int beginIndex,
                          int endIndex,
                          java.io.Writer dest)
                   throws java.io.IOException
Extract and encode a portion of a StringBuffer.

Parameters:
source - the StringBuffer to encode
beginIndex - the begin index, inclusive
endIndex - the end index, exclusive
dest - a Writer that receives the encoded result
Throws:
java.io.IOException

encodeUri

public static void encodeUri(java.lang.CharSequence source,
                             int beginIndex,
                             int endIndex,
                             java.io.Writer dest)
                      throws java.io.IOException
Throws:
java.io.IOException

decode

public static java.lang.String decode(java.lang.String source)
Decode a string.

Parameters:
source - the String to decode
Returns:
the decoded String

decode

public static void decode(java.lang.String source,
                          java.lang.StringBuffer dest)
Decode a string.

Parameters:
source - the String to decode
dest - a StringBuffer that receives the decoded result

decode

public static void decode(java.lang.String source,
                          int beginIndex,
                          int endIndex,
                          java.lang.StringBuffer dest)
Extract and decode an encoded portion of a string.

Parameters:
source - the String to extract from
beginIndex - the begin index, inclusive
endIndex - the end index, exclusive
dest - a StringBuffer that receives the decoded result

decode

public static void decode(java.lang.StringBuffer source,
                          int beginIndex,
                          int endIndex,
                          java.lang.StringBuffer dest)
Extract and decode an encoded portion of a StringBuffer.

Parameters:
source - the StringBuffer to extract from
beginIndex - the begin index, inclusive
endIndex - the end index, exclusive
dest - a StringBuffer that receives the decoded result