com.gargoylesoftware.htmlunit.javascript.host.html
Class HTMLCollection

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCollection
All Implemented Interfaces:
Serializable, Cloneable, Map, net.sourceforge.htmlunit.corejs.javascript.Callable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Function, net.sourceforge.htmlunit.corejs.javascript.Scriptable, NodeList
Direct Known Subclasses:
HTMLCollectionTags

public class HTMLCollection
extends SimpleScriptable
implements net.sourceforge.htmlunit.corejs.javascript.Function, NodeList

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.

Version:
$Revision: 5864 $
Author:
Daniel Gredler, Marc Guillemot, Chris Erskine, Ahmed Ashour
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
HTMLCollection()
          Deprecated. 
HTMLCollection(DomNode parentScope)
          Creates an instance.
HTMLCollection(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject parentScope)
          Creates an instance.
 
Method Summary
 boolean avoidObjectDetection()
          Only needed to make collections like document.all available but "invisible" when simulating Firefox.
 Object call(net.sourceforge.htmlunit.corejs.javascript.Context cx, net.sourceforge.htmlunit.corejs.javascript.Scriptable scope, net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObj, Object[] args)
          
protected  List<Object> computeElements()
          Returns the elements whose associated host objects are available through this collection.
 net.sourceforge.htmlunit.corejs.javascript.Scriptable construct(net.sourceforge.htmlunit.corejs.javascript.Context cx, net.sourceforge.htmlunit.corejs.javascript.Scriptable scope, Object[] args)
          
