public class Util
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
assembleHeader(java.util.Vector pheader)
Assembles a Vector of HttpHeaderElements into a full header string.
|
static int |
defaultPort(java.lang.String protocol)
Deprecated.
use URI.defaultPort() instead
|
static java.lang.String |
dequoteString(java.lang.String str)
Replace quoted characters by their unquoted version.
|
static HttpHeaderElement |
getElement(java.util.Vector header,
java.lang.String name)
Get the HttpHeaderElement with the name name.
|
static java.lang.String |
getFragment(java.lang.String resource)
Extract the fragment part from an http resource.
|
static java.lang.String |
getParameter(java.lang.String param,
java.lang.String hdr)
retrieves the value associated with the parameter param in
a given header string.
|
static java.lang.String |
getParams(java.lang.String resource)
Extract the params part from an http resource.
|
static java.lang.String |
getPath(java.lang.String resource)
Extract the path from an http resource.
|
static java.lang.String |
getQuery(java.lang.String resource)
Extract the query string from an http resource.
|
static boolean |
hasToken(java.lang.String header,
java.lang.String token)
Determines if the given header contains a certain token.
|
static java.lang.String |
httpDate(java.util.Date date)
This returns a string containing the date and time in date
formatted according to a subset of RFC-1123.
|
static java.util.Vector |
parseHeader(java.lang.String header)
This parses the value part of a header.
|
static java.util.Vector |
parseHeader(java.lang.String header,
boolean dequote)
This parses the value part of a header.
|
static java.lang.String |
quoteString(java.lang.String str,
java.lang.String qlist)
Replace given characters by their quoted version.
|
static boolean |
sameHttpURL(java.net.URL url1,
java.net.URL url2)
Compares two http urls for equality.
|
static boolean |
wildcardMatch(java.lang.String pattern,
java.lang.String name)
Match pattern against name, where
pattern may contain wildcards ('*').
|
public static final java.lang.String dequoteString(java.lang.String str)
str
- the string do dequotepublic static final java.lang.String quoteString(java.lang.String str, java.lang.String qlist)
str
- the string do quoteqlist
- the list of characters to quotepublic static final java.util.Vector parseHeader(java.lang.String header) throws ParseException
header
- the value part of the header.ParseException
- if the syntax rules are violated.parseHeader(java.lang.String, boolean)
public static final java.util.Vector parseHeader(java.lang.String header, boolean dequote) throws ParseException
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 = "\" charAny 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.
header
- the value part of the header.dequote
- if true all quoted strings are dequoted.ParseException
- if the above syntax rules are violated.HttpHeaderElement
public static final boolean hasToken(java.lang.String header, java.lang.String token) throws ParseException
header
- the header value.token
- the token to find; the match is case-insensitive.ParseException
- if this is thrown parseHeader().parseHeader(java.lang.String)
public static final HttpHeaderElement getElement(java.util.Vector header, java.lang.String name)
header
- a vector of HttpHeaderElement's, such as is returned
from parseHeader()
name
- the name of element to retrieve; matching is
case-insensitiveparseHeader(java.lang.String)
public static final java.lang.String getParameter(java.lang.String param, java.lang.String hdr) throws ParseException
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.
param
- the parameter namehdr
- the header valueParseException
- if the above syntax rules are violated.parseHeader(java.lang.String)
public static final java.lang.String assembleHeader(java.util.Vector pheader)
the
- parsed headerpublic static final boolean sameHttpURL(java.net.URL url1, java.net.URL url2)
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).
url1
- the first urlurl1
- the second urlpublic static final int defaultPort(java.lang.String protocol)
protocol
- the protocolURI.defaultPort(java.lang.String)
public static final java.lang.String httpDate(java.util.Date date)
Some versions of JDK 1.1.x are bugged in that their GMT uses daylight savings time... Therefore we use our own timezone definitions.
date
- the date and time to be convertedpublic static final java.lang.String getPath(java.lang.String 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-2616):
resource = [ "/" ] [ path ] [ ";" params ] [ "?" query ] [ "#" fragment ]
the
- resource to splitgetParams(java.lang.String)
,
getQuery(java.lang.String)
,
getFragment(java.lang.String)
public static final java.lang.String getParams(java.lang.String resource)
the
- resource to splitgetPath(java.lang.String)
public static final java.lang.String getQuery(java.lang.String resource)
the
- resource to splitgetPath(java.lang.String)
public static final java.lang.String getFragment(java.lang.String resource)
the
- resource to splitgetPath(java.lang.String)
public static final boolean wildcardMatch(java.lang.String pattern, java.lang.String name)
pattern
- the pattern to match; may contain '*' which match
any number (0 or more) of any character (think file
globbing)name
- the name to match against the pattern