com.gargoylesoftware.htmlunit.javascript.host
Class Document

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.Document
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:
HTMLDocument, XMLDocument

public class Document
extends EventNode

A JavaScript object for a Document.

Version:
$Revision: 8397 $
Author:
Mike Bowler, David K. Taylor, Chen Jun, Christian Sell, Chris Erskine, Marc Guillemot, Daniel Gredler, Michael Ottati, George Murnock, Ahmed Ashour, Rob Di Marco, Ronald Brill, Chuck Dumont
See Also:
MSDN documentation, W3C Dom Level 1, 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
Document()
           
 
Method Summary
 void captureEvents(String type)
          Does nothing special anymore...
 Attr createAttribute(String attributeName)
          Creates a new HTML attribute with the specified name.
 Object createComment(String comment)
          Creates a new Comment.
 Object createDocumentFragment()
          Creates a new document fragment.
 Object createElement(String tagName)
          Create a new HTML element with the given tag name.
 Object createElementNS(String namespaceURI, String qualifiedName)
          Creates a new HTML element with the given tag name, and name.
 XPathNSResolver createNSResolver(Node nodeResolver)
          Adapts any DOM node to resolve namespaces so that an XPath expression can be easily evaluated relative to the context of the node where it appeared within the document.
 Object createTextNode(String newData)
          Create a new DOM text node with the given data.
 XPathResult evaluate(String expression, Node contextNode, Object resolver, int type, Object result)
          Evaluates an XPath expression string and returns a result of the specified type if possible.
 BoxObject getBoxObjectFor(HTMLElement element)
          Returns the BoxObject for the specific element.
 Object getDefaultView()
          Gets the window in which this document is contained.
 String getDesignMode()
          Returns a value which indicates whether or not the document can be edited.
 SimpleScriptable getDoctype()
          Gets the JavaScript property "doctype" for the document.
 Element getDocumentElement()
          Gets the JavaScript property "documentElement" for the document.
 HTMLCollection 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.
 DOMImplementation getImplementation()
          Returns the implementation object of the current document.
 Location getLocation()
          Returns the value of the "location" property.
protected  SgmlPage getPage()
          Returns the page that this document is modeling.
 String getReferrer()
          Returns the value of the "referrer" property.
 Object importNode(Node importedNode, boolean deep)
          Imports a node from another document to this document.
 void setDesignMode(String mode)
          Sets a value which indicates whether or not the document can be edited.
 void setLocation(String location)
          Sets the value of the "location" property.
 void setWindow(Window window)
          Sets the Window JavaScript object that encloses this document.
 
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, contains, detachEvent, executeEvent, fireEvent, fireEvent, getAttributes, getBaseName, getChildNodes, getEventHandler, getEventHandlerProp, getFirstChild, getJavaScriptNode, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParent, getParentElement, 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, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, isReadOnlySettable, makeScriptableFor, setCaseSensitive, setDomNode, setHtmlElement, setParentScope
 
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, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Document

public Document()
Method Detail

setWindow

public void setWindow(Window window)
Sets the Window JavaScript object that encloses this document.

Parameters:
window - the Window JavaScript object that encloses this document

getLocation

public Location getLocation()
Returns the value of the "location" property.

Returns:
the value of the "location" property

setLocation

public void setLocation(String location)
                 throws IOException
Sets the value of the "location" property. The location's default property is "href", so setting "document.location='http://www.sf.net'" is equivalent to setting "document.location.href='http://www.sf.net'".

Parameters:
location - the location to navigate to
Throws:
IOException - when location loading fails
See Also:
MSDN documentation

getReferrer

public String getReferrer()
Returns the value of the "referrer" property.

Returns:
the value of the "referrer" property

getDocumentElement

public Element getDocumentElement()
Gets the JavaScript property "documentElement" for the document.

Returns:
the root node for the document

getDoctype

public SimpleScriptable getDoctype()
Gets the JavaScript property "doctype" for the document.

Returns:
the DocumentType of the document

getDesignMode

public String getDesignMode()
Returns a value which indicates whether or not the document can be edited.

Returns:
a value which indicates whether or not the document can be edited

setDesignMode

public void setDesignMode(String mode)
Sets a value which indicates whether or not the document can be edited.

Parameters:
mode - a value which indicates whether or not the document can be edited

getPage

protected SgmlPage getPage()
Returns the page that this document is modeling.

Returns:
the page that this document is modeling

getDefaultView

public Object getDefaultView()
Gets the window in which this document is contained.

Returns:
the window

createDocumentFragment

public Object createDocumentFragment()
Creates a new document fragment.

Returns:
a newly created document fragment

createAttribute

public Attr createAttribute(String attributeName)
Creates a new HTML attribute with the specified name.

Parameters:
attributeName - the name of the attribute to create
Returns:
an attribute with the specified name

getBoxObjectFor

public BoxObject getBoxObjectFor(HTMLElement element)
Returns the BoxObject for the specific element.

Parameters:
element - target for BoxObject
Returns:
the BoxObject

importNode

public Object importNode(Node importedNode,
                         boolean deep)
Imports a node from another document to this document. The source node is not altered or removed from the original document; this method creates a new copy of the source node.

Parameters:
importedNode - the node to import
deep - Whether to recursively import the subtree under the specified node; or not
Returns:
the imported node that belongs to this Document

getImplementation

public DOMImplementation getImplementation()
Returns the implementation object of the current document.

Returns:
implementation-specific object

captureEvents

public void captureEvents(String type)
Does nothing special anymore... just like FF.

Parameters:
type - the type of events to capture
See Also:
Window.captureEvents(String)

createNSResolver

public XPathNSResolver createNSResolver(Node nodeResolver)
Adapts any DOM node to resolve namespaces so that an XPath expression can be easily evaluated relative to the context of the node where it appeared within the document.

Parameters:
nodeResolver - the node to be used as a context for namespace resolution
Returns:
an XPathNSResolver which resolves namespaces with respect to the definitions in scope for a specified node

createTextNode

public Object createTextNode(String newData)
Create a new DOM text node with the given data.

Parameters:
newData - the string value for the text node
Returns:
the new text node or NOT_FOUND if there is an error

createComment

public Object createComment(String comment)
Creates a new Comment.

Parameters:
comment - the comment text
Returns:
the new Comment

evaluate

public XPathResult evaluate(String expression,
                            Node contextNode,
                            Object resolver,
                            int type,
                            Object result)
Evaluates an XPath expression string and returns a result of the specified type if possible.

Parameters:
expression - the XPath expression string to be parsed and evaluated
contextNode - the context node for the evaluation of this XPath expression
resolver - the resolver permits translation of all prefixes, including the XML namespace prefix, within the XPath expression into appropriate namespace URIs.
type - If a specific type is specified, then the result will be returned as the corresponding type
result - the result object which may be reused and returned by this method
Returns:
the result of the evaluation of the XPath expression

createElement

public Object createElement(String tagName)
Create a new HTML element with the given tag name.

Parameters:
tagName - the tag name
Returns:
the new HTML element, or NOT_FOUND if the tag is not supported

createElementNS

public Object createElementNS(String namespaceURI,
                              String qualifiedName)
Creates a new HTML element with the given tag name, and name.

Parameters:
namespaceURI - the URI that identifies an XML namespace
qualifiedName - the qualified name of the element type to instantiate
Returns:
the new HTML element, or NOT_FOUND if the tag is not supported

getElementsByTagName

public HTMLCollection 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

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


Copyright © 2002–2013 Gargoyle Software Inc.. All rights reserved.