Class HTMLDocument
- java.lang.Object
-
- org.htmlunit.corejs.javascript.ScriptableObject
-
- org.htmlunit.javascript.HtmlUnitScriptable
-
- org.htmlunit.javascript.host.event.EventTarget
-
- org.htmlunit.javascript.host.dom.Node
-
- org.htmlunit.javascript.host.dom.Document
-
- org.htmlunit.javascript.host.html.HTMLDocument
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,org.htmlunit.corejs.javascript.ConstProperties
,org.htmlunit.corejs.javascript.debug.DebuggableObject
,org.htmlunit.corejs.javascript.Scriptable
,org.htmlunit.corejs.javascript.SymbolScriptable
public class HTMLDocument extends Document
A JavaScript object forHTMLDocument
.- See Also:
- MSDN documentation, W3C DOM Level 1, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
HTMLDocument.ParsingStatus
-
Field Summary
Fields Modifier and Type Field Description private boolean
closePostponedAction_
private boolean
executionExternalPostponed_
private static org.apache.commons.logging.Log
LOG
private java.lang.StringBuilder
writeBuilder_
The buffer that will be used for calls to document.write().private boolean
writeInCurrentDocument_
-
Fields inherited from class org.htmlunit.javascript.host.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
-
-
Constructor Summary
Constructors Constructor Description HTMLDocument()
The constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
appendChild(java.lang.Object childObject)
Adds a DOM node to the node.(package private) static boolean
canAlreadyBeParsed(java.lang.String content)
Indicates if the content is a well formed HTML snippet that can already be parsed to be added to the DOM.void
close()
JavaScript functionclose
.private static java.lang.String
concatArgsAsString(java.lang.Object[] args)
Converts the arguments to strings and concatenate them.Attr
createAttribute(java.lang.String attributeName)
Creates a new HTML attribute with the specified name.boolean
dispatchEvent(Event event)
Dispatches an event into the event system (standards-conformant browsers only).HtmlUnitScriptable
elementFromPoint(int x, int y)
Returns the element for the specified x coordinate and the specified y coordinate.HTMLElement
getActiveElement()
Returns the value of theactiveElement
property.java.lang.String
getBaseURI()
Returns the Base URI as a string.java.lang.String
getCookie()
Returns thecookie
property.private static HTMLDocument
getDocument(org.htmlunit.corejs.javascript.Scriptable thisObj)
Returns the current document instance, usingthisObj
as a hint.Element
getDocumentElement()
Gets the JavaScript propertydocumentElement
for the document.DomNode
getDomNodeOrDie()
Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.HtmlUnitScriptable
getElementById(java.lang.String id)
Returns the element with the specified ID, ornull
if that element could not be found.HTMLCollection
getElementsByClassName(java.lang.String className)
Returns all the descendant elements with the specified class name.NodeList
getElementsByName(java.lang.String elementName)
Returns all HTML elements that have aname
attribute with the specified value.HTMLElement
getHead()
Returns this document'shead
element.private java.lang.Object
getIt(java.lang.String name)
(package private) static java.util.List<DomNode>
getItComputeElements(HtmlPage page, java.lang.String name, boolean alsoFrames)
(package private) HtmlElement
getLastHtmlElement(HtmlElement node)
Gets the node that is the last one when exploring following nodes, depth-first.HtmlPage
getPage()
Returns the HTML page that this document is modeling.Selection
getSelection()
Returns the current selection.java.lang.String
getTitle()
Returns this document's title.protected java.lang.Object
getWithPreemption(java.lang.String name)
Calls todocument.XYZ
should first look at elements namedXYZ
before using standard functions.boolean
hasFocus()
Returnsfalse
if the active element in the document has no focus;true
if the active element in the document has focus.private void
implicitCloseIfNecessary()
Closes the document implicitly, i.e.void
jsConstructor()
JavaScript constructor.java.lang.Object
open(java.lang.Object url, java.lang.Object name, java.lang.Object features, java.lang.Object replace)
JavaScript function "open".private void
scheduleImplicitClose()
void
setCookie(java.lang.String newCookie)
Adds a cookie, as long as cookies are enabled.void
setExecutingDynamicExternalPosponed(boolean executing)
This a hack!!! A cleaner way is welcome.void
setTitle(java.lang.String title)
Sets this document's title.protected void
write(java.lang.String content)
JavaScript function "write".static void
write(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)
JavaScript function "write" may accept a variable number of arguments.static void
writeln(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)
JavaScript function "writeln" may accept a variable number of arguments.-
Methods inherited from class org.htmlunit.javascript.host.dom.Document
adoptNode, captureEvents, clear, contains, createCDATASection, createComment, createDocumentFragment, createElement, createElementNS, createEvent, createNodeIterator, createNSResolver, createProcessingInstruction, createRange, createTextNode, createTreeWalker, evaluate, execCommand, forceDocumentMode, generateBlobUrl, getAlinkColor, getAll, getAnchors, getApplets, getBgColor, getBody, getCharacterSet, getCharset, getChildElementCount, getChildren, getCompatMode, getContentType, getCurrentScript, getDefaultView, getDesignMode, getDoctype, getDocumentMode, getDocumentURI, getDomain, getElementsByTagName, getElementsByTagNameNS, getEmbeds, getFgColor, getFirstElementChild, getFonts, getForms, getHidden, getImages, getImplementation, getInputEncoding, getLastElementChild, getLastModified, getLinkColor, getLinks, getLocation, getOnabort, getOnafterscriptexecute, getOnauxclick, getOnbeforecopy, getOnbeforecut, getOnbeforepaste, getOnbeforescriptexecute, getOnblur, getOncancel, getOncanplay, getOncanplaythrough, getOnchange, getOnclick, getOnclose, getOncontextmenu, getOncopy, getOncuechange, getOncut, getOndblclick, getOndrag, getOndragend, getOndragenter, getOndragleave, getOndragover, getOndragstart, getOndrop, getOndurationchange, getOnemptied, getOnended, getOnerror, getOnfocus, getOngotpointercapture, getOninput, getOninvalid, getOnkeydown, getOnkeypress, getOnkeyup, getOnload, getOnloadeddata, getOnloadedmetadata, getOnloadstart, getOnlostpointercapture, getOnmousedown, getOnmouseenter, getOnmouseleave, getOnmousemove, getOnmouseout, getOnmouseover, getOnmouseup, getOnmousewheel, getOnmozfullscreenchange, getOnmozfullscreenerror, getOnpaste, getOnpause, getOnplay, getOnplaying, getOnpointercancel, getOnpointerdown, getOnpointerenter, getOnpointerleave, getOnpointerlockchange, getOnpointerlockerror, getOnpointermove, getOnpointerout, getOnpointerover, getOnpointerup, getOnprogress, getOnratechange, getOnreadystatechange, getOnreset, getOnresize, getOnscroll, getOnsearch, getOnseeked, getOnseeking, getOnselect, getOnselectionchange, getOnselectstart, getOnstalled, getOnsubmit, getOnsuspend, getOntimeupdate, getOntoggle, getOnvolumechange, getOnwaiting, getOnwebkitfullscreenchange, getOnwebkitfullscreenerror, getOnwheel, getPlugins, getReadyState, getReferrer, getRootElement, getScripts, getStyleSheets, getURL_js, getVlinkColor, getXmlEncoding, getXmlVersion, importNode, isXmlStandalone, queryCommandEnabled, queryCommandSupported, querySelector, querySelectorAll, releaseCapture, releaseEvents, resolveBlobUrl, revokeBlobUrl, setAlinkColor, setBgColor, setBody, setCurrentScript, setDesignMode, setDomain, setFgColor, setLinkColor, setLocation, setOnabort, setOnafterscriptexecute, setOnauxclick, setOnbeforecopy, setOnbeforecut, setOnbeforepaste, setOnbeforescriptexecute, setOnblur, setOncancel, setOncanplay, setOncanplaythrough, setOnchange, setOnclick, setOnclose, setOncontextmenu, setOncopy, setOncuechange, setOncut, setOndblclick, setOndrag, setOndragend, setOndragenter, setOndragleave, setOndragover, setOndragstart, setOndrop, setOndurationchange, setOnemptied, setOnended, setOnerror, setOnfocus, setOngotpointercapture, setOninput, setOninvalid, setOnkeydown, setOnkeypress, setOnkeyup, setOnload, setOnloadeddata, setOnloadedmetadata, setOnloadstart, setOnlostpointercapture, setOnmousedown, setOnmouseenter, setOnmouseleave, setOnmousemove, setOnmouseout, setOnmouseover, setOnmouseup, setOnmousewheel, setOnmozfullscreenchange, setOnmozfullscreenerror, setOnpaste, setOnpause, setOnplay, setOnplaying, setOnpointercancel, setOnpointerdown, setOnpointerenter, setOnpointerleave, setOnpointerlockchange, setOnpointerlockerror, setOnpointermove, setOnpointerout, setOnpointerover, setOnpointerup, setOnprogress, setOnratechange, setOnreadystatechange, setOnreset, setOnresize, setOnscroll, setOnsearch, setOnseeked, setOnseeking, setOnselect, setOnselectionchange, setOnselectstart, setOnstalled, setOnsubmit, setOnsuspend, setOntimeupdate, setOntoggle, setOnvolumechange, setOnwaiting, setOnwebkitfullscreenchange, setOnwebkitfullscreenerror, setOnwheel, setVlinkColor, setWindow
-
Methods inherited from class org.htmlunit.javascript.host.dom.Node
after, append, before, cloneNode, compareDocumentPosition, getAttributes, getChildNodes, getFirstChild, getJavaScriptNode, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParent, getParentElement, getParentNode, getPrefix, getPreviousSibling, getRootNode, getTextContent, hasAttributes, hasChildNodes, insertBefore, insertBeforeImpl, isEqualNode, isSameNode, normalize, prepend, remove, removeChild, replaceChild, replaceChildren, replaceWith, setNodeValue, setTextContent
-
Methods inherited from class org.htmlunit.javascript.host.event.EventTarget
addEventListener, clearEventListenersContainer, executeEventLocally, fireEvent, getEventHandler, getEventListenersContainer, hasEventHandlers, isEventHandlerOnWindow, removeEventListener, setEventHandler
-
Methods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromise
-
Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
writeBuilder_
private final java.lang.StringBuilder writeBuilder_
The buffer that will be used for calls to document.write().
-
writeInCurrentDocument_
private boolean writeInCurrentDocument_
-
closePostponedAction_
private boolean closePostponedAction_
-
executionExternalPostponed_
private boolean executionExternalPostponed_
-
-
Method Detail
-
jsConstructor
public void jsConstructor()
JavaScript constructor.- Overrides:
jsConstructor
in classDocument
-
getDomNodeOrDie
public DomNode getDomNodeOrDie()
Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.- Overrides:
getDomNodeOrDie
in classHtmlUnitScriptable
- Returns:
- the DOM node
-
getPage
public HtmlPage getPage()
Returns the HTML page that this document is modeling.
-
write
public static void write(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)
JavaScript function "write" may accept a variable number of arguments.- Parameters:
context
- the JavaScript contextscope
- the scopethisObj
- the scriptableargs
- the arguments passed into the methodfunction
- the function- See Also:
- MSDN documentation
-
concatArgsAsString
private static java.lang.String concatArgsAsString(java.lang.Object[] args)
Converts the arguments to strings and concatenate them.- Parameters:
args
- the JavaScript arguments- Returns:
- the string concatenation
-
writeln
public static void writeln(org.htmlunit.corejs.javascript.Context context, org.htmlunit.corejs.javascript.Scriptable scope, org.htmlunit.corejs.javascript.Scriptable thisObj, java.lang.Object[] args, org.htmlunit.corejs.javascript.Function function)
JavaScript function "writeln" may accept a variable number of arguments.- Parameters:
context
- the JavaScript contextscope
- the scopethisObj
- the scriptableargs
- the arguments passed into the methodfunction
- the function- See Also:
- MSDN documentation
-
getDocument
private static HTMLDocument getDocument(org.htmlunit.corejs.javascript.Scriptable thisObj)
Returns the current document instance, usingthisObj
as a hint.- Parameters:
thisObj
- a hint as to the current document (may be the prototype when function is used without "this")- Returns:
- the current document instance
-
setExecutingDynamicExternalPosponed
public void setExecutingDynamicExternalPosponed(boolean executing)
This a hack!!! A cleaner way is welcome. Handle a case where document.write is simply ignored. See HTMLDocumentWrite2Test.write_fromScriptAddedWithAppendChild_external.- Parameters:
executing
- indicates if executing or not
-
write
protected void write(java.lang.String content)
JavaScript function "write".See http://www.whatwg.org/specs/web-apps/current-work/multipage/section-dynamic.html for a good description of the semantics of open(), write(), writeln() and close().
- Parameters:
content
- the content to write
-
scheduleImplicitClose
private void scheduleImplicitClose()
-
canAlreadyBeParsed
static boolean canAlreadyBeParsed(java.lang.String content)
Indicates if the content is a well formed HTML snippet that can already be parsed to be added to the DOM.- Parameters:
content
- the HTML snippet- Returns:
false
if it not well formed
-
getLastHtmlElement
HtmlElement getLastHtmlElement(HtmlElement node)
Gets the node that is the last one when exploring following nodes, depth-first.- Parameters:
node
- the node to search- Returns:
- the searched node
-
getCookie
public java.lang.String getCookie()
Returns thecookie
property.
-
setCookie
public void setCookie(java.lang.String newCookie)
Adds a cookie, as long as cookies are enabled.- Parameters:
newCookie
- in the format "name=value[;expires=date][;domain=domainname][;path=path][;secure]- See Also:
- MSDN documentation
-
open
public java.lang.Object open(java.lang.Object url, java.lang.Object name, java.lang.Object features, java.lang.Object replace)
JavaScript function "open".See http://www.whatwg.org/specs/web-apps/current-work/multipage/section-dynamic.html for a good description of the semantics of open(), write(), writeln() and close().
- Parameters:
url
- when a new document is opened, url is a String that specifies a MIME type for the document. When a new window is opened, url is a String that specifies the URL to render in the new windowname
- the namefeatures
- the featuresreplace
- whether to replace in the history list or no- Returns:
- a reference to the new document object.
- See Also:
- MSDN documentation
-
close
public void close() throws java.io.IOException
JavaScript functionclose
.See http://www.whatwg.org/specs/web-apps/current-work/multipage/section-dynamic.html for a good description of the semantics of open(), write(), writeln() and close().
-
getDocumentElement
public Element getDocumentElement()
Gets the JavaScript propertydocumentElement
for the document.- Overrides:
getDocumentElement
in classDocument
- Returns:
- the root node for the document
-
implicitCloseIfNecessary
private void implicitCloseIfNecessary()
Closes the document implicitly, i.e. flushes thedocument.write
buffer (IE only).
-
appendChild
public java.lang.Object appendChild(java.lang.Object childObject)
Adds a DOM node to the node.- Overrides:
appendChild
in classNode
- Parameters:
childObject
- the node to add to this node- Returns:
- the newly added child node
-
getElementById
public HtmlUnitScriptable getElementById(java.lang.String id)
Returns the element with the specified ID, ornull
if that element could not be found.- Overrides:
getElementById
in classDocument
- Parameters:
id
- the ID to search for- Returns:
- the element, or
null
if it could not be found
-
getElementsByClassName
public HTMLCollection getElementsByClassName(java.lang.String className)
Returns all the descendant elements with the specified class name.- Overrides:
getElementsByClassName
in classDocument
- Parameters:
className
- the name to search for- Returns:
- all the descendant elements with the specified class name
- See Also:
- Mozilla doc
-
getElementsByName
public NodeList getElementsByName(java.lang.String elementName)
Returns all HTML elements that have aname
attribute with the specified value.Refer to The DOM spec for details.
- Overrides:
getElementsByName
in classDocument
- Parameters:
elementName
- - value of thename
attribute to look for- Returns:
- all HTML elements that have a
name
attribute with the specified value
-
getWithPreemption
protected java.lang.Object getWithPreemption(java.lang.String name)
Calls todocument.XYZ
should first look at elements namedXYZ
before using standard functions.Called by
HtmlUnitScriptable.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 classHtmlUnitScriptable
- Parameters:
name
- the property name- Returns:
Scriptable.NOT_FOUND
if not found
-
getIt
private java.lang.Object getIt(java.lang.String name)
-
getItComputeElements
static java.util.List<DomNode> getItComputeElements(HtmlPage page, java.lang.String name, boolean alsoFrames)
-
getHead
public HTMLElement getHead()
Returns this document'shead
element.
-
getTitle
public java.lang.String getTitle()
Returns this document's title.
-
setTitle
public void setTitle(java.lang.String title)
Sets this document's title.
-
getActiveElement
public HTMLElement getActiveElement()
Returns the value of theactiveElement
property.- Overrides:
getActiveElement
in classDocument
- Returns:
- the value of the
activeElement
property - See Also:
- MSDN documentation
-
hasFocus
public boolean hasFocus()
Returnsfalse
if the active element in the document has no focus;true
if the active element in the document has focus.
-
dispatchEvent
public boolean dispatchEvent(Event event)
Dispatches an event into the event system (standards-conformant browsers only). See the Gecko DOM reference for more information.- Overrides:
dispatchEvent
in classEventTarget
- Parameters:
event
- the event to be dispatched- Returns:
false
if at least one of the event handlers which handled the event calledpreventDefault
;true
otherwise
-
getSelection
public Selection getSelection()
Returns the current selection.- Overrides:
getSelection
in classDocument
- Returns:
- the current selection
-
createAttribute
public Attr createAttribute(java.lang.String attributeName)
Creates a new HTML attribute with the specified name.- Overrides:
createAttribute
in classDocument
- Parameters:
attributeName
- the name of the attribute to create- Returns:
- an attribute with the specified name
-
getBaseURI
public java.lang.String getBaseURI()
Returns the Base URI as a string.- Overrides:
getBaseURI
in classNode
- Returns:
- the Base URI as a string
-
elementFromPoint
public HtmlUnitScriptable elementFromPoint(int x, int y)
Returns the element for the specified x coordinate and the specified y coordinate. The current implementation always returns the <body> element.- Overrides:
elementFromPoint
in classDocument
- Parameters:
x
- the x offset, in pixelsy
- the y offset, in pixels- Returns:
- the element for the specified x coordinate and the specified y coordinate
-
-