org.apache.tomcat.util.net

## Class URL

- java.lang.Object
- - org.apache.tomcat.util.net.URL

- All Implemented Interfaces:
    Serializable

      public final class URL
      extends Object
      implements Serializable

  URL is designed to provide public APIs for parsing and synthesizing Uniform Resource Locators as similar as possible to the APIs of `java.net.URL`, but without the ability to open a stream or connection. One of the consequences of this is that you can construct URLs for protocols for which a URLStreamHandler is not available (such as an "https" URL when JSSE is not installed).

  WARNING - This class assumes that the string representation of a URL conforms to the `spec` argument as described in RFC 2396 "Uniform Resource Identifiers: Generic Syntax":

         <scheme>//<authority><path>?<query>#<fragment>

  FIXME - This class really ought to end up in a Commons package someplace.

  Author:
    Craig R. McClanahan
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `URL(String spec)` Create a URL object from the specified String representation.
    `URL(String protocol, String host, int port, String file)` Deprecated. Unused. Will be removed in Tomcat 8.0.x
    `URL(String protocol, String host, String file)` Deprecated. Unused. Will be removed in Tomcat 8.0.x
    `URL(URL context, String spec)` Create a URL object by parsing a string representation relative to a specified context.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object obj)` Compare two URLs for equality.
    `String` | `getAuthority()` Return the authority part of the URL.
    `String` | `getFile()` Return the filename part of the URL.
    `String` | `getHost()` Return the host name part of the URL.
    `String` | `getPath()` Return the path part of the URL.
    `int` | `getPort()` Return the port number part of the URL.
    `String` | `getProtocol()` Return the protocol name part of the URL.
    `String` | `getQuery()` Return the query part of the URL.
    `String` | `getRef()` Return the reference part of the URL.
    `String` | `getUserInfo()` Return the user info part of the URL.
    `int` | `hashCode()`
    `static boolean` | `isSchemeChar(char c)` Determine if the character is allowed in the scheme of a URI.
    `void` | `normalize()` Normalize the `path` (and therefore `file`) portions of this URL.
    `boolean` | `sameFile(URL other)` Compare two URLs, excluding the "ref" fields.
    `String` | `toExternalForm()` Deprecated. Unused. Will be removed in Tomcat 8.0.x
    `String` | `toString()` Return a string representation of this object.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### URL

          public URL(String spec)
              throws MalformedURLException

      Create a URL object from the specified String representation.
      Parameters:
        `spec` - String representation of the URL
      Throws:
        `MalformedURLException` - if the string representation cannot be parsed successfully

    - #### URL

          public URL(URL context,
             String spec)
              throws MalformedURLException

      Create a URL object by parsing a string representation relative to a specified context. Based on logic from JDK 1.3.1's `java.net.URL`.
      Parameters:
        `context` - URL against which the relative representation is resolved
        `spec` - String representation of the URL (usually relative)
      Throws:
        `MalformedURLException` - if the string representation cannot be parsed successfully

    - #### URL

          @Deprecated
          public URL(String protocol,
                        String host,
                        String file)
              throws MalformedURLException

      Deprecated. Unused. Will be removed in Tomcat 8.0.x
      Create a URL object from the specified components. The default port number for the specified protocol will be used.
      Parameters:
        `protocol` - Name of the protocol to use
        `host` - Name of the host addressed by this protocol
        `file` - Filename on the specified host
      Throws:
        `MalformedURLException` - is never thrown, but present for compatible APIs

    - #### URL

          @Deprecated
          public URL(String protocol,
                        String host,
                        int port,
                        String file)
              throws MalformedURLException

      Deprecated. Unused. Will be removed in Tomcat 8.0.x
      Create a URL object from the specified components. Specifying a port number of -1 indicates that the URL should use the default port for that protocol. Based on logic from JDK 1.3.1's `java.net.URL`.
      Parameters:
        `protocol` - Name of the protocol to use
        `host` - Name of the host addressed by this protocol
        `port` - Port number, or -1 for the default port for this protocol
        `file` - Filename on the specified host
      Throws:
        `MalformedURLException` - is never thrown, but present for compatible APIs

  - ### Method Detail

    - #### equals

          public boolean equals(Object obj)

      Compare two URLs for equality. The result is `true` if and only if the argument is not null, and is a `URL` object that represents the same `URL` as this object. Two `URLs` are equal if they have the same protocol and reference the same host, the same port number on the host, and the same file and anchor on the host.
      Overrides:
        `equals` in class `Object`
      Parameters:
        `obj` - The URL to compare against

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### getAuthority

          public String getAuthority()

      Return the authority part of the URL.

    - #### getFile

          public String getFile()

      Return the filename part of the URL. NOTE - For compatibility with `java.net.URL`, this value includes the query string if there was one. For just the path portion, call `getPath()` instead.

    - #### getHost

          public String getHost()

      Return the host name part of the URL.

    - #### getPath

          public String getPath()

      Return the path part of the URL.

    - #### getPort

          public int getPort()

      Return the port number part of the URL.

    - #### getProtocol

          public String getProtocol()

      Return the protocol name part of the URL.

    - #### getQuery

          public String getQuery()

      Return the query part of the URL.

    - #### getRef

          public String getRef()

      Return the reference part of the URL.

    - #### getUserInfo

          public String getUserInfo()

      Return the user info part of the URL.

    - #### normalize

          public void normalize()
                         throws MalformedURLException

      Normalize the `path` (and therefore `file`) portions of this URL.

      NOTE - This method is not part of the public API of `java.net.URL`, but is provided as a value added service of this implementation.

      Throws:
        `MalformedURLException` - if a normalization error occurs, such as trying to move about the hierarchical root

    - #### sameFile

          public boolean sameFile(URL other)

      Compare two URLs, excluding the "ref" fields. Returns `true` if this `URL` and the `other` argument both refer to the same resource. The two `URLs` might not both contain the same anchor.

    - #### toExternalForm

          @Deprecated
          public String toExternalForm()

      Deprecated. Unused. Will be removed in Tomcat 8.0.x
      Return a string representation of this URL. This follow the rules in RFC 2396, Section 5.2, Step 7.

    - #### toString

          public String toString()

      Return a string representation of this object.
      Overrides:
        `toString` in class `Object`

    - #### isSchemeChar

          public static boolean isSchemeChar(char c)

      Determine if the character is allowed in the scheme of a URI. See RFC 2396, Section 3.1

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.