com.gargoylesoftware.htmlunit.javascript.host
Class Document

java.lang.Object
  extended by org.mozilla.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.NodeImpl
              extended by com.gargoylesoftware.htmlunit.javascript.host.Document
All Implemented Interfaces:
java.io.Serializable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Scriptable

public final class Document
extends NodeImpl

A JavaScript object for a Document.

Version:
$Revision: 1.3 $
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
See Also:
MSDN documentation, W3C Dom Level 1, Serialized Form

Field Summary
 
Fields inherited from class org.mozilla.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
Document()
 Create an instance.
 
Method Summary
 HtmlPage getHtmlPage()
 Return the html page that this document is modeling..
 HtmlPage getHtmlPageOrNull()
 Return the html page that this document is modeling or null if the page is empty.
 void jsConstructor()
 Javascript constructor.
 void jsxFunction_close()
 javascript function "close".
 Attribute jsxFunction_createAttribute(java.lang.String attributeName)
 Creates a new HTML attribute with the specified name.
 java.lang.Object jsxFunction_createDocumentFragment()
 Create a new DocumentFragment
 java.lang.Object jsxFunction_createElement(java.lang.String tagName)
 Create a new HTML element with the given tag name.
 java.lang.Object jsxFunction_createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
 Create a new HTML element with the given tag name, and name
 Event jsxFunction_createEvent(java.lang.String eventType)
 Implementation of the DocumentEvent interface's org.w3c.dom.events.DocumentEvent#createEvent(String) method.
 Event jsxFunction_createEventObject()
 Implementation of the createEventObject method supported by Internet Explorer.
 Stylesheet jsxFunction_createStyleSheet(java.lang.String url, int index)
 Creates a new Stylesheet.
 java.lang.Object jsxFunction_createTextNode(java.lang.String newData)
 Create a new DOM text node with the given data.
 java.lang.Object jsxFunction_getElementById(java.lang.String id)
 Return the element with the specified id or null if that element could not be found
 java.lang.Object jsxFunction_getElementsByName(java.lang.String elementName)
 Returns all HTML elements that have a "name" attribute with the given value.
 java.lang.Object jsxFunction_getElementsByTagName(java.lang.String tagName)
 Returns all the descendant elements with the specified tag name.
static java.lang.Object jsxFunction_open(org.mozilla.javascript.Context context, org.mozilla.javascript.Scriptable scriptable, java.lang.Object[] args, org.mozilla.javascript.Function function)
 javascript function "open".
static void jsxFunction_write(org.mozilla.javascript.Context context, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function function)
 javascript function "write" may accept a variable number of args.
static void jsxFunction_writeln(org.mozilla.javascript.Context context, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args, org.mozilla.javascript.Function function)
 javascript function "writeln" may accept a variable number of args.
 HTMLCollection jsxGet_all()
 Return the value of the "all" property.
 java.lang.Object jsxGet_anchors()
 Return the value of the javascript attribute "anchors".
 java.lang.Object jsxGet_body()
 Returns this document's body element.
 java.lang.String jsxGet_cookie()
 Return the cookie attribute.
 java.lang.Object jsxGet_defaultView()
 Get the window in which this document is contained.
 java.lang.Object jsxGet_documentElement()
 Get the JavaScript property "documentElement" for the document.
 java.lang.String jsxGet_domain()
 The domain name of the server that served the document, or null if the server cannot be identified by a domain name.
 java.lang.Object jsxGet_forms()
 Return the value of the javascript attribute "forms".
 java.lang.Object jsxGet_frames()
 Return the value of the frames property.
 java.lang.Object jsxGet_images()
 Return the value of the "images" property.
 DOMImplementation jsxGet_implementation()
 Returns the implementation object of the current document.
 java.lang.Object jsxGet_links()
 Return the value of the javascript attribute "links".
 Location jsxGet_location()
 Return the value of the "location" property.
 java.lang.Object jsxGet_parentWindow()
 Get the window in which this document is contained.
 java.lang.String jsxGet_readyState()
 Returns the ready state of the document.
 java.lang.String jsxGet_referrer()
 Return the value of the "referrer" property.
 java.lang.Object jsxGet_scripts()
 Return the value of the javascript attribute "scripts".
 java.lang.String jsxGet_title()
 Returns this document's title.
 java.lang.String jsxGet_URL()
 Return the value of the "URL" property.
 void jsxSet_cookie(java.lang.String newCookie)
 Adds a cookie
 void jsxSet_domain(java.lang.String newDomain)
 Set the the domain of this document.
 void jsxSet_location(java.lang.String location)
 Sets the value of the "location" property.
 void jsxSet_title(java.lang.String title)
 Sets this document's title.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.host.NodeImpl
