|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.fhg.igd.util.URL
public class URL
Represents a URL. This class serves as an alternative to the
java.net.URL class. This class does not require
protocol handlers for the protocol identifiers that are used
with it. It is merely a container for URL strings that allows
easy access to the individual components of a URL.
The rationale for this class is to have the URL parsing and handling functionality without the overhead caused by connection handlers and content handlers. From a security perspective this is desireable because there are viewer weak points that could be exploited for an attack. Certain applications, such as mobile agent systems, may want to support some protocols by means other than a connection handler.
This class parses URLs according to RFC 1738. It supports all aspects of the Common Internet Scheme Syntax: protocol identifiers, user names, passwords, host names, ports, and a scheme-specific path. The path itself is not parsed. This could be done in subclasses, if desired.
Host names are converted to lower case by this class. Passwords are not serialized.
| Field Summary | |
|---|---|
private static int |
HOST
|
private String |
host_
The host part. |
private String |
passwd_
The password part. |
private static int |
PATH
|
private String |
path_
The scheme-specific part. |
private static int |
PHP
|
private static int |
PORT
|
private int |
port_
The port. |
private static int |
PROTO
|
private String |
protocol_
The protocol part in lower case. |
private static int |
SLASH
|
private static int |
SLASH2
|
private static int |
UPHP
|
private String |
user_
The user part. |
| Constructor Summary | |
|---|---|
URL(String urlString)
Creates an instance with the given URL string. |
|
URL(String protocol,
String host,
int port,
String path)
Creates an URL with the given protocol identifier, host name, port, and path. |
|
URL(String protocol,
String host,
String path)
Creates an URL with the given protocol identifier, host name, and path. |
|
URL(String protocol,
String user,
String passwd,
String host,
int port,
String path)
Creates an instance with the given values. |
|
| Method Summary | |
|---|---|
private String |
cut(StringBuffer buf)
Returns the string conatined in the global string buffer, clears the string buffer, and sets the given state. |
boolean |
equals(Object o)
Compares this URL with the given object for equality. |
String |
getHost()
Returns the host name or null if none
was defined. |
String |
getPassword()
Returns the password or null if none
was defined. |
String |
getPath()
Returns the url-path or null if none
was defined. |
int |
getPort()
Returns the port number or -1 if none was defined. |
String |
getProtocol()
Returns the protocol identifier. |
String |
getUser()
Returns the user name or null if none
was defined. |
int |
hashCode()
Returns the hash code of this URL. |
private void |
initURL(String ref)
Creates an instance of a URL from the
given string representation. |
private boolean |
isHost(char c)
Tests if the given character is of the set [a-z], [A-Z], [0-9], '-', '_', '.'. |
private boolean |
isProto(char c)
Tests if the given character is of the set [a-z], [A-Z], [0-9], '+', '-', '.'. |
private boolean |
isUser(char c)
Tests if the given character is of the set [a-z], [A-Z], [0-9], '$', '-', '_', '.', '+', ';', '?', '&', '=', '%'. |
static void |
main(String[] argv)
|
void |
setHost(String host)
Sets the hostname. |
void |
setPassword(String passwd)
Sets the password. |
void |
setPath(String path)
Sets the url-path. |
void |
setPort(int port)
Sets the port number. |
void |
setProtocol(String protocol)
Sets the protocol identifier. |
void |
setUser(String user)
Sets the user name. |
String |
toString()
Returns a string representation of this URL. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final int PROTO
private static final int SLASH
private static final int SLASH2
private static final int UPHP
private static final int PHP
private static final int HOST
private static final int PORT
private static final int PATH
private String protocol_
private String user_
private transient String passwd_
private String host_
private int port_
private String path_
| Constructor Detail |
|---|
public URL(String urlString)
throws MalformedURLException
urlString - The URL string.
MalformedURLException - if url
is not well-formed.
public URL(String protocol,
String host,
String path)
protocol - The protocol identifier.host - The host name.path - The path or null.
public URL(String protocol,
String host,
int port,
String path)
protocol - The protocol identifier.host - The host name.port - The port number.path - The path or null.
public URL(String protocol,
String user,
String passwd,
String host,
int port,
String path)
protocol - The protocol identifier.user - The user name or null.passwd - The password or null.host - The host name.port - The port.path - The path or null.| Method Detail |
|---|
public String getProtocol()
public void setProtocol(String protocol)
protocol - The protocol identifier.
NullPointerExcepetion - if protocol is nullpublic String getUser()
null if none
was defined.
null.public void setUser(String user)
user - The user name or null.public String getPassword()
null if none
was defined.
null.public void setPassword(String passwd)
passwd - The password or null.public String getHost()
null if none
was defined.
null.public void setHost(String host)
host - The host name.public int getPort()
public void setPort(int port)
port - The port.public String getPath()
null if none
was defined.
null.public void setPath(String path)
path - The path or null.public String toString()
toString in class Objectpublic boolean equals(Object o)
equals in class Objecto - The object to compare with.
true if this URL equals the given one.public int hashCode()
hashCode in class Objectpublic static void main(String[] argv)
private void initURL(String ref)
throws MalformedURLException
URL from the
given string representation.
ref - The URL in string form.
MalformedURLException - if the given URL reference
is not well-formed.private String cut(StringBuffer buf)
buf - The StringBuffer with the decoded
data.private boolean isProto(char c)
true if c is
in the set given above.private boolean isUser(char c)
true if c is
in the set given above.private boolean isHost(char c)
true if c is
in the set given above.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||