Class Location

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.htmlunit.corejs.javascript.ConstProperties, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

    public class Location
    extends HtmlUnitScriptable
    A JavaScript object for Location.
    See Also:
    MSDN Documentation, Serialized Form
    • Nested Class Summary

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

        org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.reflect.Method getterHash  
      private static java.lang.reflect.Method getterHost  
      private static java.lang.reflect.Method getterHostname  
      private static java.lang.reflect.Method getterHref  
      private static java.lang.reflect.Method getterOrigin  
      private static java.lang.reflect.Method getterPathname  
      private static java.lang.reflect.Method getterPort  
      private static java.lang.reflect.Method getterProtocol  
      private static java.lang.reflect.Method getterSearch  
      private java.lang.String hash_
      The current hash; we cache it locally because we don't want to modify the page's URL and force a page reload each time this changes.
      private static org.apache.commons.logging.Log LOG  
      private static java.lang.reflect.Method methodAssign  
      private static java.lang.reflect.Method methodReload  
      private static java.lang.reflect.Method methodReplace  
      private static java.lang.reflect.Method methodToString  
      private static java.lang.reflect.Method setterHash  
      private static java.lang.reflect.Method setterHost  
      private static java.lang.reflect.Method setterHostname  
      private static java.lang.reflect.Method setterHref  
      private static java.lang.reflect.Method setterPathname  
      private static java.lang.reflect.Method setterPort  
      private static java.lang.reflect.Method setterProtocol  
      private static java.lang.reflect.Method setterSearch  
      private static java.lang.String UNKNOWN  
      private Window window_
      The window which owns this location object.
      • Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject

        CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
      • Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable

        NOT_FOUND
    • Constructor Summary

      Constructors 
      Constructor Description
      Location()
      Creates an instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void assign​(java.lang.String url)
      Loads the new HTML document corresponding to the specified URL.
      private static java.lang.String decodeHash​(java.lang.String hash)  
      java.lang.Object getDefaultValue​(java.lang.Class<?> hint)
      Returns the JavaScript default value of this object.
      java.lang.String getHash()
      Returns the hash portion of the location URL (the portion following the '#').
      private java.lang.String getHash​(boolean encoded)  
      java.lang.String getHost()
      Returns the host portion of the location URL (the '[hostname]:[port]' portion).
      java.lang.String getHostname()
      Returns the hostname portion of the location URL.
      java.lang.String getHref()
      Returns the location URL.
      java.lang.String getOrigin()
      Returns the origin property.
      java.lang.String getPathname()
      Returns the pathname portion of the location URL.
      java.lang.String getPort()
      Returns the port portion of the location URL.
      java.lang.String getProtocol()
      Returns the protocol portion of the location URL, including the trailing ':'.
      java.lang.String getSearch()
      Returns the search portion of the location URL (the portion following the '?').
      private java.net.URL getUrl()
      Returns this location's current URL.
      void initialize​(Window window, Page page)
      Initializes this Location.
      void jsConstructor()
      Creates an instance.
      java.lang.String jsToString()
      Returns the location URL.
      void reload​(boolean force)
      Reloads the current page, possibly forcing retrieval from the server even if the browser cache contains the latest version of the document.
      void replace​(java.lang.String url)
      Reloads the window using the specified URL via a postponed action.
      void setHash​(java.lang.String hash)
      Sets the hash portion of the location URL (the portion following the '#').
      void setHash​(java.lang.String oldURL, java.lang.String hash)
      Sets the hash portion of the location URL (the portion following the '#').
      void setHash​(java.lang.String oldURL, java.lang.String hash, boolean triggerHashChanged)
      INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
      Sets the hash portion of the location URL (the portion following the '#').
      void setHost​(java.lang.String host)
      Sets the host portion of the location URL (the '[hostname]:[port]' portion).
      void setHostname​(java.lang.String hostname)
      Sets the hostname portion of the location URL.
      void setHref​(java.lang.String newLocation)
      Sets the location URL to an entirely new value.
      void setPathname​(java.lang.String pathname)
      Sets the pathname portion of the location URL.
      void setPort​(java.lang.String port)
      Sets the port portion of the location URL.
      void setProtocol​(java.lang.String protocol)
      Sets the protocol portion of the location URL.
      void setSearch​(java.lang.String search)
      Sets the search portion of the location URL (the portion following the '?').
      private void setUrl​(java.net.URL url)
      Sets this location's URL, triggering a server hit and loading the resultant document into this location's window.
      • Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject

        applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • window_

        private Window window_
        The window which owns this location object.
      • methodAssign

        private static final java.lang.reflect.Method methodAssign
      • methodReload

        private static final java.lang.reflect.Method methodReload
      • methodReplace

        private static final java.lang.reflect.Method methodReplace
      • methodToString

        private static final java.lang.reflect.Method methodToString
      • getterHash

        private static final java.lang.reflect.Method getterHash
      • setterHash

        private static final java.lang.reflect.Method setterHash
      • getterHost

        private static final java.lang.reflect.Method getterHost
      • setterHost

        private static final java.lang.reflect.Method setterHost
      • getterHostname

        private static final java.lang.reflect.Method getterHostname
      • setterHostname

        private static final java.lang.reflect.Method setterHostname
      • getterHref

        private static final java.lang.reflect.Method getterHref
      • setterHref

        private static final java.lang.reflect.Method setterHref
      • getterOrigin

        private static final java.lang.reflect.Method getterOrigin
      • getterPathname

        private static final java.lang.reflect.Method getterPathname
      • setterPathname

        private static final java.lang.reflect.Method setterPathname
      • getterPort

        private static final java.lang.reflect.Method getterPort
      • setterPort

        private static final java.lang.reflect.Method setterPort
      • getterProtocol

        private static final java.lang.reflect.Method getterProtocol
      • setterProtocol

        private static final java.lang.reflect.Method setterProtocol
      • getterSearch

        private static final java.lang.reflect.Method getterSearch
      • setterSearch

        private static final java.lang.reflect.Method setterSearch
      • hash_

        private java.lang.String hash_
        The current hash; we cache it locally because we don't want to modify the page's URL and force a page reload each time this changes.
    • Constructor Detail

      • Location

        public Location()
        Creates an instance.
    • Method Detail

      • jsConstructor

        public void jsConstructor()
        Creates an instance.
      • initialize

        public void initialize​(Window window,
                               Page page)
        Initializes this Location.
        Parameters:
        window - the window that this location belongs to
        page - the page that will become the enclosing page
      • getDefaultValue

        public java.lang.Object getDefaultValue​(java.lang.Class<?> hint)
        Returns the JavaScript default value of this object. This is the JavaScript equivalent of a toString() in Java.
        Specified by:
        getDefaultValue in interface org.htmlunit.corejs.javascript.Scriptable
        Overrides:
        getDefaultValue in class HtmlUnitScriptable
        Parameters:
        hint - a hint as to the format of the default value (ignored in this case)
        Returns:
        the default value
      • assign

        public void assign​(java.lang.String url)
                    throws java.io.IOException
        Loads the new HTML document corresponding to the specified URL.
        Parameters:
        url - the location of the new HTML document to load
        Throws:
        java.io.IOException - if loading the specified location fails
        See Also:
        MSDN Documentation
      • reload

        public void reload​(boolean force)
                    throws java.io.IOException
        Reloads the current page, possibly forcing retrieval from the server even if the browser cache contains the latest version of the document.
        Parameters:
        force - if true, force reload from server; otherwise, may reload from cache
        Throws:
        java.io.IOException - if there is a problem reloading the page
        See Also:
        MSDN Documentation
      • replace

        public void replace​(java.lang.String url)
                     throws java.io.IOException
        Reloads the window using the specified URL via a postponed action.
        Parameters:
        url - the new URL to use to reload the window
        Throws:
        java.io.IOException - if loading the specified location fails
        See Also:
        MSDN Documentation
      • jsToString

        public java.lang.String jsToString()
        Returns the location URL.
        Returns:
        the location URL
      • getHref

        public java.lang.String getHref()
        Returns the location URL.
        Returns:
        the location URL
        See Also:
        MSDN Documentation
      • setHref

        public void setHref​(java.lang.String newLocation)
                     throws java.io.IOException
        Sets the location URL to an entirely new value.
        Parameters:
        newLocation - the new location URL
        Throws:
        java.io.IOException - if loading the specified location fails
        See Also:
        MSDN Documentation
      • getSearch

        public java.lang.String getSearch()
        Returns the search portion of the location URL (the portion following the '?').
        Returns:
        the search portion of the location URL
        See Also:
        MSDN Documentation
      • setSearch

        public void setSearch​(java.lang.String search)
                       throws java.lang.Exception
        Sets the search portion of the location URL (the portion following the '?').
        Parameters:
        search - the new search portion of the location URL
        Throws:
        java.lang.Exception - if an error occurs
        See Also:
        MSDN Documentation
      • getHash

        public java.lang.String getHash()
        Returns the hash portion of the location URL (the portion following the '#').
        Returns:
        the hash portion of the location URL
        See Also:
        MSDN Documentation
      • getHash

        private java.lang.String getHash​(boolean encoded)
      • setHash

        public void setHash​(java.lang.String hash)
        Sets the hash portion of the location URL (the portion following the '#').
        Parameters:
        hash - the new hash portion of the location URL
        See Also:
        MSDN Documentation
      • setHash

        public void setHash​(java.lang.String oldURL,
                            java.lang.String hash)
        Sets the hash portion of the location URL (the portion following the '#').
        Parameters:
        oldURL - the old URL
        hash - the new hash portion of the location URL
      • setHash

        public void setHash​(java.lang.String oldURL,
                            java.lang.String hash,
                            boolean triggerHashChanged)
        INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
        Sets the hash portion of the location URL (the portion following the '#').
        Parameters:
        oldURL - the old URL
        hash - the new hash portion of the location URL
        triggerHashChanged - option to disable event triggering
      • decodeHash

        private static java.lang.String decodeHash​(java.lang.String hash)
      • getHostname

        public java.lang.String getHostname()
        Returns the hostname portion of the location URL.
        Returns:
        the hostname portion of the location URL
        See Also:
        MSDN Documentation
      • setHostname

        public void setHostname​(java.lang.String hostname)
                         throws java.lang.Exception
        Sets the hostname portion of the location URL.
        Parameters:
        hostname - the new hostname portion of the location URL
        Throws:
        java.lang.Exception - if an error occurs
        See Also:
        MSDN Documentation
      • getHost

        public java.lang.String getHost()
        Returns the host portion of the location URL (the '[hostname]:[port]' portion).
        Returns:
        the host portion of the location URL
        See Also:
        MSDN Documentation
      • setHost

        public void setHost​(java.lang.String host)
                     throws java.lang.Exception
        Sets the host portion of the location URL (the '[hostname]:[port]' portion).
        Parameters:
        host - the new host portion of the location URL
        Throws:
        java.lang.Exception - if an error occurs
        See Also:
        MSDN Documentation
      • getPathname

        public java.lang.String getPathname()
        Returns the pathname portion of the location URL.
        Returns:
        the pathname portion of the location URL
        See Also:
        MSDN Documentation
      • setPathname

        public void setPathname​(java.lang.String pathname)
                         throws java.lang.Exception
        Sets the pathname portion of the location URL.
        Parameters:
        pathname - the new pathname portion of the location URL
        Throws:
        java.lang.Exception - if an error occurs
        See Also:
        MSDN Documentation
      • getPort

        public java.lang.String getPort()
        Returns the port portion of the location URL.
        Returns:
        the port portion of the location URL
        See Also:
        MSDN Documentation
      • setPort

        public void setPort​(java.lang.String port)
                     throws java.lang.Exception
        Sets the port portion of the location URL.
        Parameters:
        port - the new port portion of the location URL
        Throws:
        java.lang.Exception - if an error occurs
        See Also:
        MSDN Documentation
      • getProtocol

        public java.lang.String getProtocol()
        Returns the protocol portion of the location URL, including the trailing ':'.
        Returns:
        the protocol portion of the location URL, including the trailing ':'
        See Also:
        MSDN Documentation
      • setProtocol

        public void setProtocol​(java.lang.String protocol)
                         throws java.lang.Exception
        Sets the protocol portion of the location URL.
        Parameters:
        protocol - the new protocol portion of the location URL
        Throws:
        java.lang.Exception - if an error occurs
        See Also:
        MSDN Documentation
      • getUrl

        private java.net.URL getUrl()
        Returns this location's current URL.
        Returns:
        this location's current URL
      • setUrl

        private void setUrl​(java.net.URL url)
                     throws java.io.IOException
        Sets this location's URL, triggering a server hit and loading the resultant document into this location's window.
        Parameters:
        url - This location's new URL
        Throws:
        java.io.IOException - if there is a problem loading the new location
      • getOrigin

        public java.lang.String getOrigin()
        Returns the origin property.
        Returns:
        the origin property