protected  Object equivalentValues(Object other)
          Called for the js "==".
 Object get(int index, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          Returns the element at the specified index, or NOT_FOUND if the index is invalid.
 String getClassName()
          Returns the JavaScript class name.
protected  List<Object> getElements()
          Gets the HTML elements from cache or retrieve them at first call.
 Object[] getIds()
          .
 int getLength()
          
protected  net.sourceforge.htmlunit.corejs.javascript.Scriptable getScriptableForElement(Object object)
          Gets the scriptable for the provided element that may already be the right scriptable.
protected  Object getWithPreemption(String name)
          Returns the element or elements that match the specified key.
 boolean has(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          
 void init(DomNode node, String xpath)
          Initializes the content of this collection.
 void init(DomNode node, String xpath, org.apache.commons.collections.Transformer transformer)
          Initializes the content of this collection.
 void initFromChildren(DomNode node)
          Initializes the collection.
 Node item(int index)
          
 Object jsxFunction_item(Object index)
          Returns the item or items corresponding to the specified index or key.
 Object jsxFunction_namedItem(String name)
          Retrieves the item or items corresponding to the specified name (checks ids, and if that does not work, then names).
 Object jsxFunction_nextNode()
          Returns the next node in the collection (supporting iteration in IE only).
 void jsxFunction_reset()
          Resets the node iterator accessed via jsxFunction_nextNode().
 Object jsxFunction_tags(String tagName)
          Returns all the elements in this element array that have the specified tag name.
 int jsxGet_length()
          Returns the length of this element array.
 void setAvoidObjectDetection(boolean newValue)
           
 String toString()
          
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, get, getBrowserVersion, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, hasInstance, initParentScope, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, buildDataDescriptor, callMethod, callMethod, clear, containsKey, containsValue, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, entrySet, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypeOf, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, keySet, preventExtensions, put, put, put, putAll, putConst, putConstProperty, putProperty, putProperty, redefineProperty, remove, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype, size, values
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
delete, delete, get, getDefaultValue, getParentScope, getPrototype, has, hasInstance, put, put, setParentScope, setPrototype
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

HTMLCollection

@Deprecated
public HTMLCollection()
Deprecated. 

Creates an instance. JavaScript objects must have a default constructor. Don't call.


HTMLCollection

public HTMLCollection(DomNode parentScope)
Creates an instance.

Parameters:
parentScope - parent scope

HTMLCollection

public HTMLCollection(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject parentScope)
Creates an instance.

Parameters:
parentScope - parent scope
Method Detail

avoidObjectDetection

public boolean avoidObjectDetection()
Only needed to make collections like document.all available but "invisible" when simulating Firefox.

Overrides:
avoidObjectDetection in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

setAvoidObjectDetection

public void setAvoidObjectDetection(boolean newValue)
Parameters:
newValue - the new value

init

public void init(DomNode node,
                 String xpath)
Initializes the content of this collection. The elements will be "calculated" at each access using the specified XPath expression, applied to the specified node.

Parameters:
node - the node to serve as root for the XPath expression
xpath - the XPath expression which determines the elements of the collection

init

public void init(DomNode node,
                 String xpath,
                 org.apache.commons.collections.Transformer transformer)
Initializes the content of this collection. The elements will be "calculated" at each access using the specified XPath expression, applied to the specified node, and transformed using the specified transformer.

Parameters:
node - the node to serve as root for the XPath expression
xpath - the XPath expression which determines the elements of the collection
transformer - the transformer enabling the retrieval of the expected objects from the results of the XPath evaluation

initFromChildren

public void initFromChildren(DomNode node)
Initializes the collection. The elements will be "calculated" as the children of the node.

Parameters:
node - the node to grab children from

call

public final Object call(net.sourceforge.htmlunit.corejs.javascript.Context cx,
                         net.sourceforge.htmlunit.corejs.javascript.Scriptable scope,
                         net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObj,
                         Object[] args)

Specified by:
call in interface net.sourceforge.htmlunit.corejs.javascript.Callable
Specified by:
call in interface net.sourceforge.htmlunit.corejs.javascript.Function

construct

public final net.sourceforge.htmlunit.corejs.javascript.Scriptable construct(net.sourceforge.htmlunit.corejs.javascript.Context cx,
                                                                             net.sourceforge.htmlunit.corejs.javascript.Scriptable scope,
                                                                             Object[] args)

Specified by:
construct in interface net.sourceforge.htmlunit.corejs.javascript.Function

get

public final Object get(int index,
                        net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
Returns the element at the specified index, or NOT_FOUND if the index is invalid.

Specified by:
get in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
get in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

getElements

protected List<Object> getElements()
Gets the HTML elements from cache or retrieve them at first call.

Returns:
the list of HtmlElement contained in this collection

computeElements

protected List<Object> computeElements()
Returns the elements whose associated host objects are available through this collection.

Returns:
the elements whose associated host objects are available through this collection

getWithPreemption

protected Object getWithPreemption(String name)
Returns the element or elements that match the specified key. If it is the name of a property, the property value is returned. If it is the id of an element in the array, that element is returned. Finally, if it is the name of an element or elements in the array, then all those elements are returned. Otherwise, Scriptable.NOT_FOUND is returned.

Called by SimpleScriptable.get(String, Scriptable) to allow retrieval of the property before the prototype chain is searched.

IMPORTANT: This method is invoked *very* often by Rhino. If you override this method, the implementation needs to be as fast as possible!

Overrides:
getWithPreemption in class SimpleScriptable
Parameters:
name - the property name
Returns:
Scriptable.NOT_FOUND if not found

jsxGet_length

public final int jsxGet_length()
Returns the length of this element array.

Returns:
the length of this element array
See Also:
MSDN doc

jsxFunction_item

public final Object jsxFunction_item(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

jsxFunction_namedItem

public final Object jsxFunction_namedItem(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

jsxFunction_nextNode

public Object jsxFunction_nextNode()
Returns the next node in the collection (supporting iteration in IE only).

Returns:
the next node in the collection

jsxFunction_reset

public void jsxFunction_reset()
Resets the node iterator accessed via jsxFunction_nextNode().


jsxFunction_tags

public Object jsxFunction_tags(String tagName)
Returns all the elements in this element array that have the specified tag name. This method returns an empty element array if there are no elements with the specified tag name.

Parameters:
tagName - the name of the tag of the elements to return
Returns:
all the elements in this element array that have the specified tag name
See Also:
MSDN doc

toString

public String toString()

Overrides:
toString in class Object

equivalentValues

protected Object equivalentValues(Object other)
Called for the js "==".

Overrides:
equivalentValues in class SimpleScriptable

has

public boolean has(String name,
                   net.sourceforge.htmlunit.corejs.javascript.Scriptable start)

Specified by:
has in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
has in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

getIds

public Object[] getIds()
.

Specified by:
getIds in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
getIds in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

getLength

public int getLength()

Specified by:
getLength in interface NodeList

item

public Node item(int index)

Specified by:
item in interface NodeList

getScriptableForElement

protected net.sourceforge.htmlunit.corejs.javascript.Scriptable getScriptableForElement(Object object)
Gets the scriptable for the provided element that may already be the right scriptable.

Parameters:
object - the object for which to get the scriptable
Returns:
the scriptable

getClassName

public String getClassName()
Returns the JavaScript class name.

Specified by:
getClassName in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
getClassName in class SimpleScriptable
Returns:
the JavaScript class name


Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.