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 classHTMLDocument.ParsingStatus
-
Field Summary
Fields Modifier and Type Field Description private booleanclosePostponedAction_private booleanexecutionExternalPostponed_private static org.apache.commons.logging.LogLOGprivate java.lang.StringBuilderwriteBuilder_The buffer that will be used for calls to document.write().private booleanwriteInCurrentDocument_-
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.ObjectappendChild(java.lang.Object childObject)Adds a DOM node to the node.(package private) static booleancanAlreadyBeParsed(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.voidclose()JavaScript functionclose.private static java.lang.StringconcatArgsAsString(java.lang.Object[] args)Converts the arguments to strings and concatenate them.AttrcreateAttribute(java.lang.String attributeName)Creates a new HTML attribute with the specified name.booleandispatchEvent(Event event)Dispatches an event into the event system (standards-conformant browsers only).HtmlUnitScriptableelementFromPoint(int x, int y)Returns the element for the specified x coordinate and the specified y coordinate.HTMLElementgetActiveElement()Returns the value of theactiveElementproperty.java.lang.StringgetBaseURI()Returns the Base URI as a string.java.lang.StringgetCookie()Returns thecookieproperty.private static HTMLDocumentgetDocument(org.htmlunit.corejs.javascript.Scriptable thisObj)Returns the current document instance, usingthisObjas a hint.ElementgetDocumentElement()Gets the JavaScript propertydocumentElementfor the document.DomNodegetDomNodeOrDie()Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.HtmlUnitScriptablegetElementById(java.lang.String id)Returns the element with the specified ID, ornullif that element could not be found.HTMLCollectiongetElementsByClassName(java.lang.String className)Returns all the descendant elements with the specified class name.NodeListgetElementsByName(java.lang.String elementName)Returns all HTML elements that have anameattribute with the specified value.HTMLElementgetHead()Returns this document'sheadelement.private java.lang.ObjectgetIt(java.lang.String name)(package private) static java.util.List<DomNode>getItComputeElements(HtmlPage page, java.lang.String name, boolean alsoFrames)(package private) HtmlElementgetLastHtmlElement(HtmlElement node)Gets the node that is the last one when exploring following nodes, depth-first.HtmlPagegetPage()Returns the HTML page that this document is modeling.SelectiongetSelection()Returns the current selection.java.lang.StringgetTitle()Returns this document's title.protected java.lang.ObjectgetWithPreemption(java.lang.String name)Calls todocument.XYZshould first look at elements namedXYZbefore using standard functions.booleanhasFocus()Returnsfalseif the active element in the document has no focus;trueif the active element in the document has focus.private voidimplicitCloseIfNecessary()Closes the document implicitly, i.e.voidjsConstructor()JavaScript constructor.java.lang.Objectopen(java.lang.Object url, java.lang.Object name, java.lang.Object features, java.lang.Object replace)JavaScript function "open".private voidscheduleImplicitClose()voidsetCookie(java.lang.String newCookie)Adds a cookie, as long as cookies are enabled.voidsetExecutingDynamicExternalPosponed(boolean executing)This a hack!!! A cleaner way is welcome.voidsetTitle(java.lang.String title)Sets this document's title.protected voidwrite(java.lang.String content)JavaScript function "write".static voidwrite(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 voidwriteln(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:
jsConstructorin 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:
getDomNodeOrDiein 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, usingthisObjas 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:
falseif 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 thecookieproperty.
-
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.IOExceptionJavaScript 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 propertydocumentElementfor the document.- Overrides:
getDocumentElementin classDocument- Returns:
- the root node for the document
-
implicitCloseIfNecessary
private void implicitCloseIfNecessary()
Closes the document implicitly, i.e. flushes thedocument.writebuffer (IE only).
-
appendChild
public java.lang.Object appendChild(java.lang.Object childObject)
Adds a DOM node to the node.- Overrides:
appendChildin 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, ornullif that element could not be found.- Overrides:
getElementByIdin classDocument- Parameters:
id- the ID to search for- Returns:
- the element, or
nullif it could not be found
-
getElementsByClassName
public HTMLCollection getElementsByClassName(java.lang.String className)
Returns all the descendant elements with the specified class name.- Overrides:
getElementsByClassNamein 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 anameattribute with the specified value.Refer to The DOM spec for details.
- Overrides:
getElementsByNamein classDocument- Parameters:
elementName- - value of thenameattribute to look for- Returns:
- all HTML elements that have a
nameattribute with the specified value
-
getWithPreemption
protected java.lang.Object getWithPreemption(java.lang.String name)
Calls todocument.XYZshould first look at elements namedXYZbefore 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:
getWithPreemptionin classHtmlUnitScriptable- Parameters:
name- the property name- Returns:
Scriptable.NOT_FOUNDif 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'sheadelement.
-
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 theactiveElementproperty.- Overrides:
getActiveElementin classDocument- Returns:
- the value of the
activeElementproperty - See Also:
- MSDN documentation
-
hasFocus
public boolean hasFocus()
Returnsfalseif the active element in the document has no focus;trueif 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:
dispatchEventin classEventTarget- Parameters:
event- the event to be dispatched- Returns:
falseif at least one of the event handlers which handled the event calledpreventDefault;trueotherwise
-
getSelection
public Selection getSelection()
Returns the current selection.- Overrides:
getSelectionin classDocument- Returns:
- the current selection
-
createAttribute
public Attr createAttribute(java.lang.String attributeName)
Creates a new HTML attribute with the specified name.- Overrides:
createAttributein 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:
getBaseURIin 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:
elementFromPointin 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
-
-