executeEvent, fireEvent, getEventHandler, jsxFunction_addEventListener, jsxFunction_appendChild, jsxFunction_attachEvent, jsxFunction_cloneNode, jsxFunction_detachEvent, jsxFunction_hasChildNodes, jsxFunction_insertBefore, jsxFunction_isSameNode, jsxFunction_removeChild, jsxFunction_removeEventListener, jsxFunction_replaceChild, jsxGet_childNodes, jsxGet_firstChild, jsxGet_lastChild, jsxGet_nextSibling, jsxGet_nodeName, jsxGet_nodeType, jsxGet_nodeValue, jsxGet_parentNode, jsxGet_previousSibling, jsxSet_nodeValue, setEventHandler
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
get, getBooleanArg, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getHtmlElementOrDie, getHtmlElementOrNull, getIntArg, getObjectArg, getStringArg, makeScriptableFor, setDomNode, setHtmlElement
 
Methods inherited from class org.mozilla.javascript.ScriptableObject
associateValue, avoidObjectDetection, callMethod, callMethod, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, get, getAllIds, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, has, has, hasInstance, hasProperty, hasProperty, isConst, isSealed, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Document

public Document()
Create an instance. Javascript objects must have a default constructor.

Method Detail

getHtmlPage

public HtmlPage getHtmlPage()
Return the html page that this document is modeling..

Returns:
The page.

getHtmlPageOrNull

public HtmlPage getHtmlPageOrNull()
Return the html page that this document is modeling or null if the page is empty.

Returns:
The page.

jsConstructor

public void jsConstructor()
Javascript constructor. This must be declared in every javascript file because the rhino engine won't walk up the hierarchy looking for constructors.


jsxFunction_close

public void jsxFunction_close()
                       throws java.io.IOException
javascript function "close".

Throws:
java.io.IOException - If an IO problem occurs.

jsxFunction_createAttribute

