com.gargoylesoftware.htmlunit.javascript.host
Class Element

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.Node
              extended by com.gargoylesoftware.htmlunit.javascript.host.EventNode
                  extended by com.gargoylesoftware.htmlunit.javascript.host.Element
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable
Direct Known Subclasses:
HTMLElement, SVGElement

public class Element
extends EventNode

A JavaScript object for DomElement.

Version:
$Revision: 7650 $
Author:
Ahmed Ashour, Marc Guillemot, Sudhan Moghe, Ronald Brill
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.gargoylesoftware.htmlunit.javascript.host.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
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
Element()
           
 
Method Summary
protected  NamedNodeMap createAttributesObject()
          Creates the JS object for the property attributes.
protected  String fixAttributeName(String attributeName)
          Allows subclasses to transform the attribute name before it gets used.
 Object getAttribute(String attributeName, Integer flags)
          Returns the value of the specified attribute.
 Object getAttributeNode(String name)
          Retrieves an attribute node by name.
 String getAttributeNS(String namespaceURI, String localName)
          Gets the specified attribute.
 Object getAttributes()
          Returns the attributes of this XML element.
 String getBaseURI()
          Returns the Base URI as a string.
 ClientRect getBoundingClientRect()
          Retrieves an object that specifies the bounds of a collection of TextRectangle objects.
 int getChildElementCount()
          Returns the current number of child elements.
 HTMLCollection getChildren()
          Gets the children of the current node.
 DOMTokenList getClassList()
          Gets the token list of class attribute.
 DomElement getDomNodeOrDie()
          Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.
 Object getElementsByTagName(String tagName)
          Returns all the descendant elements with the specified tag name.
 Object getElementsByTagNameNS(Object namespaceURI, String localName)
          Returns a list of elements with the given tag name belonging to the given namespace.
 Element getFirstElementChild()
          Returns the first element child.
 Element getLastElementChild()
          Returns the last element child.
 Element getNextElementSibling()
          Returns the next element sibling.
 Element getParentElement()
          Gets the first ancestor instance of Element.
 Element getPreviousElementSibling()
          Returns the previous element sibling.
 String getTagName()
          Returns the tag name of this element.
 String getText()
          Represents the text content of the node or the concatenated text representing the node and its descendants.
 boolean hasAttribute(String name)
          Returns true when an attribute with a given name is specified on this element or has a default value.
 boolean hasAttributeNS(String namespaceURI, String localName)
          Test for attribute.
 void removeAttribute(String name)
          Removes the specified attribute.
 void removeAttributeNS(String namespaceURI, String localName)
          Removes the specified attribute.
 HTMLCollection selectNodes(String expression)
          Applies the specified XPath expression to this node's context and returns the generated list of matching nodes.
 Object selectSingleNode(String expression)
          Applies the specified pattern-matching operation to this node's context and returns the first matching node.
 void setAttribute(String name, String value)
          Sets an attribute.
 void setAttributeNS(String namespaceURI, String qualifiedName, String value)
          Sets the specified attribute.
 void setDefaults(ComputedCSSStyleDeclaration style)
          Callback method which allows different HTML element types to perform custom initialization of computed styles.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.host.EventNode
fireEvent, getOnblur, getOnclick, getOncontextmenu, getOndblclick, getOnerror, getOnfocus, getOnfocusin, getOnfocusout, getOnkeydown, getOnkeypress, getOnkeyup, getOnmousedown, getOnmousemove, getOnmouseout, getOnmouseover, getOnmouseup, getOnpropertychange, getOnresize, setOnblur, setOnclick, setOncontextmenu, setOndblclick, setOnerror, setOnfocus, setOnfocusin, setOnfocusout, setOnkeydown, setOnkeypress, setOnkeyup, setOnmousedown, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setOnpropertychange, setOnresize
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.host.Node
addEventListener, appendChild, attachEvent, cloneNode, compareDocumentPosition, detachEvent, executeEvent, fireEvent, fireEvent, getChildNodes, getEventHandler, getEventHandlerProp, getFirstChild, getJavaScriptNode, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParent, getParentNode, getPrefix, getPreviousSibling, getTextContent, getXml, hasChildNodes, hasEventHandlers, insertBefore, insertBeforeImpl, isSameNode, normalize, removeChild, removeEventListener, replaceChild, setDomNode, setEventHandler, setEventHandlerProp, setNodeValue, setTextContent
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, isReadOnlySettable, makeScriptableFor, setCaseSensitive, setDomNode, setHtmlElement
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Element

public Element()
Method Detail

selectNodes

public HTMLCollection selectNodes(String expression)
Applies the specified XPath expression to this node's context and returns the generated list of matching nodes.

Parameters:
expression - a string specifying an XPath expression
Returns:
list of the found elements

selectSingleNode

public Object selectSingleNode(String expression)
Applies the specified pattern-matching operation to this node's context and returns the first matching node.

Parameters:
expression - a string specifying an XPath expression
Returns:
the first node that matches the given pattern-matching operation If no nodes match the expression, returns a null value.

getTagName

public String getTagName()
Returns the tag name of this element.

Returns:
the tag name

getAttributes

public Object getAttributes()
Returns the attributes of this XML element.

