org.apache.batik.util
public class ParsedURL extends Object
This class is used as a replacement for java.net.URL. This is done for several reasons. First, unlike java.net.URL this class will accept and parse as much of a URL as possible, without throwing a java.net.MalformedURLException. This makes it useful for simply parsing a URL string (hence its name).
Second, it allows for extension of the URI schemes supported by the
parser. Batik uses this to support the
data:
URL scheme (RFC2397).
Third, by default it checks the streams that it opens to see if they are GZIP compressed, and if so it automatically uncompresses them (avoiding opening the stream twice in the process).
It is worth noting that most real work is defered to the ParsedURLData class to which most methods are forwarded. This is done because it allows a constructor interface to ParsedURL (mostly for compatability with core URL), in spite of the fact that the real implemenation uses the protocol handlers as factories for protocol specific instances of the ParsedURLData class.
Constructor Summary | |
---|---|
ParsedURL(String urlStr)
Construct a ParsedURL from the given url string. | |
ParsedURL(URL url)
Construct a ParsedURL from the given java.net.URL instance.
| |
ParsedURL(String baseStr, String urlStr)
Construct a sub URL from two strings. | |
ParsedURL(URL baseURL, String urlStr)
Construct a sub URL from a base URL and a string for the sub url. | |
ParsedURL(ParsedURL baseURL, String urlStr)
Construct a sub URL from a base ParsedURL and a string for the sub url. |
Method Summary | |
---|---|
static InputStream | checkGZIP(InputStream is)
This is a utility function others can call that checks if
is is a GZIP stream if so it returns a GZIPInputStream that
will decode the contents, otherwise it returns (or a
buffered version of is) untouched. |
boolean | complete()
Returns true if the URL looks well formed and complete.
|
boolean | equals(Object obj)
Implement Object.equals.
|
String | getContentEncoding()
Returns the content encoding if available. |
String | getContentType()
Returns the content type if available. |
String | getContentTypeCharset()
Returns the content type's charset parameter, if available. |
String | getContentTypeMediaType()
Returns the content type's type/subtype, if available. |
static String | getGlobalUserAgent() |
static ParsedURLProtocolHandler | getHandler(String protocol)
Returns the handler for a particular protocol. |
String | getHost()
Returns the host for this URL, if any, null if there isn't
one or it doesn't make sense for the protocol. |
String | getPath()
Returns the path for this URL, if any (where appropriate for
the protocol this also includes the file, not just directory).
|
int | getPort()
Returns the port on the host to connect to, if it was specified
in the url that was parsed, otherwise returns -1. |
String | getPortStr()
Returns the URL up to and include the port number on
the host. |
String | getProtocol()
Returns the protocol for this URL.
|
protected static String | getProtocol(String urlStr)
Parse out the protocol from a url string. |
String | getRef()
Returns the 'fragment' reference in the URL. |
String | getUserAgent()
Return the user agent current associated with this url (or
null if none). |
boolean | hasContentTypeParameter(String param)
Returns whether the Content-Type header has the given parameter. |
int | hashCode()
Implement Object.hashCode.
|
InputStream | openStream()
Attempt to open the stream checking for common compression
types, and automatically decompressing them if found. |
InputStream | openStream(String mimeType)
Attempt to open the stream checking for common compression
types, and automatically decompressing them if found. |
InputStream | openStream(String[] mimeTypes)
Attempt to open the stream checking for common compression
types, and automatically decompressing them if found. |
InputStream | openStream(Iterator mimeTypes)
Attempt to open the stream checking for common compression
types, and automatically decompressing them if found. |
InputStream | openStreamRaw()
Attempt to open the stream, does no checking for compression
types. |
InputStream | openStreamRaw(String mimeType)
Attempt to open the stream, does no checking for compression
types. |
InputStream | openStreamRaw(String[] mimeTypes)
Attempt to open the stream, does no checking for comression
types. |
InputStream | openStreamRaw(Iterator mimeTypes)
Attempt to open the stream, does no checking for comression
types. |
static ParsedURLData | parseURL(String urlStr)
Factory method to construct an appropriate subclass of ParsedURLData |
static ParsedURLData | parseURL(String baseStr, String urlStr)
Factory method to construct an appropriate subclass of ParsedURLData,
for a sub url. |
static ParsedURLData | parseURL(ParsedURL baseURL, String urlStr)
Factory method to construct an appropriate subclass of ParsedURLData,
for a sub url. |
static void | registerHandler(ParsedURLProtocolHandler handler)
Registers a Protocol handler by adding it to the handlers map.
|
boolean | sameFile(ParsedURL other) |
static void | setGlobalUserAgent(String userAgent) |
void | setUserAgent(String userAgent)
Sets the user agent associated with this url (null clears
any associated user agent). |
String | toString()
Return a string rep of the URL (can be passed back into the
constructor if desired). |
Parameters: urlStr The string to try and parse as a URL
Parameters: url The URL to "mimic".
Parameters: baseStr The 'parent' URL. Should be complete. urlStr The 'sub' URL may be complete or partial. the missing pieces will be taken from the baseStr.
Parameters: baseURL The 'parent' URL. urlStr The 'sub' URL may be complete or partial. the missing pieces will be taken from the baseURL.
Parameters: baseURL The 'parent' URL. urlStr The 'sub' URL may be complete or partial. the missing pieces will be taken from the baseURL.
Parameters: is Stream that may potentially be a GZIP stream.
Parameters: protocol The protocol to get a handler for.
Parameters: mimeType The expected mime type of the content in the returned InputStream (mapped to Http accept header among other possabilities).
Parameters: mimeTypes The expected mime types of the content in the returned InputStream (mapped to Http accept header among other possabilities).
Parameters: mimeTypes The expected mime types of the content in the returned InputStream (mapped to Http accept header among other possabilities). The elements of the iterator must be strings.
Parameters: mimeType The expected mime type of the content in the returned InputStream (mapped to Http accept header among other possabilities).
Parameters: mimeTypes The expected mime types of the content in the returned InputStream (mapped to Http accept header among other possabilities).
Parameters: mimeTypes The expected mime types of the content in the returned InputStream (mapped to Http accept header among other possabilities). The elements of the iterator must be strings.
Parameters: urlStr the string to parse.
Parameters: baseStr The base URL string to parse. urlStr the sub URL string to parse.
Parameters: baseURL The base ParsedURL to parse. urlStr the sub URL string to parse.
Parameters: handler the new Protocol Handler to register