Skip to content

Commit 2d6ec1c

Browse files
committed
move some methods up
1 parent bc1f58d commit 2d6ec1c

File tree

3 files changed

+52
-57
lines changed

3 files changed

+52
-57
lines changed

src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_SETTING_DOMAIN_THROWS_FOR_ABOUT_BLANK;
3333
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TREEWALKER_EXPAND_ENTITY_REFERENCES_FALSE;
3434
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TREEWALKER_FILTER_FUNCTION_ONLY;
35+
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_XML_GET_ELEMENT_BY_ID__ANY_ELEMENT;
3536
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS;
3637
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
3738
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF;
@@ -59,8 +60,10 @@
5960
import org.apache.commons.logging.Log;
6061
import org.apache.commons.logging.LogFactory;
6162
import org.apache.xml.utils.PrefixResolver;
63+
import org.w3c.dom.CDATASection;
6264
import org.w3c.dom.DOMException;
6365
import org.w3c.dom.DocumentType;
66+
import org.w3c.dom.ProcessingInstruction;
6467

6568
import com.gargoylesoftware.css.parser.CSSException;
6669
import com.gargoylesoftware.htmlunit.BrowserVersion;
@@ -134,6 +137,7 @@
134137
import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument;
135138
import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement;
136139
import com.gargoylesoftware.htmlunit.util.EncodingSniffer;
140+
import com.gargoylesoftware.htmlunit.xml.XmlPage;
137141

138142
import net.sourceforge.htmlunit.corejs.javascript.Callable;
139143
import net.sourceforge.htmlunit.corejs.javascript.Context;
@@ -4157,4 +4161,48 @@ protected boolean isReadOnlySettable(final String name, final Object value) {
41574161
}
41584162
return super.isReadOnlySettable(name, value);
41594163
}
4164+
4165+
/**
4166+
* Returns the element with the specified ID, as long as it is an HTML element; {@code null} otherwise.
4167+
* @param id the ID to search for
4168+
* @return the element with the specified ID, as long as it is an HTML element; {@code null} otherwise
4169+
*/
4170+
@JsxFunction
4171+
public Object getElementById(final String id) {
4172+
final DomNode domNode = getDomNodeOrDie();
4173+
final Object domElement = domNode.getFirstByXPath("//*[@id = \"" + id + "\"]");
4174+
if (domElement != null) {
4175+
if (!(domNode instanceof XmlPage) || domElement instanceof HtmlElement
4176+
|| getBrowserVersion().hasFeature(JS_XML_GET_ELEMENT_BY_ID__ANY_ELEMENT)) {
4177+
return ((DomElement) domElement).getScriptableObject();
4178+
}
4179+
if (LOG.isDebugEnabled()) {
4180+
LOG.debug("getElementById(" + id + "): no HTML DOM node found with this ID");
4181+
}
4182+
}
4183+
return null;
4184+
}
4185+
4186+
/**
4187+
* Creates a new ProcessingInstruction.
4188+
* @param target the target
4189+
* @param data the data
4190+
* @return the new ProcessingInstruction
4191+
*/
4192+
@JsxFunction
4193+
public Object createProcessingInstruction(final String target, final String data) {
4194+
final ProcessingInstruction node = getPage().createProcessingInstruction(target, data);
4195+
return getScriptableFor(node);
4196+
}
4197+
4198+
/**
4199+
* Creates a new createCDATASection.
4200+
* @param data the data
4201+
* @return the new CDATASection
4202+
*/
4203+
@JsxFunction
4204+
public Object createCDATASection(final String data) {
4205+
final CDATASection node = getPage().createCDATASection(data);
4206+
return getScriptableFor(node);
4207+
}
41604208
}

src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLDocument.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOMPARSER_EXCEPTION_ON_ERROR;
1919
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOMPARSER_PARSERERROR_ON_ERROR;
2020
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_XML_GET_ELEMENTS_BY_TAG_NAME_LOCAL;
21-
import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_XML_GET_ELEMENT_BY_ID__ANY_ELEMENT;
2221
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
2322
import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF;
2423

