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
A JavaScript 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 in parameter.
    Calls for instance for implicit conversion to string.
     
     
     
     
     
     
     
     
     
     
     
     
    void
    Creates an instance.
    Returns the text of the URL.
    static void
    revokeObjectURL(org.htmlunit.corejs.javascript.Scriptable objectURL)
     
    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.
    void
    setPassword(String password)
    Sets the password property.
    void
    Sets the path 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 based on NameValuePair's.
    void
    setUsername(String username)
    Sets the username property.
     

    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, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, 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.
      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 in case 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 in parameter. The URL lifetime is tied to the document in the window on which it was created. The new object URL represents the specified File object or Blob object.
      Parameters:
      fileOrBlob - Is a File object or a Blob object to create a object URL for.
      Returns:
      the url
    • revokeObjectURL

      public static void revokeObjectURL(org.htmlunit.corejs.javascript.Scriptable objectURL)
      Parameters:
      objectURL - String representing the object URL that was created by calling URL.createObjectURL().
    • getHash

      public String getHash()
      Returns:
      hash property of the URL containing a '#' followed by the fragment identifier of the URL.
    • setHash

      public void setHash(String fragment) throws MalformedURLException
      Sets the hash property.
      Parameters:
      fragment - the hash property
      Throws:
      MalformedURLException
    • getHost

      public String getHost()
      Returns:
      the host, that is the hostname, and then, if the port of the URL is nonempty, a ':', followed by the port of the URL.
    • setHost

      public void setHost(String host) throws MalformedURLException
      Sets the host property.
      Parameters:
      host - the host property
      Throws:
      MalformedURLException
    • getHostname

      public String getHostname()
      Returns:
      the host, that is the hostname, and then, if the port of the URL is nonempty, a ':', followed by the port of the URL.
    • setHostname

      public void setHostname(String hostname) throws MalformedURLException
      Sets the hostname property.
      Parameters:
      hostname - the hostname property
      Throws:
      MalformedURLException
    • getHref

      public String getHref()
      Returns:
      whole URL
    • setHref

      public void setHref(String href) throws MalformedURLException
      Sets the href property.
      Parameters:
      href - the href property
      Throws:
      MalformedURLException
    • getOrigin

      public Object getOrigin()
      Returns:
      the origin
    • getSearchParams

      public URLSearchParams getSearchParams()
      Returns:
      a URLSearchParams object allowing access to the GET decoded query arguments contained in the URL.
    • getPassword

      public String getPassword()
      Returns:
      the password specified before the domain name.
    • setPassword

      public void setPassword(String password) throws MalformedURLException
      Sets the password property.
      Parameters:
      password - the password property
      Throws:
      MalformedURLException
    • getPathname

      public String getPathname()
      Returns:
      a URLSearchParams object allowing access to the GET decoded query arguments contained in the URL.
    • setPathname

      public void setPathname(String path) throws MalformedURLException
      Sets the path property.
      Parameters:
      path - the path property
      Throws:
      MalformedURLException
    • getPort

      public String getPort()
      Returns:
      the port number of the URL. If the URL does not contain an explicit port number, it will be set to ''
    • setPort

      public void setPort(String port) throws MalformedURLException
      Sets the port property.
      Parameters:
      port - the port property
      Throws:
      MalformedURLException
    • getProtocol

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

      public void setProtocol(String protocol) throws MalformedURLException
      Sets the protocol property.
      Parameters:
      protocol - the protocol property
      Throws:
      MalformedURLException
    • getSearch

      public String getSearch()
      Returns:
      the query string containing a '?' followed by the parameters of the URL
    • setSearch

      public void setSearch(String search) throws MalformedURLException
      Sets the search property.
      Parameters:
      search - the search property
      Throws:
      MalformedURLException
    • setSearch

      public void setSearch(List<NameValuePair> nameValuePairs) throws MalformedURLException
      Sets the search property based on NameValuePair's.
      Parameters:
      nameValuePairs - the pairs
      Throws:
      MalformedURLException - in case of error
    • getUsername

      public String getUsername()
      Returns:
      the username specified before the domain name.
    • setUsername

      public void setUsername(String username) throws MalformedURLException
      Sets the username property.
      Parameters:
      username - the username property
      Throws:
      MalformedURLException
    • getDefaultValue

      public Object getDefaultValue(Class<?> hint)
      Calls for instance for implicit conversion to string.
      Specified by:
      getDefaultValue in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      getDefaultValue in class HtmlUnitScriptable
      Parameters:
      hint - the type hint
      Returns:
      the default value
      See Also:
    • toJSON

      public String toJSON()
      Returns:
      a serialized version of the URL, although in practice it seems to have the same effect as URL.toString().
    • jsToString

      public String jsToString()
      Returns the text of the URL.
      Returns:
      the text