| Constructor: |
public URI() {
}
Construct a new and uninitialized URI. |
public URI(URI p_other) {
initialize(p_other);
}
Construct a new URI from another URI. All fields for this URI are
set equal to the fields of the URI passed in. Parameters:
p_other - the URI to copy (cannot be null)
|
public URI(String p_uriSpec) throws URI.MalformedURIException {
this((URI)null, p_uriSpec);
}
Construct a new URI from a URI specification string. If the
specification follows the "generic URI" syntax, (two slashes
following the first colon), the specification will be parsed
accordingly - setting the scheme, userinfo, host,port, path, query
string and fragment fields as necessary. If the specification does
not follow the "generic URI" syntax, the specification is parsed
into a scheme and scheme-specific part (stored as the path) only. Parameters:
p_uriSpec - the URI specification string (cannot be null or
empty)
Throws:
MalformedURIException - if p_uriSpec violates any syntax
rules
- exception:
MalformedURIException - if p_uriSpec violates any syntax
rules
|
public URI(String p_uriSpec,
boolean allowNonAbsoluteURI) throws URI.MalformedURIException {
this((URI)null, p_uriSpec, allowNonAbsoluteURI);
}
Construct a new URI from a URI specification string. If the
specification follows the "generic URI" syntax, (two slashes
following the first colon), the specification will be parsed
accordingly - setting the scheme, userinfo, host,port, path, query
string and fragment fields as necessary. If the specification does
not follow the "generic URI" syntax, the specification is parsed
into a scheme and scheme-specific part (stored as the path) only.
Construct a relative URI if boolean is assigned to "true"
and p_uriSpec is not valid absolute URI, instead of throwing an exception. Parameters:
p_uriSpec - the URI specification string (cannot be null or
empty)
allowNonAbsoluteURI - true to permit non-absolute URIs,
false otherwise.
Throws:
MalformedURIException - if p_uriSpec violates any syntax
rules
- exception:
MalformedURIException - if p_uriSpec violates any syntax
rules
|
public URI(URI p_base,
String p_uriSpec) throws URI.MalformedURIException {
initialize(p_base, p_uriSpec);
}
Construct a new URI from a base URI and a URI specification string.
The URI specification string may be a relative URI. Parameters:
p_base - the base URI (cannot be null if p_uriSpec is null or
empty)
p_uriSpec - the URI specification string (cannot be null or
empty if p_base is null)
Throws:
MalformedURIException - if p_uriSpec violates any syntax
rules
- exception:
MalformedURIException - if p_uriSpec violates any syntax
rules
|
public URI(String p_scheme,
String p_schemeSpecificPart) throws URI.MalformedURIException {
if (p_scheme == null || p_scheme.trim().length() == 0) {
throw new MalformedURIException(
"Cannot construct URI with null/empty scheme!");
}
if (p_schemeSpecificPart == null ||
p_schemeSpecificPart.trim().length() == 0) {
throw new MalformedURIException(
"Cannot construct URI with null/empty scheme-specific part!");
}
setScheme(p_scheme);
setPath(p_schemeSpecificPart);
}
Construct a new URI that does not follow the generic URI syntax.
Only the scheme and scheme-specific part (stored as the path) are
initialized. Parameters:
p_scheme - the URI scheme (cannot be null or empty)
p_schemeSpecificPart - the scheme-specific part (cannot be
null or empty)
Throws:
MalformedURIException - if p_scheme violates any
syntax rules
- exception:
MalformedURIException - if p_scheme violates any
syntax rules
|
public URI(URI p_base,
String p_uriSpec,
boolean allowNonAbsoluteURI) throws URI.MalformedURIException {
initialize(p_base, p_uriSpec, allowNonAbsoluteURI);
}
Construct a new URI from a base URI and a URI specification string.
The URI specification string may be a relative URI.
Construct a relative URI if boolean is assigned to "true"
and p_uriSpec is not valid absolute URI and p_base is null
instead of throwing an exception. Parameters:
p_base - the base URI (cannot be null if p_uriSpec is null or
empty)
p_uriSpec - the URI specification string (cannot be null or
empty if p_base is null)
allowNonAbsoluteURI - true to permit non-absolute URIs,
false otherwise.
Throws:
MalformedURIException - if p_uriSpec violates any syntax
rules
- exception:
MalformedURIException - if p_uriSpec violates any syntax
rules
|
public URI(String p_scheme,
String p_host,
String p_path,
String p_queryString,
String p_fragment) throws URI.MalformedURIException {
this(p_scheme, null, p_host, -1, p_path, p_queryString, p_fragment);
}
Construct a new URI that follows the generic URI syntax from its
component parts. Each component is validated for syntax and some
basic semantic checks are performed as well. See the individual
setter methods for specifics. Parameters:
p_scheme - the URI scheme (cannot be null or empty)
p_host - the hostname, IPv4 address or IPv6 reference for the URI
p_path - the URI path - if the path contains '?' or '#',
then the query string and/or fragment will be
set from the path; however, if the query and
fragment are specified both in the path and as
separate parameters, an exception is thrown
p_queryString - the URI query string (cannot be specified
if path is null)
p_fragment - the URI fragment (cannot be specified if path
is null)
Throws:
MalformedURIException - if any of the parameters violates
syntax rules or semantic rules
- exception:
MalformedURIException - if any of the parameters violates
syntax rules or semantic rules
|
public URI(String p_scheme,
String p_userinfo,
String p_host,
int p_port,
String p_path,
String p_queryString,
String p_fragment) throws URI.MalformedURIException {
if (p_scheme == null || p_scheme.trim().length() == 0) {
throw new MalformedURIException("Scheme is required!");
}
if (p_host == null) {
if (p_userinfo != null) {
throw new MalformedURIException(
"Userinfo may not be specified if host is not specified!");
}
if (p_port != -1) {
throw new MalformedURIException(
"Port may not be specified if host is not specified!");
}
}
if (p_path != null) {
if (p_path.indexOf('?") != -1 && p_queryString != null) {
throw new MalformedURIException(
"Query string cannot be specified in path and query string!");
}
if (p_path.indexOf('#") != -1 && p_fragment != null) {
throw new MalformedURIException(
"Fragment cannot be specified in both the path and fragment!");
}
}
setScheme(p_scheme);
setHost(p_host);
setPort(p_port);
setUserinfo(p_userinfo);
setPath(p_path);
setQueryString(p_queryString);
setFragment(p_fragment);
}
Construct a new URI that follows the generic URI syntax from its
component parts. Each component is validated for syntax and some
basic semantic checks are performed as well. See the individual
setter methods for specifics. Parameters:
p_scheme - the URI scheme (cannot be null or empty)
p_userinfo - the URI userinfo (cannot be specified if host
is null)
p_host - the hostname, IPv4 address or IPv6 reference for the URI
p_port - the URI port (may be -1 for "unspecified"; cannot
be specified if host is null)
p_path - the URI path - if the path contains '?' or '#',
then the query string and/or fragment will be
set from the path; however, if the query and
fragment are specified both in the path and as
separate parameters, an exception is thrown
p_queryString - the URI query string (cannot be specified
if path is null)
p_fragment - the URI fragment (cannot be specified if path
is null)
Throws:
MalformedURIException - if any of the parameters violates
syntax rules or semantic rules
- exception:
MalformedURIException - if any of the parameters violates
syntax rules or semantic rules
|
| Method from org.apache.xerces.util.URI Detail: |
public void absolutize(URI p_base) {
// check to see if this is the current doc - RFC 2396 5.2 #2
// note that this is slightly different from the RFC spec in that
// we don't include the check for query string being null
// - this handles cases where the urispec is just a query
// string or a fragment (e.g. "?y" or "#s") -
// see < http://www.ics.uci.edu/~fielding/url/test1.html > which
// identified this as a bug in the RFC
if (m_path.length() == 0 && m_scheme == null &&
m_host == null && m_regAuthority == null) {
m_scheme = p_base.getScheme();
m_userinfo = p_base.getUserinfo();
m_host = p_base.getHost();
m_port = p_base.getPort();
m_regAuthority = p_base.getRegBasedAuthority();
m_path = p_base.getPath();
if (m_queryString == null) {
m_queryString = p_base.getQueryString();
if (m_fragment == null) {
m_fragment = p_base.getFragment();
}
}
return;
}
// check for scheme - RFC 2396 5.2 #3
// if we found a scheme, it means absolute URI, so we're done
if (m_scheme == null) {
m_scheme = p_base.getScheme();
}
else {
return;
}
// check for authority - RFC 2396 5.2 #4
// if we found a host, then we've got a network path, so we're done
if (m_host == null && m_regAuthority == null) {
m_userinfo = p_base.getUserinfo();
m_host = p_base.getHost();
m_port = p_base.getPort();
m_regAuthority = p_base.getRegBasedAuthority();
}
else {
return;
}
// check for absolute path - RFC 2396 5.2 #5
if (m_path.length() > 0 &&
m_path.startsWith("/")) {
return;
}
// if we get to this point, we need to resolve relative path
// RFC 2396 5.2 #6
String path = "";
String basePath = p_base.getPath();
// 6a - get all but the last segment of the base URI path
if (basePath != null && basePath.length() > 0) {
int lastSlash = basePath.lastIndexOf('/");
if (lastSlash != -1) {
path = basePath.substring(0, lastSlash+1);
}
}
else if (m_path.length() > 0) {
path = "/";
}
// 6b - append the relative URI path
path = path.concat(m_path);
// 6c - remove all "./" where "." is a complete path segment
int index = -1;
while ((index = path.indexOf("/./")) != -1) {
path = path.substring(0, index+1).concat(path.substring(index+3));
}
// 6d - remove "." if path ends with "." as a complete path segment
if (path.endsWith("/.")) {
path = path.substring(0, path.length()-1);
}
// 6e - remove all "< segment >/../" where "< segment >" is a complete
// path segment not equal to ".."
index = 1;
int segIndex = -1;
String tempString = null;
while ((index = path.indexOf("/../", index)) > 0) {
tempString = path.substring(0, path.indexOf("/../"));
segIndex = tempString.lastIndexOf('/");
if (segIndex != -1) {
if (!tempString.substring(segIndex).equals("..")) {
path = path.substring(0, segIndex+1).concat(path.substring(index+4));
index = segIndex;
}
else {
index += 4;
}
}
else {
index += 4;
}
}
// 6f - remove ending "< segment >/.." where "< segment >" is a
// complete path segment
if (path.endsWith("/..")) {
tempString = path.substring(0, path.length()-3);
segIndex = tempString.lastIndexOf('/");
if (segIndex != -1) {
path = path.substring(0, segIndex+1);
}
}
m_path = path;
}
Absolutize URI with given base URI. |
public void appendPath(String p_addToPath) throws URI.MalformedURIException {
if (p_addToPath == null || p_addToPath.trim().length() == 0) {
return;
}
if (!isURIString(p_addToPath)) {
throw new MalformedURIException(
"Path contains invalid character!");
}
if (m_path == null || m_path.trim().length() == 0) {
if (p_addToPath.startsWith("/")) {
m_path = p_addToPath;
}
else {
m_path = "/" + p_addToPath;
}
}
else if (m_path.endsWith("/")) {
if (p_addToPath.startsWith("/")) {
m_path = m_path.concat(p_addToPath.substring(1));
}
else {
m_path = m_path.concat(p_addToPath);
}
}
else {
if (p_addToPath.startsWith("/")) {
m_path = m_path.concat(p_addToPath);
}
else {
m_path = m_path.concat("/" + p_addToPath);
}
}
}
Append to the end of the path of this URI. If the current path does
not end in a slash and the path to be appended does not begin with
a slash, a slash will be appended to the current path before the
new segment is added. Also, if the current path ends in a slash
and the new segment begins with a slash, the extra slash will be
removed before the new segment is appended. |
public boolean equals(Object p_test) {
if (p_test instanceof URI) {
URI testURI = (URI) p_test;
if (((m_scheme == null && testURI.m_scheme == null) ||
(m_scheme != null && testURI.m_scheme != null &&
m_scheme.equals(testURI.m_scheme))) &&
((m_userinfo == null && testURI.m_userinfo == null) ||
(m_userinfo != null && testURI.m_userinfo != null &&
m_userinfo.equals(testURI.m_userinfo))) &&
((m_host == null && testURI.m_host == null) ||
(m_host != null && testURI.m_host != null &&
m_host.equals(testURI.m_host))) &&
m_port == testURI.m_port &&
((m_path == null && testURI.m_path == null) ||
(m_path != null && testURI.m_path != null &&
m_path.equals(testURI.m_path))) &&
((m_queryString == null && testURI.m_queryString == null) ||
(m_queryString != null && testURI.m_queryString != null &&
m_queryString.equals(testURI.m_queryString))) &&
((m_fragment == null && testURI.m_fragment == null) ||
(m_fragment != null && testURI.m_fragment != null &&
m_fragment.equals(testURI.m_fragment)))) {
return true;
}
}
return false;
}
Determines if the passed-in Object is equivalent to this URI. |
public String getAuthority() {
StringBuffer authority = new StringBuffer();
if (m_host != null || m_regAuthority != null) {
authority.append("//");
// Server based authority.
if (m_host != null) {
if (m_userinfo != null) {
authority.append(m_userinfo);
authority.append('@");
}
authority.append(m_host);
if (m_port != -1) {
authority.append(':");
authority.append(m_port);
}
}
// Registry based authority.
else {
authority.append(m_regAuthority);
}
}
return authority.toString();
}
Get the authority for this URI. |
public String getFragment() {
return m_fragment;
}
Get the fragment for this URI. |
public String getHost() {
return m_host;
}
Get the host for this URI. |
public String getPath() {
return m_path;
}
Get the path for this URI. Note that the value returned is the path
only and does not include the query string or fragment. |
public String getPath(boolean p_includeQueryString,
boolean p_includeFragment) {
StringBuffer pathString = new StringBuffer(m_path);
if (p_includeQueryString && m_queryString != null) {
pathString.append('?");
pathString.append(m_queryString);
}
if (p_includeFragment && m_fragment != null) {
pathString.append('#");
pathString.append(m_fragment);
}
return pathString.toString();
}
Get the path for this URI (optionally with the query string and
fragment). |
public int getPort() {
return m_port;
}
Get the port for this URI. |
public String getQueryString() {
return m_queryString;
}
Get the query string for this URI. |
public String getRegBasedAuthority() {
return m_regAuthority;
}
Get the registry based authority for this URI. |
public String getScheme() {
return m_scheme;
}
Get the scheme for this URI. |
public String getSchemeSpecificPart() {
StringBuffer schemespec = new StringBuffer();
if (m_host != null || m_regAuthority != null) {
schemespec.append("//");
// Server based authority.
if (m_host != null) {
if (m_userinfo != null) {
schemespec.append(m_userinfo);
schemespec.append('@");
}
schemespec.append(m_host);
if (m_port != -1) {
schemespec.append(':");
schemespec.append(m_port);
}
}
// Registry based authority.
else {
schemespec.append(m_regAuthority);
}
}
if (m_path != null) {
schemespec.append((m_path));
}
if (m_queryString != null) {
schemespec.append('?");
schemespec.append(m_queryString);
}
if (m_fragment != null) {
schemespec.append('#");
schemespec.append(m_fragment);
}
return schemespec.toString();
}
Get the scheme-specific part for this URI (everything following the
scheme and the first colon). See RFC 2396 Section 5.2 for spec. |
public String getUserinfo() {
return m_userinfo;
}
Get the userinfo for this URI. |
public boolean isAbsoluteURI() {
// presence of the scheme means absolute uri
return (m_scheme != null);
}
Returns whether this URI represents an absolute URI. |
public static boolean isConformantSchemeName(String p_scheme) {
if (p_scheme == null || p_scheme.trim().length() == 0) {
return false;
}
if (!isAlpha(p_scheme.charAt(0))) {
return false;
}
char testChar;
int schemeLength = p_scheme.length();
for (int i = 1; i < schemeLength; ++i) {
testChar = p_scheme.charAt(i);
if (!isSchemeCharacter(testChar)) {
return false;
}
}
return true;
}
Determine whether a scheme conforms to the rules for a scheme name.
A scheme is conformant if it starts with an alphanumeric, and
contains only alphanumerics, '+','-' and '.'. |
public boolean isGenericURI() {
// presence of the host (whether valid or empty) means
// double-slashes which means generic uri
return (m_host != null);
}
Get the indicator as to whether this URI uses the "generic URI"
syntax. |
public static boolean isWellFormedAddress(String address) {
if (address == null) {
return false;
}
int addrLength = address.length();
if (addrLength == 0) {
return false;
}
// Check if the host is a valid IPv6reference.
if (address.startsWith("[")) {
return isWellFormedIPv6Reference(address);
}
// Cannot start with a '.', '-', or end with a '-'.
if (address.startsWith(".") ||
address.startsWith("-") ||
address.endsWith("-")) {
return false;
}
// rightmost domain label starting with digit indicates IP address
// since top level domain label can only start with an alpha
// see RFC 2396 Section 3.2.2
int index = address.lastIndexOf('.");
if (address.endsWith(".")) {
index = address.substring(0, index).lastIndexOf('.");
}
if (index+1 < addrLength && isDigit(address.charAt(index+1))) {
return isWellFormedIPv4Address(address);
}
else {
// hostname = *( domainlabel "." ) toplabel [ "." ]
// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
// RFC 2396 states that hostnames take the form described in
// RFC 1034 (Section 3) and RFC 1123 (Section 2.1). According
// to RFC 1034, hostnames are limited to 255 characters.
if (addrLength > 255) {
return false;
}
// domain labels can contain alphanumerics and '-"
// but must start and end with an alphanumeric
char testChar;
int labelCharCount = 0;
for (int i = 0; i < addrLength; i++) {
testChar = address.charAt(i);
if (testChar == '.") {
if (!isAlphanum(address.charAt(i-1))) {
return false;
}
if (i+1 < addrLength && !isAlphanum(address.charAt(i+1))) {
return false;
}
labelCharCount = 0;
}
else if (!isAlphanum(testChar) && testChar != '-") {
return false;
}
// RFC 1034: Labels must be 63 characters or less.
else if (++labelCharCount > 63) {
return false;
}
}
}
return true;
}
Determine whether a string is syntactically capable of representing
a valid IPv4 address, IPv6 reference or the domain name of a network host.
A valid IPv4 address consists of four decimal digit groups separated by a
'.'. Each group must consist of one to three digits. See RFC 2732 Section 3,
and RFC 2373 Section 2.2, for the definition of IPv6 references. A hostname
consists of domain labels (each of which must begin and end with an alphanumeric
but may contain '-') separated & by a '.'. See RFC 2396 Section 3.2.2. |
public static boolean isWellFormedIPv4Address(String address) {
int addrLength = address.length();
char testChar;
int numDots = 0;
int numDigits = 0;
// make sure that 1) we see only digits and dot separators, 2) that
// any dot separator is preceded and followed by a digit and
// 3) that we find 3 dots
//
// RFC 2732 amended RFC 2396 by replacing the definition
// of IPv4address with the one defined by RFC 2373. - mrglavas
//
// IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
//
// One to three digits must be in each segment.
for (int i = 0; i < addrLength; i++) {
testChar = address.charAt(i);
if (testChar == '.") {
if ((i > 0 && !isDigit(address.charAt(i-1))) ||
(i+1 < addrLength && !isDigit(address.charAt(i+1)))) {
return false;
}
numDigits = 0;
if (++numDots > 3) {
return false;
}
}
else if (!isDigit(testChar)) {
return false;
}
// Check that that there are no more than three digits
// in this segment.
else if (++numDigits > 3) {
return false;
}
// Check that this segment is not greater than 255.
else if (numDigits == 3) {
char first = address.charAt(i-2);
char second = address.charAt(i-1);
if (!(first < '2" ||
(first == '2" &&
(second < '5" ||
(second == '5" && testChar < = '5"))))) {
return false;
}
}
}
return (numDots == 3);
}
Determines whether a string is an IPv4 address as defined by
RFC 2373, and under the further constraint that it must be a 32-bit
address. Though not expressed in the grammar, in order to satisfy
the 32-bit address constraint, each segment of the address cannot
be greater than 255 (8 bits of information).
IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
|
public static boolean isWellFormedIPv6Reference(String address) {
int addrLength = address.length();
int index = 1;
int end = addrLength-1;
// Check if string is a potential match for IPv6reference.
if (!(addrLength > 2 && address.charAt(0) == '["
&& address.charAt(end) == ']")) {
return false;
}
// Counter for the number of 16-bit sections read in the address.
int [] counter = new int[1];
// Scan hex sequence before possible '::' or IPv4 address.
index = scanHexSequence(address, index, end, counter);
if (index == -1) {
return false;
}
// Address must contain 128-bits of information.
else if (index == end) {
return (counter[0] == 8);
}
if (index+1 < end && address.charAt(index) == ':") {
if (address.charAt(index+1) == ':") {
// '::' represents at least one 16-bit group of zeros.
if (++counter[0] > 8) {
return false;
}
index += 2;
// Trailing zeros will fill out the rest of the address.
if (index == end) {
return true;
}
}
// If the second character wasn't ':', in order to be valid,
// the remainder of the string must match IPv4Address,
// and we must have read exactly 6 16-bit groups.
else {
return (counter[0] == 6) &&
isWellFormedIPv4Address(address.substring(index+1, end));
}
}
else {
return false;
}
// 3. Scan hex sequence after '::'.
int prevCount = counter[0];
index = scanHexSequence(address, index, end, counter);
// We've either reached the end of the string, the address ends in
// an IPv4 address, or it is invalid. scanHexSequence has already
// made sure that we have the right number of bits.
return (index == end) ||
(index != -1 && isWellFormedIPv4Address(
address.substring((counter[0] > prevCount) ? index+1 : index, end)));
}
Determines whether a string is an IPv6 reference as defined
by RFC 2732, where IPv6address is defined in RFC 2373. The
IPv6 address is parsed according to Section 2.2 of RFC 2373,
with the additional constraint that the address be composed of
128 bits of information.
IPv6reference = "[" IPv6address "]"
Note: The BNF expressed in RFC 2373 Appendix B does not
accurately describe section 2.2, and was in fact removed from
RFC 3513, the successor of RFC 2373.
|
public void setFragment(String p_fragment) throws URI.MalformedURIException {
if (p_fragment == null) {
m_fragment = null;
}
else if (!isGenericURI()) {
throw new MalformedURIException(
"Fragment can only be set for a generic URI!");
}
else if (getPath() == null) {
throw new MalformedURIException(
"Fragment cannot be set when path is null!");
}
else if (!isURIString(p_fragment)) {
throw new MalformedURIException(
"Fragment contains invalid character!");
}
else {
m_fragment = p_fragment;
}
}
Set the fragment for this URI. A non-null value is valid only
if this is a URI conforming to the generic URI syntax and
the path value is not null. |
public void setHost(String p_host) throws URI.MalformedURIException {
if (p_host == null || p_host.length() == 0) {
if (p_host != null) {
m_regAuthority = null;
}
m_host = p_host;
m_userinfo = null;
m_port = -1;
return;
}
else if (!isWellFormedAddress(p_host)) {
throw new MalformedURIException("Host is not a well formed address!");
}
m_host = p_host;
m_regAuthority = null;
}
Set the host for this URI. If null is passed in, the userinfo
field is also set to null and the port is set to -1.
Note: This method overwrites registry based authority if it
previously existed in this URI.
|
public void setPath(String p_path) throws URI.MalformedURIException {
if (p_path == null) {
m_path = null;
m_queryString = null;
m_fragment = null;
}
else {
initializePath(p_path, 0);
}
}
Set the path for this URI. If the supplied path is null, then the
query string and fragment are set to null as well. If the supplied
path includes a query string and/or fragment, these fields will be
parsed and set as well. Note that, for URIs following the "generic
URI" syntax, the path specified should start with a slash.
For URIs that do not follow the generic URI syntax, this method
sets the scheme-specific part. |
public void setPort(int p_port) throws URI.MalformedURIException {
if (p_port >= 0 && p_port < = 65535) {
if (m_host == null) {
throw new MalformedURIException(
"Port cannot be set when host is null!");
}
}
else if (p_port != -1) {
throw new MalformedURIException("Invalid port number!");
}
m_port = p_port;
}
Set the port for this URI. -1 is used to indicate that the port is
not specified, otherwise valid port numbers are between 0 and 65535.
If a valid port number is passed in and the host field is null,
an exception is thrown. |
public void setQueryString(String p_queryString) throws URI.MalformedURIException {
if (p_queryString == null) {
m_queryString = null;
}
else if (!isGenericURI()) {
throw new MalformedURIException(
"Query string can only be set for a generic URI!");
}
else if (getPath() == null) {
throw new MalformedURIException(
"Query string cannot be set when path is null!");
}
else if (!isURIString(p_queryString)) {
throw new MalformedURIException(
"Query string contains invalid character!");
}
else {
m_queryString = p_queryString;
}
}
Set the query string for this URI. A non-null value is valid only
if this is an URI conforming to the generic URI syntax and
the path value is not null. |
public void setRegBasedAuthority(String authority) throws URI.MalformedURIException {
if (authority == null) {
m_regAuthority = null;
return;
}
// reg_name = 1*( unreserved | escaped | "$" | "," |
// ";" | ":" | "@" | "&" | "=" | "+" )
else if (authority.length() < 1 ||
!isValidRegistryBasedAuthority(authority) ||
authority.indexOf('/") != -1) {
throw new MalformedURIException("Registry based authority is not well formed.");
}
m_regAuthority = authority;
m_host = null;
m_userinfo = null;
m_port = -1;
}
Sets the registry based authority for this URI.
Note: This method overwrites server based authority
if it previously existed in this URI.
|
public void setScheme(String p_scheme) throws URI.MalformedURIException {
if (p_scheme == null) {
throw new MalformedURIException(
"Cannot set scheme from null string!");
}
if (!isConformantSchemeName(p_scheme)) {
throw new MalformedURIException("The scheme is not conformant.");
}
m_scheme = p_scheme.toLowerCase();
}
Set the scheme for this URI. The scheme is converted to lowercase
before it is set. |
public void setUserinfo(String p_userinfo) throws URI.MalformedURIException {
if (p_userinfo == null) {
m_userinfo = null;
return;
}
else {
if (m_host == null) {
throw new MalformedURIException(
"Userinfo cannot be set when host is null!");
}
// userinfo can contain alphanumerics, mark characters, escaped
// and ';',':','&','=','+','$',','
int index = 0;
int end = p_userinfo.length();
char testChar = '\0";
while (index < end) {
testChar = p_userinfo.charAt(index);
if (testChar == '%") {
if (index+2 >= end ||
!isHex(p_userinfo.charAt(index+1)) ||
!isHex(p_userinfo.charAt(index+2))) {
throw new MalformedURIException(
"Userinfo contains invalid escape sequence!");
}
}
else if (!isUserinfoCharacter(testChar)) {
throw new MalformedURIException(
"Userinfo contains invalid character:"+testChar);
}
index++;
}
}
m_userinfo = p_userinfo;
}
Set the userinfo for this URI. If a non-null value is passed in and
the host value is null, then an exception is thrown. |
public String toString() {
StringBuffer uriSpecString = new StringBuffer();
if (m_scheme != null) {
uriSpecString.append(m_scheme);
uriSpecString.append(':");
}
uriSpecString.append(getSchemeSpecificPart());
return uriSpecString.toString();
}
Get the URI as a string specification. See RFC 2396 Section 5.2. |