Module org.htmlunit

Class URL

java.lang.Object
org.htmlunit.corejs.javascript.SlotMapOwner<org.htmlunit.corejs.javascript.Scriptable>
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.URL
All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

public class URL extends HtmlUnitScriptable
JavaScript host object for URL.
Author:
Ahmed Ashour, Ronald Brill, cd alexndr, Lai Quang Duong
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    org.htmlunit.corejs.javascript.ScriptableObject.DescriptorInfo, org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator, org.htmlunit.corejs.javascript.ScriptableObject.LambdaGetterFunction, org.htmlunit.corejs.javascript.ScriptableObject.LambdaSetterFunction
  • Field Summary

    Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST

    Fields inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    isSealed

    Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable

    NOT_FOUND
  • Constructor Summary

    Constructors
    Constructor
    Description
    URL()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    createObjectURL(Object fileOrBlob)
    The URL.createObjectURL() static method creates a DOMString containing a URL representing the object given as parameter.
    Returns the default string representation of this URL.
    Returns the hash portion of the URL, containing a # followed by the fragment identifier.
    Returns the host portion of the URL, consisting of the hostname and, if the port is non-empty, a : followed by the port.
    Returns the hostname portion of the URL.
    Returns the full URL as a string.
    Returns the origin of the URL.
    Returns the password specified before the domain name.
    Returns the pathname portion of the URL.
    Returns the port number of the URL, or an empty string if no explicit port is specified.
    Returns the protocol scheme of the URL, including the trailing :.
    Returns the query string, containing a ? followed by the URL's parameters.
    Returns a URLSearchParams object providing access to the decoded query arguments of the URL.
    Returns the username specified before the domain name.
    void
    Creates an instance of this object.
    Returns the URL as a string.
    static void
    revokeObjectURL(org.htmlunit.corejs.javascript.Scriptable objectURL)
    Revokes a blob: URL, removing its entry from the blob URL store.
    void
    setHash(String fragment)
    Sets the hash property.
    void
    Sets the host property.
    void
    setHostname(String hostname)
    Sets the hostname property.
    void
    Sets the href property, navigating to the new URL.
    void
    setPassword(String password)
    Sets the password property.
    void
    Sets the pathname property.
    void
    Sets the port property.
    void
    setProtocol(String protocol)
    Sets the protocol property.
    void
    setSearch(String search)
    Sets the search property.
    void
    setSearch(List<NameValuePair> nameValuePairs)
    Sets the search property from a list of NameValuePairs.
    void
    setUsername(String username)
    Sets the username property.
    Returns a serialized version of the URL.

    Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    applyDescriptorToAttributeBitset, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkNotSealed, checkPropertyChangeForSlot, checkPropertyChangeForSlot, checkPropertyDefinition, checkPropertyDefinition, checkSlotRemoval, defineBuiltinProperty, defineBuiltinProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, ensureType, get, get, getAllIds, getAncestor, getArrayPrototype, getClassPrototype, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getThis, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasProperty, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGenericDescriptor, isGetterOrSetter, isGetterOrSetter, isTrue, preventExtensions, put, put, putConst, putConstProperty, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, redefineProperty, sameValue, sealObject, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size

    Methods inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    associateValue, checkNotSealed, copyAssociatedValue, createSlotMap, defineProperty, defineProperty, get, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getIds, has, has, isSealed, readMaps, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, writeMaps

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.htmlunit.corejs.javascript.Scriptable

    get, getIds, has, has

    Methods inherited from interface org.htmlunit.corejs.javascript.SymbolScriptable

    get, has
  • Constructor Details

    • URL

      public URL()
  • Method Details

    • jsConstructor

      public void jsConstructor(String url, Object base)
      Creates an instance of this object.
      Parameters:
      url - a string representing an absolute or relative URL. If url is a relative URL, base is required and will be used as the base URL. If url is an absolute URL, a given base will be ignored.
      base - a string representing the base URL to use when url is a relative URL. If not specified, it defaults to ''.
    • createObjectURL

      public static String createObjectURL(Object fileOrBlob)
      The URL.createObjectURL() static method creates a DOMString containing a URL representing the object given as parameter. The new object URL represents the specified File object or Blob object and is registered in the user-agent-wide blob URL store, so it can be resolved from any document of the same client.
      Parameters:
      fileOrBlob - the File or Blob to create an object URL for
      Returns:
      the object URL, or null if the argument is not a supported type
      See Also:
    • revokeObjectURL

      public static void revokeObjectURL(org.htmlunit.corejs.javascript.Scriptable objectURL)
      Revokes a blob: URL, removing its entry from the blob URL store.
      Parameters:
      objectURL - the object URL previously returned by createObjectURL(Object)
      See Also:
    • getHash

      public String getHash()
      Returns the hash portion of the URL, containing a # followed by the fragment identifier.
      Returns:
      the hash portion of the URL, or an empty string if there is no fragment
    • setHash

      public void setHash(String fragment) throws MalformedURLException
      Sets the hash property.
      Parameters:
      fragment - the new hash value
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • getHost

      public String getHost()
      Returns the host portion of the URL, consisting of the hostname and, if the port is non-empty, a : followed by the port.
      Returns:
      the host
    • setHost

      public void setHost(String host) throws MalformedURLException
      Sets the host property.
      Parameters:
      host - the new host value
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • getHostname

      public String getHostname()
      Returns the hostname portion of the URL.
      Returns:
      the hostname
    • setHostname

      public void setHostname(String hostname) throws MalformedURLException
      Sets the hostname property.
      Parameters:
      hostname - the new hostname value
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • getHref

      public String getHref()
      Returns the full URL as a string.
      Returns:
      the full URL
    • setHref

      public void setHref(String href) throws MalformedURLException
      Sets the href property, navigating to the new URL.
      Parameters:
      href - the new URL string
      Throws:
      MalformedURLException - if the URL is malformed
    • getOrigin

      public Object getOrigin()
      Returns the origin of the URL.
      Returns:
      the origin
    • getSearchParams

      public URLSearchParams getSearchParams()
      Returns a URLSearchParams object providing access to the decoded query arguments of the URL.
      Returns:
      the search params
    • getPassword

      public String getPassword()
      Returns the password specified before the domain name.
      Returns:
      the password, or an empty string if none is specified
    • setPassword

      public void setPassword(String password) throws MalformedURLException
      Sets the password property.
      Parameters:
      password - the new password value
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • getPathname

      public String getPathname()
      Returns the pathname portion of the URL.
      Returns:
      the pathname
    • setPathname

      public void setPathname(String path) throws MalformedURLException
      Sets the pathname property.
      Parameters:
      path - the new pathname value
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • getPort

      public String getPort()
      Returns the port number of the URL, or an empty string if no explicit port is specified.
      Returns:
      the port, or an empty string
    • setPort

      public void setPort(String port) throws MalformedURLException
      Sets the port property.
      Parameters:
      port - the new port value, or an empty string to remove the port
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • getProtocol

      public String getProtocol()
      Returns the protocol scheme of the URL, including the trailing :.
      Returns:
      the protocol
    • setProtocol

      public void setProtocol(String protocol) throws MalformedURLException
      Sets the protocol property.
      Parameters:
      protocol - the new protocol value
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • getSearch

      public String getSearch()
      Returns the query string, containing a ? followed by the URL's parameters.
      Returns:
      the search string, or an empty string if none
    • setSearch

      public void setSearch(String search) throws MalformedURLException
      Sets the search property.
      Parameters:
      search - the new search string
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • setSearch

      public void setSearch(List<NameValuePair> nameValuePairs) throws MalformedURLException
      Sets the search property from a list of NameValuePairs.
      Parameters:
      nameValuePairs - the pairs to encode as the query string
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • getUsername

      public String getUsername()
      Returns the username specified before the domain name.
      Returns:
      the username, or an empty string if none is specified
    • setUsername

      public void setUsername(String username) throws MalformedURLException
      Sets the username property.
      Parameters:
      username - the new username value
      Throws:
      MalformedURLException - if the resulting URL is malformed
    • getDefaultValue

      public Object getDefaultValue(Class<?> hint)
      Returns the default string representation of this URL.
      Specified by:
      getDefaultValue in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      getDefaultValue in class HtmlUnitScriptable
      Parameters:
      hint - the type hint
      Returns:
      the URL as a string
      See Also:
    • toJSON

      public String toJSON()
      Returns a serialized version of the URL. In practice this is equivalent to jsToString().
      Returns:
      the serialized URL string
    • jsToString

      public String jsToString()
      Returns the URL as a string.
      Returns:
      the URL string