|
|||||||||
| Home >> All >> org >> apache >> batik >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.batik.util
Class ParsedURL

java.lang.Objectorg.apache.batik.util.ParsedURL
- public class ParsedURL
- extends java.lang.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 MalformedURL exception. This makes it extreamly useful for simply parsing a URL string (hence it's name). Second it allows for extension of the protocols supported by the URL parser. Batik uses this to support the 'Data' protocol. Third by default it checks the streams that it opens to see if they are GZIP compressed, if so it automatically uncompresses them (avoiding opening the stream twice in the processes). 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.
- Version:
- $Id: ParsedURL.java,v 1.20 2004/10/08 16:12:01 deweese Exp $
| Field Summary | |
(package private) ParsedURLData |
data
The data class we defer most things to. |
private static ParsedURLProtocolHandler |
defaultHandler
The default protocol handler. |
private static java.lang.String |
globalUserAgent
|
private static java.util.Map |
handlersMap
This maps between protocol names and ParsedURLProtocolHandler instances. |
(package private) java.lang.String |
userAgent
The user agent to associate with this URL |
| Constructor Summary | |
ParsedURL(ParsedURL baseURL,
java.lang.String urlStr)
Construct a sub URL from a base ParsedURL and a string for the sub url. |
|
ParsedURL(java.lang.String urlStr)
Construct a ParsedURL from the given url string. |
|
ParsedURL(java.lang.String baseStr,
java.lang.String urlStr)
Construct a sub URL from two strings. |
|
ParsedURL(java.net.URL url)
Construct a ParsedURL from the given java.net.URL instance. |
|
ParsedURL(java.net.URL baseURL,
java.lang.String urlStr)
Construct a sub URL from a base URL and a string for the sub url. |
|
| Method Summary | |
static java.io.InputStream |
checkGZIP(java.io.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(java.lang.Object obj)
Implement Object.equals. |
java.lang.String |
getContentEncoding()
Returns the content encoding if available. |
java.lang.String |
getContentType()
Returns the content type if available. |
static java.lang.String |
getGlobalUserAgent()
|
static ParsedURLProtocolHandler |
getHandler(java.lang.String protocol)
Returns the handler for a particular protocol. |
private static java.util.Map |
getHandlersMap()
Returns the shared instance of HandlersMap. |
java.lang.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. |
java.lang.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. |
java.lang.String |
getPortStr()
Returns the URL up to and include the port number on the host. |
java.lang.String |
getProtocol()
Returns the protocol for this URL. |
protected static java.lang.String |
getProtocol(java.lang.String urlStr)
Parse out the protocol from a url string. |
java.lang.String |
getRef()
Returns the 'fragment' reference in the URL. |
java.lang.String |
getUserAgent()
Return the user agent current associated with this url (or null if none). |
int |
hashCode()
Implement Object.hashCode. |
java.io.InputStream |
openStream()
Attempt to open the stream checking for common compression types, and automatically decompressing them if found. |
java.io.InputStream |
openStream(java.util.Iterator mimeTypes)
Attempt to open the stream checking for common compression types, and automatically decompressing them if found. |
java.io.InputStream |
openStream(java.lang.String mimeType)
Attempt to open the stream checking for common compression types, and automatically decompressing them if found. |
java.io.InputStream |
openStream(java.lang.String[] mimeTypes)
Attempt to open the stream checking for common compression types, and automatically decompressing them if found. |
java.io.InputStream |
openStreamRaw()
Attempt to open the stream, does no checking for compression types. |
java.io.InputStream |
openStreamRaw(java.util.Iterator mimeTypes)
Attempt to open the stream, does no checking for comression types. |
java.io.InputStream |
openStreamRaw(java.lang.String mimeType)
Attempt to open the stream, does no checking for compression types. |
java.io.InputStream |
openStreamRaw(java.lang.String[] mimeTypes)
Attempt to open the stream, does no checking for comression types. |
static ParsedURLData |
parseURL(ParsedURL baseURL,
java.lang.String urlStr)
Factory method to construct an appropriate subclass of ParsedURLData, for a sub url. |
static ParsedURLData |
parseURL(java.lang.String urlStr)
Factory method to construct an appropriate subclass of ParsedURLData |
static ParsedURLData |
parseURL(java.lang.String baseStr,
java.lang.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(java.lang.String userAgent)
|
void |
setUserAgent(java.lang.String userAgent)
Sets the user agent associated with this url (null clears any associated user agent). |
java.lang.String |
toString()
Return a string rep of the URL (can be passed back into the constructor if desired). |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
data
ParsedURLData data
- The data class we defer most things to.
userAgent
java.lang.String userAgent
- The user agent to associate with this URL
handlersMap
private static java.util.Map handlersMap
- This maps between protocol names and ParsedURLProtocolHandler instances.
defaultHandler
private static ParsedURLProtocolHandler defaultHandler
- The default protocol handler. This handler is used when
other handlers fail or no match for a protocol can be
found.
globalUserAgent
private static java.lang.String globalUserAgent
| Constructor Detail |
ParsedURL
public ParsedURL(java.lang.String urlStr)
- Construct a ParsedURL from the given url string.
ParsedURL
public ParsedURL(java.net.URL url)
- Construct a ParsedURL from the given java.net.URL instance.
This is useful if you already have a valid java.net.URL
instance. This bypasses most of the parsing and hence is
quicker and less prone to reinterpretation than converting the
URL to a string before construction.
ParsedURL
public ParsedURL(java.lang.String baseStr, java.lang.String urlStr)
- Construct a sub URL from two strings.
ParsedURL
public ParsedURL(java.net.URL baseURL, java.lang.String urlStr)
- Construct a sub URL from a base URL and a string for the sub url.
ParsedURL
public ParsedURL(ParsedURL baseURL, java.lang.String urlStr)
- Construct a sub URL from a base ParsedURL and a string for the sub url.
| Method Detail |
getGlobalUserAgent
public static java.lang.String getGlobalUserAgent()
setGlobalUserAgent
public static void setGlobalUserAgent(java.lang.String userAgent)
getHandlersMap
private static java.util.Map getHandlersMap()
- Returns the shared instance of HandlersMap. This method is
also responsible for initializing the handler map if this is
the first time it has been requested since the class was
loaded.
getHandler
public static ParsedURLProtocolHandler getHandler(java.lang.String protocol)
- Returns the handler for a particular protocol. If protocol is
null or no match is found in the handlers map it
returns the default protocol handler.
registerHandler
public static void registerHandler(ParsedURLProtocolHandler handler)
- Registers a Protocol handler by adding it to the handlers map.
If the given protocol handler returns null as it's
supported protocol then it is registered as the default
protocol handler.
checkGZIP
public static java.io.InputStream checkGZIP(java.io.InputStream is) throws java.io.IOException
- 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.
toString
public java.lang.String toString()
- Return a string rep of the URL (can be passed back into the
constructor if desired).
equals
public boolean equals(java.lang.Object obj)
- Implement Object.equals.
Relies heavily on the contained ParsedURLData's implementation
of equals.
hashCode
public int hashCode()
- Implement Object.hashCode.
Relies on the contained ParsedURLData's implementation
of hashCode.
complete
public boolean complete()
- Returns true if the URL looks well formed and complete.
This does not garuntee that the stream can be opened but
is a good indication that things aren't totally messed up.
getUserAgent
public java.lang.String getUserAgent()
- Return the user agent current associated with this url (or
null if none).
setUserAgent
public void setUserAgent(java.lang.String userAgent)
- Sets the user agent associated with this url (null clears
any associated user agent).
getProtocol
public java.lang.String getProtocol()
- Returns the protocol for this URL.
The protocol is everything upto the first ':'.
getHost
public java.lang.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.
getPort
public int getPort()
- Returns the port on the host to connect to, if it was specified
in the url that was parsed, otherwise returns -1.
getPath
public java.lang.String getPath()
- Returns the path for this URL, if any (where appropriate for
the protocol this also includes the file, not just directory).
Note that getPath appears in JDK 1.3 as a synonym for getFile
from JDK 1.2.
getRef
public java.lang.String getRef()
- Returns the 'fragment' reference in the URL.
getPortStr
public java.lang.String getPortStr()
- Returns the URL up to and include the port number on
the host. Does not include the path or fragment pieces.
getContentType
public java.lang.String getContentType()
- Returns the content type if available. This is only available
for some protocols.
getContentEncoding
public java.lang.String getContentEncoding()
- Returns the content encoding if available. This is only available
for some protocols.
openStream
public java.io.InputStream openStream() throws java.io.IOException
- Attempt to open the stream checking for common compression
types, and automatically decompressing them if found.
openStream
public java.io.InputStream openStream(java.lang.String mimeType) throws java.io.IOException
- Attempt to open the stream checking for common compression
types, and automatically decompressing them if found.
openStream
public java.io.InputStream openStream(java.lang.String[] mimeTypes) throws java.io.IOException
- Attempt to open the stream checking for common compression
types, and automatically decompressing them if found.
openStream
public java.io.InputStream openStream(java.util.Iterator mimeTypes) throws java.io.IOException
- Attempt to open the stream checking for common compression
types, and automatically decompressing them if found.
openStreamRaw
public java.io.InputStream openStreamRaw() throws java.io.IOException
- Attempt to open the stream, does no checking for compression
types.
openStreamRaw
public java.io.InputStream openStreamRaw(java.lang.String mimeType) throws java.io.IOException
- Attempt to open the stream, does no checking for compression
types.
openStreamRaw
public java.io.InputStream openStreamRaw(java.lang.String[] mimeTypes) throws java.io.IOException
- Attempt to open the stream, does no checking for comression
types.
openStreamRaw
public java.io.InputStream openStreamRaw(java.util.Iterator mimeTypes) throws java.io.IOException
- Attempt to open the stream, does no checking for comression
types.
sameFile
public boolean sameFile(ParsedURL other)
getProtocol
protected static java.lang.String getProtocol(java.lang.String urlStr)
- Parse out the protocol from a url string. Used internally to
select the proper handler, all other parsing is done by
the selected protocol handler.
parseURL
public static ParsedURLData parseURL(java.lang.String urlStr)
- Factory method to construct an appropriate subclass of ParsedURLData
parseURL
public static ParsedURLData parseURL(java.lang.String baseStr, java.lang.String urlStr)
- Factory method to construct an appropriate subclass of ParsedURLData,
for a sub url.
parseURL
public static ParsedURLData parseURL(ParsedURL baseURL, java.lang.String urlStr)
- Factory method to construct an appropriate subclass of ParsedURLData,
for a sub url.
|
|||||||||
| Home >> All >> org >> apache >> batik >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.batik.util.ParsedURL