Web The root document of a web page is not represented by a
Window node, but the special node Web page.
Nested document nodes in frames correspond to
Components nodes.
The DocumentNode class is derived from Node and also resides
in the package de.qfs.apps.qftest.client.web.dom. In addition to the
methods defined in the Node class and explained above,
DocumentNode provides the following:
Object callJS(String code)
Execute some JavaScript code within a function in the context of this document. This often works even
if the call of eval() is restricted by a Content Security Policy (CSP).
Parameters
code
The code to execute.
Returns
Whatever the code returns explicitely using a return statement, converted to the proper object type. Even
returning a DOM node, frame or document works.
Object evalJS(String script)
Evaluate some JavaScript code in the context of this document by calling window.eval().
In most cases, the method callJS should be use, since the call of eval()
might be restricted for the document by a Content Security Policy (CSP).
Parameters
script
The script to execute.
Returns
Whatever the script returns, converted to the proper object type. Even
returning a DOM node, frame or document works.
FrameNode[] getFrames()
Get the child frames of the document.
Returns
The child frames of the document, an empty array in case there are none.
DomNode getRootElement()
Get the <HTML> root element of the document.
Returns
The root element of the document.
String getSourcecode()
Get the HTML source code of the document in its current state, which is not
necessarily the same as what was loaded when the document was opened because
attributes or the DOM's structure may have been changes since, e.g. via JavaScript.
Returns
The current HTML code of the document.
String getTitle()
Get the title of the document as defined in the <TITLE> of the <HEAD> of
its root element.
Returns
The title of the document.
String getUrl()
Get the URL of the document.
Returns
The URL of the document.
boolean hasParent()
To test whether a document is a top-level document this method should be used
instead of testing whether the result of getParent() is null. The
reason is that loading of nested child documents may be completed before loading of
the main document. During this time it is known that the nested document will have a
parent, but the parent is not available yet.
Returns
True if the document has a parent, false if it is a top-level document.
In addition to the instance methods describe above, the DocumentNode class
provides some static convenience methods for manipulating URLs.
static String getUrlBase(String url)
Get the base part of an URL, including host and directory but excluding possible
parameters separated by '?' and excluding a possible Tomcat session ID.
Parameters
url
The URL to get the base part of.
Returns
The base part of the URL.
static String getUrlHost(String url)
Get the host part of an URL, i.e. the part between "http(s)://" and the next '/'.
Parameters
url
The URL to get the host part of.
Returns
The host part of the URL or null if the protocol is neither http nor https.
Get the parameters of an URL, including those separated by '?' and a possible Tomcat
session ID, in the form of an ExtraFeatureSet that can be used for an
ExtraFeatureResolver as described in subsection 54.1.11.
Parameters
url
The URL to get the parameters for.
Returns
The parameters of the URL.
static String normalizeUrl(String url)
Normalize an URL by replacing '\' with '/', "file:/(/(/))" with "file:///", up-casing
windows drive letters and decoding %.. sequences.