|
32 | 32 | import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_SETTING_DOMAIN_THROWS_FOR_ABOUT_BLANK;
|
33 | 33 | import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TREEWALKER_EXPAND_ENTITY_REFERENCES_FALSE;
|
34 | 34 | 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; |
35 | 36 | import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS;
|
36 | 37 | import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
|
37 | 38 | import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF;
|
|
59 | 60 | import org.apache.commons.logging.Log;
|
60 | 61 | import org.apache.commons.logging.LogFactory;
|
61 | 62 | import org.apache.xml.utils.PrefixResolver;
|
| 63 | +import org.w3c.dom.CDATASection; |
62 | 64 | import org.w3c.dom.DOMException;
|
63 | 65 | import org.w3c.dom.DocumentType;
|
| 66 | +import org.w3c.dom.ProcessingInstruction; |
64 | 67 |
|
65 | 68 | import com.gargoylesoftware.css.parser.CSSException;
|
66 | 69 | import com.gargoylesoftware.htmlunit.BrowserVersion;
|
|
134 | 137 | import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument;
|
135 | 138 | import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement;
|
136 | 139 | import com.gargoylesoftware.htmlunit.util.EncodingSniffer;
|
| 140 | +import com.gargoylesoftware.htmlunit.xml.XmlPage; |
137 | 141 |
|
138 | 142 | import net.sourceforge.htmlunit.corejs.javascript.Callable;
|
139 | 143 | import net.sourceforge.htmlunit.corejs.javascript.Context;
|
@@ -4157,4 +4161,48 @@ protected boolean isReadOnlySettable(final String name, final Object value) {
|
4157 | 4161 | }
|
4158 | 4162 | return super.isReadOnlySettable(name, value);
|
4159 | 4163 | }
|
| 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 | + } |
4160 | 4208 | }
|
0 commit comments