MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / cloneNode

Method cloneNode

src/main/java/org/htmlunit/html/HtmlPage.java:2063–2088  ·  view source on GitHub ↗

{@inheritDoc}

(final boolean deep)

Source from the content-addressed store, hash-verified

2061 * {@inheritDoc}
2062 */
2063 @Override
2064 public HtmlPage cloneNode(final boolean deep) {
2065 // we need the ScriptObject clone before cloning the kids.
2066 final HtmlPage result = (HtmlPage) super.cloneNode(false);
2067 if (getWebClient().isJavaScriptEnabled()) {
2068 final HtmlUnitScriptable jsObjClone = getScriptableObject().clone();
2069 jsObjClone.setDomNode(result);
2070 }
2071
2072 // if deep, clone the kids too, and re initialize parts of the clone
2073 if (deep) {
2074 // this was previously synchronized but that makes not sense, why
2075 // lock the source against a copy only one has a reference too,
2076 // because result is a local reference
2077 result.attributeListeners_ = null;
2078
2079 result.selectionRanges_ = new ArrayList<>(3);
2080 // the original one is synchronized so we should do that here too, shouldn't we?
2081 result.afterLoadActions_ = Collections.synchronizedList(new ArrayList<>());
2082 result.frameElements_ = new ArrayList<>();
2083 for (DomNode child = getFirstChild(); child != null; child = child.getNextSibling()) {
2084 result.appendChild(child.cloneNode(true));
2085 }
2086 }
2087 return result;
2088 }
2089
2090 /**
2091 * Adds an HtmlAttributeChangeListener to the listener list.

Callers 7

cloneNodeMethod · 0.95
clonedPageHasOwnIdMapMethod · 0.95
cloneNodeMethod · 0.95

Calls 9

setDomNodeMethod · 0.95
getNextSiblingMethod · 0.95
cloneNodeMethod · 0.95
getWebClientMethod · 0.65
getScriptableObjectMethod · 0.65
isJavaScriptEnabledMethod · 0.45
cloneMethod · 0.45
getFirstChildMethod · 0.45
appendChildMethod · 0.45

Tested by 7

cloneNodeMethod · 0.76
clonedPageHasOwnIdMapMethod · 0.76
cloneNodeMethod · 0.76