Overrides:
getAttributes in class Node
Returns:
the attributes of this XML element
See Also:
Gecko DOM Reference

getBaseURI

public String getBaseURI()
Returns the Base URI as a string.

Returns:
the Base URI as a string

createAttributesObject

protected NamedNodeMap createAttributesObject()
Creates the JS object for the property attributes. This object will the be cached.

Returns:
the JS object

getAttribute

public Object getAttribute(String attributeName,
                           Integer flags)
Returns the value of the specified attribute.

Parameters:
attributeName - attribute name
flags - IE-specific flags (see the MSDN documentation for more info)
Returns:
the value of the specified attribute, null if the attribute is not defined
See Also:
MSDN Documentation, IE Bug Documentation

fixAttributeName

protected String fixAttributeName(String attributeName)
Allows subclasses to transform the attribute name before it gets used.

Parameters:
attributeName - the original attribute
Returns:
this implementation returns the original value

setAttribute

public void setAttribute(String name,
                         String value)
Sets an attribute.

Parameters:
name - Name of the attribute to set
value - Value to set the attribute to

getElementsByTagName

public Object getElementsByTagName(String tagName)
Returns all the descendant elements with the specified tag name.

Parameters:
tagName - the name to search for
Returns:
all the descendant elements with the specified tag name

getAttributeNode

public Object getAttributeNode(String name)
Retrieves an attribute node by name.

Parameters:
name - the name of the attribute to retrieve
Returns:
the XMLAttr node with the specified name or null if there is no such attribute

getText

public String getText()
Represents the text content of the node or the concatenated text representing the node and its descendants.

Returns:
the text content of the node or the concatenated text representing the node and its descendants

getElementsByTagNameNS

public Object getElementsByTagNameNS(Object namespaceURI,
                                     String localName)
Returns a list of elements with the given tag name belonging to the given namespace.

Parameters:
namespaceURI - the namespace URI of elements to look for
localName - is either the local name of elements to look for or the special value "*", which matches all elements.
Returns:
a live NodeList of found elements in the order they appear in the tree

hasAttribute

public boolean hasAttribute(String name)
Returns true when an attribute with a given name is specified on this element or has a default value. See also the DOM reference

Parameters:
name - the name of the attribute to look for
Returns:
true if an attribute with the given name is specified on this element or has a default value

getDomNodeOrDie

public DomElement getDomNodeOrDie()
Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.

Overrides:
getDomNodeOrDie in class SimpleScriptable
Returns:
the DOM node

removeAttribute

public void removeAttribute(String name)
Removes the specified attribute.

Parameters:
name - the name of the attribute to remove

getBoundingClientRect

public ClientRect getBoundingClientRect()
Retrieves an object that specifies the bounds of a collection of TextRectangle objects.

Returns:
an object that specifies the bounds of a collection of TextRectangle objects
See Also:
MSDN doc

getChildElementCount

public int getChildElementCount()
Returns the current number of child elements.

Returns:
the child element count

getFirstElementChild

public Element getFirstElementChild()
Returns the first element child.

Returns:
the first element child

getLastElementChild

public Element getLastElementChild()
Returns the last element child.

Returns:
the last element child

getNextElementSibling

public Element getNextElementSibling()
Returns the next element sibling.

Returns:
the next element sibling

getPreviousElementSibling

public Element getPreviousElementSibling()
Returns the previous element sibling.

Returns:
the previous element sibling

getParentElement

public Element getParentElement()
Gets the first ancestor instance of Element. It is mostly identical to Node.getParent() except that it skips non Element nodes.

Overrides:
getParentElement in class Node
Returns:
the parent element
See Also:
Node.getParent()

setDefaults

public void setDefaults(ComputedCSSStyleDeclaration style)
Callback method which allows different HTML element types to perform custom initialization of computed styles. For example, body elements in most browsers have default values for their margins.

Parameters:
style - the style to initialize

getChildren

public HTMLCollection getChildren()
Gets the children of the current node.

Returns:
the child at the given position
See Also:
MSDN documentation

getClassList

public DOMTokenList getClassList()
Gets the token list of class attribute.

Returns:
the token list of class attribute

getAttributeNS

public String getAttributeNS(String namespaceURI,
                             String localName)
Gets the specified attribute.

Parameters:
namespaceURI - the namespace URI
localName - the local name of the attribute to look for
Returns:
the value of the specified attribute, null if the attribute is not defined

hasAttributeNS

public boolean hasAttributeNS(String namespaceURI,
                              String localName)
Test for attribute. See also the DOM reference

Parameters:
namespaceURI - the namespace URI
localName - the local name of the attribute to look for
Returns:
true if the node has this attribute

setAttributeNS

public void setAttributeNS(String namespaceURI,
                           String qualifiedName,
                           String value)
Sets the specified attribute.

Parameters:
namespaceURI - the namespace URI
qualifiedName - the qualified name of the attribute to look for
value - the new attribute value

removeAttributeNS

public void removeAttributeNS(String namespaceURI,
                              String localName)
Removes the specified attribute.

Parameters:
namespaceURI - the namespace URI of the attribute to remove
localName - the local name of the attribute to remove


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