com.gargoylesoftware.htmlunit.html
Class HtmlScript

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.html.DomNode
      extended by com.gargoylesoftware.htmlunit.html.DomNamespaceNode
          extended by com.gargoylesoftware.htmlunit.html.DomElement
              extended by com.gargoylesoftware.htmlunit.html.HtmlElement
                  extended by com.gargoylesoftware.htmlunit.html.HtmlScript
All Implemented Interfaces:
Serializable, Cloneable, Element, Node

public class HtmlScript
extends HtmlElement

Wrapper for the HTML element "script".
When a script tag references an external script (with attribute src) it gets executed when the node is added to the DOM tree. When the script code is nested, it gets executed when the text node containing the script is added to the HtmlScript.
The ScriptFilter feature of NekoHtml can't be used because it doesn't allow immediate access to the DOM (i.e. document.write("<span id='mySpan'/>"); document.getElementById("mySpan").tagName; can't work with a filter).

Version:
$Revision: 5876 $
Author:
Mike Bowler, Christian Sell, Marc Guillemot, David K. Taylor, Ahmed Ashour, Daniel Gredler, Dmitri Zoubkov, Sudhan Moghe
See Also:
DOM Level 1, DOM Level 2, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.gargoylesoftware.htmlunit.html.HtmlElement
HtmlElement.ChildElementsIterator
 
Nested classes/interfaces inherited from class com.gargoylesoftware.htmlunit.html.DomNode
DomNode.ChildIterator, DomNode.DescendantElementsIterator<T extends DomNode>
 
Field Summary
static String TAG_NAME
          The HTML tag represented by this element.
 
Fields inherited from class com.gargoylesoftware.htmlunit.html.HtmlElement
TAB_INDEX_OUT_OF_BOUNDS
 
Fields inherited from class com.gargoylesoftware.htmlunit.html.DomElement
ATTRIBUTE_NOT_DEFINED, ATTRIBUTE_VALUE_EMPTY
 
Fields inherited from class com.gargoylesoftware.htmlunit.html.DomNode
AS_TEXT_BLANK, AS_TEXT_BLOCK_SEPARATOR, AS_TEXT_NEW_LINE, AS_TEXT_TAB, PROPERTY_ELEMENT, READY_STATE_COMPLETE, READY_STATE_INTERACTIVE, READY_STATE_LOADED, READY_STATE_LOADING, READY_STATE_UNINITIALIZED
 
Fields inherited from interface org.w3c.dom.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
 
Method Summary
 String asText()
          Returns a textual representation of this element that represents what would be visible to the user if this page was shown in a web browser.
 String getCharsetAttribute()
          Returns the value of the attribute "charset".
 String getDeferAttribute()
          Returns the value of the attribute "defer".
 String getEventAttribute()
          Returns the value of the attribute "event".
 String getHtmlForAttribute()
          Returns the value of the attribute "for".
 String getLanguageAttribute()
          Returns the value of the attribute "language".
 String getSrcAttribute()
          Returns the value of the attribute "src".
 String getTypeAttribute()
          Returns the value of the attribute "type".
protected  boolean isDeferred()
          Returns true if this script is deferred.
protected  boolean isEmptyXmlTagExpanded()
          Indicates if a node without children should be written in expanded form as XML (i.e.
 boolean mayBeDisplayed()
          Returns true if nodes of this type can ever be displayed, false otherwise.
protected  void onAllChildrenAddedToPage(boolean postponed)
          Executes the onreadystatechange handler when simulating IE, as well as executing the script itself, if necessary.
protected  void printChildrenAsXml(String indent, PrintWriter printWriter)
          Recursively writes the XML data for the node tree starting at node.
protected  void setAndExecuteReadyState(String state)
          Sets the readyState to the specified state and executes the onreadystatechange handler when simulating IE.
 void setAttributeNS(String namespaceURI, String qualifiedName, String attributeValue)
          If setting the src attribute, this method executes the new JavaScript if necessary (behavior varies by browser version).
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.HtmlElement
addHtmlAttributeChangeListener, appendChildIfNoneExists, blur, checkChildHierarchy, click, click, click, dblClick, dblClick, doClickAction, doType, fireEvent, fireEvent, fireHtmlAttributeAdded, fireHtmlAttributeRemoved, fireHtmlAttributeReplaced, focus, getCanonicalXPath, getChildElements, getElementById, getElementsByAttribute, getEnclosingElement, getEnclosingForm, getEnclosingFormOrDie, getEventTargetElement, getHtmlElementsByTagName, getHtmlElementsByTagNames, getId, getLangAttribute, getNodeName, getOnClickAttribute, getOnDblClickAttribute, getOneHtmlElementByAttribute, getOnKeyDownAttribute, getOnKeyPressAttribute, getOnKeyUpAttribute, getOnMouseDownAttribute, getOnMouseMoveAttribute, getOnMouseOutAttribute, getOnMouseOverAttribute, getOnMouseUpAttribute, getTabIndex, getTextDirectionAttribute, getXmlLangAttribute, hasEventHandlers, hasHtmlElementWithId, isAttributeCaseSensitive, isStateUpdateFirst, isSubmittableByEnter, mouseDown, mouseDown, mouseMove, mouseMove, mouseOut, mouseOut, mouseOver, mouseOver, mouseUp, mouseUp, preventDefault, removeAttribute, removeChild, removeEventHandler, removeHtmlAttributeChangeListener, rightClick, rightClick, setEventHandler, setEventHandler, setId, toString, type, type, type, type
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomElement
cloneNode, getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getAttributesMap, getElementsByTagName, getElementsByTagNameNS, getNodeType, getSchemaTypeInfo, getTagName, hasAttribute, hasAttributeNS, hasAttributes, namespaces, printOpeningTagContentAsXml, printXml, removeAttributeNode, removeAttributeNS, setAttribute, setAttributeNode, setAttributeNodeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomNamespaceNode
getLocalName, getNamespaceURI, getPrefix, getQualifiedName, setPrefix
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomNode
addDomChangeListener, appendChild, asXml, compareDocumentPosition, fireNodeAdded, fireNodeDeleted, getAllHtmlChildElements, getAncestors, getBaseURI, getByXPath, getChildNodes, getChildren, getDescendants, getEndColumnNumber, getEndLineNumber, getFeature, getFirstByXPath, getFirstChild, getHtmlElementDescendants, getIndex, getLastChild, getNextSibling, getNodeValue, getOwnerDocument, getPage, getParentNode, getPreviousSibling, getReadyState, getScriptObject, getStartColumnNumber, getStartLineNumber, getTextContent, getUserData, hasChildNodes, insertBefore, insertBefore, isAncestorOf, isAncestorOfAny, isBlock, isDefaultNamespace, isDisplayed, isEqualNode, isSameNode, isSupported, isTrimmedText, lookupNamespaceURI, lookupPrefix, normalize, notifyIncorrectness, onAddedToPage, remove, removeAllChildren, removeChild, removeDomChangeListener, replace, replaceChild, setNextSibling, setNodeValue, setParentNode, setPreviousSibling, setReadyState, setScriptObject, setTextContent, setUserData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Node
appendChild, compareDocumentPosition, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
 

Field Detail

TAG_NAME

public static final String TAG_NAME
The HTML tag represented by this element.

See Also:
Constant Field Values
Method Detail

getCharsetAttribute

public final String getCharsetAttribute()
Returns the value of the attribute "charset". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "charset" or an empty string if that attribute isn't defined.

getTypeAttribute

public final String getTypeAttribute()
Returns the value of the attribute "type". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "type" or an empty string if that attribute isn't defined.

getLanguageAttribute

public final String getLanguageAttribute()
Returns the value of the attribute "language". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "language" or an empty string if that attribute isn't defined.

getSrcAttribute

public final String getSrcAttribute()
Returns the value of the attribute "src". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "src" or an empty string if that attribute isn't defined.

getEventAttribute

public final String getEventAttribute()
Returns the value of the attribute "event".

Returns:
the value of the attribute "event"

getHtmlForAttribute

public final String getHtmlForAttribute()
Returns the value of the attribute "for".

Returns:
the value of the attribute "for"

getDeferAttribute

public final String getDeferAttribute()
Returns the value of the attribute "defer". Refer to the HTML 4.01 documentation for details on the use of this attribute.

Returns:
the value of the attribute "defer" or an empty string if that attribute isn't defined.

isDeferred

protected boolean isDeferred()
Returns true if this script is deferred.

Returns:
true if this script is deferred

mayBeDisplayed

public boolean mayBeDisplayed()
Returns true if nodes of this type can ever be displayed, false otherwise. Examples of nodes that can never be displayed are <head>, <meta>, <script>, etc.

Overrides:
mayBeDisplayed in class DomNode
Returns:
true if nodes of this type can ever be displayed, false otherwise
See Also:
DomNode.isDisplayed()

setAttributeNS

public void setAttributeNS(String namespaceURI,
                           String qualifiedName,
                           String attributeValue)
If setting the src attribute, this method executes the new JavaScript if necessary (behavior varies by browser version). Sets the value of the specified attribute. This method may be overridden by subclasses which are interested in specific attribute value changes, but such methods must invoke super.setAttributeValue(), and should consider the value of the cloning parameter when deciding whether or not to execute custom logic.

Specified by:
setAttributeNS in interface Element
Overrides:
setAttributeNS in class HtmlElement
Parameters:
namespaceURI - the URI that identifies an XML namespace
qualifiedName - the qualified name of the attribute
attributeValue - the value of the attribute

onAllChildrenAddedToPage

protected void onAllChildrenAddedToPage(boolean postponed)
Executes the onreadystatechange handler when simulating IE, as well as executing the script itself, if necessary. Lifecycle method invoked after a node and all its children have been added to a page, during parsing of the HTML. Intended to be overridden by nodes which need to perform custom logic after they and all their child nodes have been processed by the HTML parser. This method is not recursive, and the default implementation is empty, so there is no need to call super.onAllChildrenAddedToPage() if you implement this method.

Overrides:
onAllChildrenAddedToPage in class DomNode
Parameters:
postponed - whether to use PostponedAction or no

setAndExecuteReadyState

protected void setAndExecuteReadyState(String state)
Sets the readyState to the specified state and executes the onreadystatechange handler when simulating IE.

Parameters:
state - this script ready state

asText

public String asText()
Description copied from class: DomNode
Returns a textual representation of this element that represents what would be visible to the user if this page was shown in a web browser. For example, a single-selection select element would return the currently selected value as text.

Overrides:
asText in class DomNode
Returns:
an empty string as the content of script is not visible by itself
See Also:
DomNode.asText()

isEmptyXmlTagExpanded

protected boolean isEmptyXmlTagExpanded()
Indicates if a node without children should be written in expanded form as XML (i.e. with closing tag rather than with "/>")

Overrides:
isEmptyXmlTagExpanded in class DomElement
Returns:
true to make generated XML readable as HTML

printChildrenAsXml

protected void printChildrenAsXml(String indent,
                                  PrintWriter printWriter)
Recursively writes the XML data for the node tree starting at node.

Overrides:
printChildrenAsXml in class DomNode
Parameters:
indent - white space to indent child nodes
printWriter - writer where child nodes are written


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