public Attribute jsxFunction_createAttribute(java.lang.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.

jsxFunction_createDocumentFragment

public java.lang.Object jsxFunction_createDocumentFragment()
Create a new DocumentFragment

Returns:
a newly created DocumentFragment.

jsxFunction_createElement

public java.lang.Object jsxFunction_createElement(java.lang.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.

jsxFunction_createElementNS

public java.lang.Object jsxFunction_createElementNS(java.lang.String namespaceURI,
                                                    java.lang.String qualifiedName)
Create 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.

jsxFunction_createEvent

public Event jsxFunction_createEvent(java.lang.String eventType)
                              throws org.w3c.dom.DOMException
Implementation of the DocumentEvent interface's org.w3c.dom.events.DocumentEvent#createEvent(String) method. The method creates an event of the specified type.

Parameters:
eventType - The event type to create.
Returns:
The associated event object for that type. The event object will NOT have had its initialization method called. It is up to the caller of the method to initialize the event.
Throws:
org.w3c.dom.DOMException - Thrown if the event type is not supported. The DOMException will have a type of DOMException.NOT_SUPPORTED_ERR

jsxFunction_createEventObject

public Event jsxFunction_createEventObject()
Implementation of the createEventObject method supported by Internet Explorer.

Returns:
An instance of the event object. The event object will NOT have its member variables initialized. It is up to the caller of the method to initialize the properties of the event.

jsxFunction_createStyleSheet

public Stylesheet jsxFunction_createStyleSheet(java.lang.String url,
                                               int index)
Creates a new Stylesheet. Current implementation just creates an empty Stylesheet object.

Parameters:
url - the stylesheet url
index - where to insert the sheet in the collection
Returns:
the newly created stylesheet

jsxFunction_createTextNode

public java.lang.Object jsxFunction_createTextNode(java.lang.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.

jsxFunction_getElementById

public java.lang.Object jsxFunction_getElementById(java.lang.String id)
Return the element with the specified id or null if that element could not be found

Parameters:
id - The ID to search for
Returns:
the element or null

jsxFunction_getElementsByName

public java.lang.Object jsxFunction_getElementsByName(java.lang.String elementName)
Returns all HTML elements that have a "name" attribute with the given value. Refer to The DOM spec for details.

Parameters:
elementName - - value of the "name" attribute to look for
Returns:
NodeList of elements

jsxFunction_getElementsByTagName

public java.lang.Object jsxFunction_getElementsByTagName(java.lang.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

jsxFunction_open

public static java.lang.Object jsxFunction_open(org.mozilla.javascript.Context context,
                                                org.mozilla.javascript.Scriptable scriptable,
                                                java.lang.Object[] args,
                                                org.mozilla.javascript.Function function)
javascript function "open".

Parameters:
context - The javascript context
scriptable - The scriptable
args - The arguments passed into the method.
function - The function.
Returns:
Nothing
See Also:
MSDN documentation

jsxFunction_write

public static void jsxFunction_write(org.mozilla.javascript.Context context,
                                     org.mozilla.javascript.Scriptable thisObj,
                                     java.lang.Object[] args,
                                     org.mozilla.javascript.Function function)
javascript function "write" may accept a variable number of args. It's not documented by W3C, Mozilla or MSDN but works with Mozilla and IE.

Parameters:
context - The javascript context
thisObj - The scriptable
args - The arguments passed into the method.
function - The function.
See Also:
MSDN documentation

jsxFunction_writeln

public static void jsxFunction_writeln(org.mozilla.javascript.Context context,
                                       org.mozilla.javascript.Scriptable thisObj,
                                       java.lang.Object[] args,
                                       org.mozilla.javascript.Function function)
javascript function "writeln" may accept a variable number of args. It's not documented by W3C, Mozilla or MSDN but works with Mozilla and IE.

Parameters:
context - The javascript context
thisObj - The scriptable
args - The arguments passed into the method.
function - The function.
See Also:
MSDN documentation

jsxGet_all

public HTMLCollection jsxGet_all()
Return the value of the "all" property.

Returns:
The value of the "all" property

jsxGet_anchors

public java.lang.Object jsxGet_anchors()
Return the value of the javascript attribute "anchors".

Returns:
The value of this attribute.
See Also:
MSDN documentation, Gecko DOM reference

jsxGet_body

public java.lang.Object jsxGet_body()
Returns this document's body element.

Returns:
this document's body element

jsxGet_cookie

public java.lang.String jsxGet_cookie()
Return the cookie attribute.

Returns:
The cookie attribute

jsxGet_defaultView

public java.lang.Object jsxGet_defaultView()
Get the window in which this document is contained.

Returns:
the window

jsxGet_documentElement

public java.lang.Object jsxGet_documentElement()
Get the JavaScript property "documentElement" for the document.

Returns:
The root node for the document.

jsxGet_domain

public java.lang.String jsxGet_domain()
The domain name of the server that served the document, or null if the server cannot be identified by a domain name.

Returns:
domain name
See Also:
W3C documentation

jsxGet_forms

public java.lang.Object jsxGet_forms()
Return the value of the javascript attribute "forms".

Returns:
The value of this attribute.

jsxGet_frames

public java.lang.Object jsxGet_frames()
Return the value of the frames property.

Returns:
The live collection of frames
See Also:
MSDN documentation

jsxGet_images

public java.lang.Object jsxGet_images()
Return the value of the "images" property.

Returns:
The value of the "images" property

jsxGet_implementation

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

Returns:
implementation-specific object.

jsxGet_links

public java.lang.Object jsxGet_links()
Return the value of the javascript attribute "links". Refer also to the

Returns:
The value of this attribute.

jsxGet_location

public Location jsxGet_location()
Return the value of the "location" property.

Returns:
The value of the "location" property

jsxGet_parentWindow

public java.lang.Object jsxGet_parentWindow()
Get the window in which this document is contained.

Returns:
the window

jsxGet_readyState

public java.lang.String jsxGet_readyState()
Returns the ready state of the document. This is an IE-only property.

Returns:
The ready state of the document.
See Also:
DomNode.READY_STATE_UNINITIALIZED, DomNode.READY_STATE_LOADING, DomNode.READY_STATE_LOADED, DomNode.READY_STATE_INTERACTIVE, DomNode.READY_STATE_COMPLETE

jsxGet_referrer

public java.lang.String jsxGet_referrer()
Return the value of the "referrer" property.

Returns:
The value of the "referrer" property

jsxGet_scripts

public java.lang.Object jsxGet_scripts()
Return the value of the javascript attribute "scripts".

Returns:
The value of this attribute.

jsxGet_title

public java.lang.String jsxGet_title()
Returns this document's title.

Returns:
this document's title

jsxGet_URL

public java.lang.String jsxGet_URL()
Return the value of the "URL" property.

Returns:
The value of the "URL" property

jsxSet_cookie

public void jsxSet_cookie(java.lang.String newCookie)
Adds a cookie

Parameters:
newCookie - in the format "name=value[;expires=date][;domain=domainname][;path=path][;secure]
See Also:
MSDN documentation

jsxSet_domain

public void jsxSet_domain(java.lang.String newDomain)
Set the the domain of this document. Domains can only be set to suffixes of the existing domain with the exception of setting the domain to itself.

The domain will be set according to the following rules:

  1. If the newDomain.equalsIgnoreCase(currentDomain) the method returns with no error.
  2. If the browser version is netscape, the newDomain is downshifted.
  3. The change will take place if and only if the suffixes of the current domain and the new domain match AND there are at least two domain qualifiers e.g. the following transformations are legal d1.d2.d3.gargoylesoftware.com may be transformed to itself or: d2.d3.gargoylesoftware.com d3.gargoylesoftware.com gargoylesoftware.com tranformation to: com will fail

TODO This code could be modified to understand country domain suffixes. The domain www.bbc.co.uk should be trimmable only down to bbc.co.uk trimming to co.uk should not be possible.

Parameters:
newDomain - the new domain to set

jsxSet_location

public void jsxSet_location(java.lang.String location)
                     throws java.io.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:
java.io.IOException - when location loading fails
See Also:
MSDN documentation

jsxSet_title

public void jsxSet_title(java.lang.String title)
Sets this document's title.

Parameters:
title - the new title


Copyright © 2003-2016 AppPerfect Corporation. All Rights Reserved.