MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / addElement

Method addElement

src/main/java/org/htmlunit/html/HtmlPage.java:1879–1917  ·  view source on GitHub ↗
(final DomElement element, final boolean recurse)

Source from the content-addressed store, hash-verified

1877 }
1878
1879 private void addElement(final DomElement element, final boolean recurse) {
1880 final String idValue = element.getAttribute(DomElement.ID_ATTRIBUTE);
1881 if (ATTRIBUTE_NOT_DEFINED != idValue) {
1882 MappedElementIndexEntry elements = idMap_.get(idValue);
1883 if (elements == null) {
1884 elements = new MappedElementIndexEntry();
1885 elements.add(element);
1886 idMap_.put(idValue, elements);
1887 }
1888 else {
1889 elements.add(element);
1890 }
1891 }
1892
1893 final String nameValue = element.getAttribute(DomElement.NAME_ATTRIBUTE);
1894 if (ATTRIBUTE_NOT_DEFINED != nameValue) {
1895 MappedElementIndexEntry elements = nameMap_.get(nameValue);
1896 if (elements == null) {
1897 elements = new MappedElementIndexEntry();
1898 elements.add(element);
1899 nameMap_.put(nameValue, elements);
1900 }
1901 else {
1902 elements.add(element);
1903 }
1904 }
1905
1906 if (recurse) {
1907 // poor man's approach - we don't use getChildElements()
1908 // to avoid a bunch of object constructions
1909 DomNode nextChild = element.getFirstChild();
1910 while (nextChild != null) {
1911 if (nextChild instanceof DomElement domElement) {
1912 addElement(domElement, true);
1913 }
1914 nextChild = nextChild.getNextSibling();
1915 }
1916 }
1917 }
1918
1919 /**
1920 * Removes an element and optionally its children from the ID and name maps, if necessary.

Callers 15

addMappedElementMethod · 0.95
SelectionFunction · 0.80
SelectionFunction · 0.80
tiny_mce_src.jsFile · 0.80
aFunction · 0.80
tiny_mce.jsFile · 0.80
aFunction · 0.80
tiny_mce_jquery.jsFile · 0.80
aFunction · 0.80

Calls 6

addMethod · 0.95
getNextSiblingMethod · 0.95
getAttributeMethod · 0.45
getMethod · 0.45
putMethod · 0.45
getFirstChildMethod · 0.45

Tested by

no test coverage detected