Save This Page
Home » Xerces-J-src.2.9.1 » org.apache.xerces » util » [javadoc | source]
org.apache.xerces.util
public class: URI [javadoc | source]
java.lang.Object
   org.apache.xerces.util.URI

All Implemented Interfaces:
    Serializable

A class to represent a Uniform Resource Identifier (URI). This class is designed to handle the parsing of URIs and provide access to the various components (scheme, host, port, userinfo, path, query string and fragment) that may constitute a URI.

Parsing of a URI specification is done according to the URI syntax described in RFC 2396, and amended by RFC 2732.

Every absolute URI consists of a scheme, followed by a colon (':'), followed by a scheme-specific part. For URIs that follow the "generic URI" syntax, the scheme-specific part begins with two slashes ("//") and may be followed by an authority segment (comprised of user information, host, and port), path segment, query segment and fragment. Note that RFC 2396 no longer specifies the use of the parameters segment and excludes the "user:password" syntax as part of the authority segment. If "user:password" appears in a URI, the entire user/password string is stored as userinfo.

For URIs that do not follow the "generic URI" syntax (e.g. mailto), the entire scheme-specific part is treated as the "path" portion of the URI.

Note that, unlike the java.net.URL class, this class does not provide any built-in network access functionality nor does it provide any scheme-specific functionality (for example, it does not know a default port for a specific scheme). Rather, it only knows the grammar and basic set of operations that can be applied to a URI.

Nested Class Summary:
public static class  URI.MalformedURIException  MalformedURIExceptions are thrown in the process of building a URI or setting fields on a URI when an operation would result in an invalid URI specification. 
Field Summary
static final  long serialVersionUID    Serialization version. 
Constructor:
 public URI() 
 public URI(URI 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 
    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 
    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 
    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 
    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 
    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 
    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 
    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 Summary:
absolutize,   appendPath,   equals,   getAuthority,   getFragment,   getHost,   getPath,   getPath,   getPort,   getQueryString,   getRegBasedAuthority,   getScheme,   getSchemeSpecificPart,   getUserinfo,   isAbsoluteURI,   isConformantSchemeName,   isGenericURI,   isWellFormedAddress,   isWellFormedIPv4Address,   isWellFormedIPv6Reference,   setFragment,   setHost,   setPath,   setPort,   setQueryString,   setRegBasedAuthority,   setScheme,   setUserinfo,   toString
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.xerces.util.URI Detail:
 public  void absolutize(URI p_base) 
    Absolutize URI with given base URI.
 public  void appendPath(String p_addToPath) throws URI.MalformedURIException 
    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) 
    Determines if the passed-in Object is equivalent to this URI.
 public String getAuthority() 
    Get the authority for this URI.
 public String getFragment() 
    Get the fragment for this URI.
 public String getHost() 
    Get the host for this URI.
 public String getPath() 
    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) 
    Get the path for this URI (optionally with the query string and fragment).
 public int getPort() 
    Get the port for this URI.
 public String getQueryString() 
    Get the query string for this URI.
 public String getRegBasedAuthority() 
    Get the registry based authority for this URI.
 public String getScheme() 
    Get the scheme for this URI.
 public String getSchemeSpecificPart() 
    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() 
    Get the userinfo for this URI.
 public boolean isAbsoluteURI() 
    Returns whether this URI represents an absolute URI.
 public static boolean isConformantSchemeName(String p_scheme) 
    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() 
    Get the indicator as to whether this URI uses the "generic URI" syntax.
 public static boolean isWellFormedAddress(String address) 
    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) 

    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) 

    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 
    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 

    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 
    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 
    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 
    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 

    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 
    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 
    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() 
    Get the URI as a string specification. See RFC 2396 Section 5.2.