Class URLWithScheme

java.lang.Object
org.htmlunit.csp.url.URLWithScheme
Direct Known Subclasses:
GUID, URI

public abstract class URLWithScheme extends Object
Abstract base class representing a URL that has at least a scheme component.

This is the common supertype for both hierarchical URLs (URI) and opaque/non-hierarchical URLs (GUID). The scheme and host are always stored in lowercase per the relevant specifications. The port and path may be null depending on the URL type.

Two URLWithScheme instances are considered equal if their scheme, host, port, and path are all equal.

Author:
Salvation Team
  • Constructor Details

    • URLWithScheme

      protected URLWithScheme(String scheme, String host, Integer port, String path)
      Constructs a URL with the given components.

      The scheme is lowercased. The host, if non-null, is also lowercased. The port and path are stored as-is.

      Parameters:
      scheme - the URL scheme (e.g. "https", "javascript"); will be lowercased
      host - the host component, or null if not applicable; will be lowercased if non-null
      port - the port number, or null if not applicable
      path - the path component, or null if not applicable
  • Method Details

    • getScheme

      public String getScheme()
      Returns the scheme component of this URL, in lowercase.
      Returns:
      the scheme (e.g. "https", "data", "javascript")
    • getHost

      public String getHost()
      Returns the host component of this URL, in lowercase.
      Returns:
      the host, or null if this URL has no host (e.g. for GUID URLs like data: or javascript:)
    • getPort

      public Integer getPort()
      Returns the port component of this URL.
      Returns:
      the port number, or null if this URL has no port
    • getPath

      public String getPath()
      Returns the path component of this URL.

      For URI instances this is the path portion of the hierarchical URL (e.g. "/scripts/app.js"). For GUID instances this is the opaque data after the scheme (e.g. the source code in a javascript: URL).

      Returns:
      the path, or null if not applicable
    • equals

      public boolean equals(Object o)

      Two URLWithScheme instances are equal if their scheme, host, port, and path are all equal.

      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object