All Packages Class Hierarchy This Package Previous Next Index
Class HTTPClient.Util
java.lang.Object
|
+----HTTPClient.Util
- public class Util
- extends Object
This class holds various utility methods.
- Version:
- 0.3 30/01/1998
- Author:
- Ronald Tschalär
-
assembleHeader(Vector)
- Assembles a Vector of HttpHeaderElements into a full header string.
-
defaultPort(String)
- Return the default port used by a given protocol.
-
dequoteString(String)
- Replace quoted characters by their unquoted version.
-
getElement(Vector, String)
- Get the HttpHeaderElement with the name name.
-
getFragment(String)
- Extract the fragment part from an http resource.
-
getParameter(String, String)
- retrieves the value associated with the parameter param in
a given header string.
-
getParams(String)
- Extract the params part from an http resource.
-
getPath(String)
- Extract the path from an http resource.
-
getQuery(String)
- Extract the query string from an http resource.
-
hasToken(String, String)
- Determines if the given header contains a certain token.
-
httpDate(Date)
- This returns a string containing the date and time in date
formatted according to a subset of RFC-1123.
-
parseHeader(String)
- This parses the value part of a header.
-
parseHeader(String, boolean)
- This parses the value part of a header.
-
quoteString(String, String)
- Replace given characters by their quoted version.
-
sameHttpURL(URL, URL)
- Compares two http urls for equality.
dequoteString
public static final String dequoteString(String str)
- Replace quoted characters by their unquoted version. Quoted characters
are characters preceded by a slash. E.g. "\c" would be replaced by "c".
This is used in parsing http headers where quoted-characters are
allowed in quoted-strings and often used to quote the quote character
<">.
- Parameters:
- str - the string do dequote
- Returns:
- the string do with all quoted characters replaced by their
true value.
quoteString
public static final String quoteString(String str,
String qlist)
- Replace given characters by their quoted version. Quoted characters
are characters preceded by a slash. E.g. "c" would be replaced by "\c".
This is used in generating http headers where certain characters need
to be quoted, such as the quote character <">.
- Parameters:
- str - the string do quote
- qlist - the list of characters to quote
- Returns:
- the string do with all characters replaced by their
quoted version.
parseHeader
public static final Vector parseHeader(String header) throws ParseException
- This parses the value part of a header. All quoted strings are
dequoted.
- Parameters:
- header - the value part of the header.
- Returns:
- a Vector containing all the elements; each entry is an
instance of HttpHeaderElement.
- Throws:
ParseException
- if the syntax rules are violated.
- See Also:
- parseHeader
parseHeader
public static final Vector parseHeader(String header,
boolean dequote) throws ParseException
- This parses the value part of a header. The result is a Vector of
HttpHeaderElement's. The syntax the header must conform to is:
header = [ element ] *( "," [ element ] )
element = name [ "=" [ value ] ] *( ";" [ param ] )
param = name [ "=" [ value ] ]
name = token
value = ( token | quoted-string )
token = 1*<any char except "=", ",", ";", <"> and
white space>
quoted-string = <"> *( text | quoted-char ) <">
text = any char except <">
quoted-char = "\" char
Any amount of white space is allowed between any part of the header,
element or param and is ignored. A missing value in any element or
param will be stored as the empty string; if the "=" is also missing
null will be stored instead.
- Parameters:
- header - the value part of the header.
- dequote - if true all quoted strings are dequoted.
- Returns:
- a Vector containing all the elements; each entry is an
instance of HttpHeaderElement.
- Throws:
ParseException
- if the above syntax rules are violated.
- See Also:
- HttpHeaderElement
hasToken
public static final boolean hasToken(String header,
String token) throws ParseException
- Determines if the given header contains a certain token. The header
must conform to the rules outlined in parseHeader().
- Parameters:
- header - the header value.
- token - the token to find; the match is case-insensitive.
- Returns:
- true if the token is present, false otherwise.
- Throws:
ParseException
- if this is thrown parseHeader().
- See Also:
- parseHeader
getElement
public static final HttpHeaderElement getElement(Vector header,
String name)
- Get the HttpHeaderElement with the name name.
- Parameters:
- header - a vector of HttpHeaderElement's, such as is returned
from
parseHeader()
- name - the name of element to retrieve; matching is
case-insensitive
- Returns:
- the request element, or null if none found.
- See Also:
- parseHeader
getParameter
public static final String getParameter(String param,
String hdr) throws ParseException
- retrieves the value associated with the parameter param in
a given header string. It parses the header using
parseHeader()
and then searches the first element for the
given parameter. This is used especially in headers like
'Content-type' and 'Content-Disposition'.
quoted characters ("\x") in a quoted string are dequoted.
- Parameters:
- param - the parameter name
- hdr - the header value
- Returns:
- the value for this parameter, or null if not found.
- Throws:
ParseException
- if the above syntax rules are violated.
- See Also:
- parseHeader
assembleHeader
public static final String assembleHeader(Vector pheader)
- Assembles a Vector of HttpHeaderElements into a full header string.
The individual header elements are seperated by a ", ".
- Parameters:
- the - parsed header
- Returns:
- a string containing the assembled header
sameHttpURL
public static final boolean sameHttpURL(URL url1,
URL url2)
- Compares two http urls for equality. This exists because the method
java.net.URL.sameFile()
is broken (an explicit port 80
doesn't compare equal to an implicit port, and it doesn't take
escapes into account).
Two http urls are considered equal if they have the same protocol
(case-insensitive match), the same host (case-insensitive), the
same port and the same file (after decoding escaped characters).
- Parameters:
- url1 - the first url
- url1 - the second url
- Returns:
- true if url1 and url2 compare equal
defaultPort
public static final int defaultPort(String protocol)
- Return the default port used by a given protocol.
- Parameters:
- protocol - the protocol
- Returns:
- the port number, or 0 if unknown
httpDate
public static final String httpDate(Date date)
- This returns a string containing the date and time in date
formatted according to a subset of RFC-1123. The format is defined in
the HTTP/1.0 spec (RFC-1945), section 3.3, and the HTTP/1.1 spec
(RFC-2068), section 3.3.1. Note that Date.toGMTString() is close, but
is missing the weekday and supresses the leading zero if the day is
less than the 10th. Instead we use the SimpleDateFormat class.
Some versions of JDK 1.1.x are bugged in that their GMT uses
daylight savings time... Therefore we use our own timezone
definitions.
- Parameters:
- date - the date and time to be converted
- Returns:
- a string containg the date and time as used in http
getPath
public static final String getPath(String resource)
- Extract the path from an http resource.
The "resource" part of an HTTP URI can contain a number of parts,
some of which are not always of interest. These methods here will
extract the various parts, assuming the following syntanx (taken from
RFC-2068):
resource = [ "/" ] [ path ] [ ";" params ] [ "?" query ] [ "#" fragment ]
- Parameters:
- the - resource to split
- Returns:
- the path, including any leading "/"
- See Also:
- getParams, getQuery, getFragment
getParams
public static final String getParams(String resource)
- Extract the params part from an http resource.
- Parameters:
- the - resource to split
- Returns:
- the params, or null if there are none
- See Also:
- getPath
getQuery
public static final String getQuery(String resource)
- Extract the query string from an http resource.
- Parameters:
- the - resource to split
- Returns:
- the query, or null if there was none
- See Also:
- getPath
getFragment
public static final String getFragment(String resource)
- Extract the fragment part from an http resource.
- Parameters:
- the - resource to split
- Returns:
- the fragment, or null if there was none
- See Also:
- getPath
All Packages Class Hierarchy This Package Previous Next Index