@@ -27,9 +26,6 @@
2726
import org.apache.commons.lang3.StringUtils;
2827
import org.apache.commons.logging.Log;
2928
import org.apache.commons.logging.LogFactory;
30-
import org.w3c.dom.CDATASection;
31-
import org.w3c.dom.ProcessingInstruction;
32-
3329
import com.gargoylesoftware.htmlunit.StringWebResponse;
3430
import com.gargoylesoftware.htmlunit.WebRequest;
3531
import com.gargoylesoftware.htmlunit.WebResponse;
@@ -275,48 +271,4 @@ protected boolean isMatching(final DomNode node) {
275271

276272
return collection;
277273
}
278-
279-
/**
280-
* Returns the element with the specified ID, as long as it is an HTML element; {@code null} otherwise.
281-
* @param id the ID to search for
282-
* @return the element with the specified ID, as long as it is an HTML element; {@code null} otherwise
283-
*/
284-
@JsxFunction
285-
public Object getElementById(final String id) {
286-
final DomNode domNode = getDomNodeOrDie();
287-
final Object domElement = domNode.getFirstByXPath("//*[@id = \"" + id + "\"]");
288-
if (domElement != null) {
289-
if (!(domNode instanceof XmlPage) || domElement instanceof HtmlElement
290-
|| getBrowserVersion().hasFeature(JS_XML_GET_ELEMENT_BY_ID__ANY_ELEMENT)) {
291-
return ((DomElement) domElement).getScriptableObject();
292-
}
293-
if (LOG.isDebugEnabled()) {
294-
LOG.debug("getElementById(" + id + "): no HTML DOM node found with this ID");
295-
}
296-
}
297-
return null;
298-
}
299-
300-
/**
301-
* Creates a new ProcessingInstruction.
302-
* @param target the target
303-
* @param data the data
304-
* @return the new ProcessingInstruction
305-
*/
306-
@JsxFunction
307-
public Object createProcessingInstruction(final String target, final String data) {
308-
final ProcessingInstruction node = getPage().createProcessingInstruction(target, data);
309-
return getScriptableFor(node);
310-
}
311-
312-
/**
313-
* Creates a new createCDATASection.
314-
* @param data the data
315-
* @return the new CDATASection
316-
*/
317-
@JsxFunction
318-
public Object createCDATASection(final String data) {
319-
final CDATASection node = getPage().createCDATASection(data);
320-
return getScriptableFor(node);
321-
}
322274
}

src/test/java/com/gargoylesoftware/htmlunit/general/ElementOwnPropertiesTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7534,15 +7534,10 @@ public void htmlDocument() throws Exception {
75347534
FF60 = "async,constructor(),load()",
75357535
FF68 = "async,constructor(),load()",
75367536
IE = "constructor")
7537-
@HtmlUnitNYI(CHROME = "constructor(),createCDATASection(),createProcessingInstruction(),"
7538-
+ "getElementById(),getElementsByTagName()",
7539-
FF60 = "async,constructor(),createCDATASection(),createProcessingInstruction(),"
7540-
+ "getElementById(),getElementsByTagName(),load()",
7541-
FF68 = "async,constructor(),createCDATASection(),createProcessingInstruction(),"
7542-
+ "getElementById(),getElementsByTagName(),load()",
7543-
IE = "constructor,createCDATASection(),createProcessingInstruction(),"
7544-
+ "getElementById(),getElementsByTagName()")
7545-
//IE expectations are bigger than real IE alert length, test should be changed to store value in textarea
7537+
@HtmlUnitNYI(CHROME = "constructor(),getElementsByTagName()",
7538+
FF60 = "async,constructor(),getElementsByTagName(),load()",
7539+
FF68 = "async,constructor(),getElementsByTagName(),load()",
7540+
IE = "constructor,getElementsByTagName()")
75467541
public void document() throws Exception {
75477542
testString("xmlDocument");
75487543
}

0 commit comments

Comments
 (0)