Class HTMLCollection

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.htmlunit.corejs.javascript.Callable, org.htmlunit.corejs.javascript.ConstProperties, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.ExternalArrayData, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable
    Direct Known Subclasses:
    HTMLAllCollection, HTMLCollectionFrames, HTMLFormControlsCollection

    public class HTMLCollection
    extends AbstractList
    implements org.htmlunit.corejs.javascript.Callable
    An array of elements. Used for the element arrays returned by document.all, document.all.tags('x'), document.forms, window.frames, etc. Note that this class must not be used for collections that can be modified, for example map.areas and select.options.
    This class (like all classes in this package) is specific for the JavaScript engine. Users of HtmlUnit shouldn't use it directly.
    See Also:
    Serialized Form
    • Constructor Detail

      • HTMLCollection

        public HTMLCollection()
        Creates an instance.
      • HTMLCollection

        public HTMLCollection​(DomNode domNode,
                              boolean attributeChangeSensitive)
        Creates an instance.
        Parameters:
        domNode - parent scope
        attributeChangeSensitive - indicates if the content of the collection may change when an attribute of a descendant node of parentScope changes (attribute added, modified or removed)
      • HTMLCollection

        HTMLCollection​(DomNode domNode,
                       java.util.List<DomNode> initialElements)
        Constructs an instance with an initial cache value.
        Parameters:
        domNode - the parent scope, on which we listen for changes
        initialElements - the initial content for the cache
      • HTMLCollection

        private HTMLCollection​(DomNode domNode,
                               boolean attributeChangeSensitive,
                               java.util.List<DomNode> initialElements)
    • Method Detail

      • jsConstructor

        public void jsConstructor()
        JavaScript constructor.
      • emptyCollection

        public static HTMLCollection emptyCollection​(DomNode domNode)
        Gets an empty collection.
        Parameters:
        domNode - the DOM node
        Returns:
        an empty collection
      • create

        protected HTMLCollection create​(DomNode parentScope,
                                        java.util.List<DomNode> initialElements)
        Constructs a new instance with an initial cache value.
        Overrides:
        create in class AbstractList
        Parameters:
        parentScope - the parent scope, on which we listen for changes
        initialElements - the initial content for the cache
        Returns:
        the newly created instance
      • iterator

        public org.htmlunit.corejs.javascript.Scriptable iterator()
      • getLength

        public final int getLength()
        Returns the length.
        Overrides:
        getLength in class AbstractList
        Returns:
        the length
      • call

        public java.lang.Object call​(org.htmlunit.corejs.javascript.Context cx,
                                     org.htmlunit.corejs.javascript.Scriptable scope,
                                     org.htmlunit.corejs.javascript.Scriptable thisObj,
                                     java.lang.Object[] args)
        Specified by:
        call in interface org.htmlunit.corejs.javascript.Callable
      • supportsParentheses

        protected boolean supportsParentheses()
        Is parentheses supported.
        Returns:
        true or false
      • getWithPreemptionByName

        protected java.lang.Object getWithPreemptionByName​(java.lang.String name,
                                                           java.util.List<DomNode> elements)
        Helper for AbstractList.getWithPreemption(String) when finding by id doesn't get results.
        Overrides:
        getWithPreemptionByName in class AbstractList
        Parameters:
        name - the property name
        elements - the children elements.
        Returns:
        Scriptable.NOT_FOUND if not found
      • item

        public java.lang.Object item​(java.lang.Object index)
        Returns the item or items corresponding to the specified index or key.
        Parameters:
        index - the index or key corresponding to the element or elements to return
        Returns:
        the element or elements corresponding to the specified index or key
        See Also:
        MSDN doc
      • namedItem

        public java.lang.Object namedItem​(java.lang.String name)
        Retrieves the item or items corresponding to the specified name (checks ids, and if that does not work, then names).
        Parameters:
        name - the name or id the element or elements to return
        Returns:
        the element or elements corresponding to the specified name or id
        See Also:
        MSDN doc