Java Code Examples for com.gargoylesoftware.htmlunit.html.DomNode#getOwnerDocument()

The following examples show how to use com.gargoylesoftware.htmlunit.html.DomNode#getOwnerDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLDOMNode.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a node list containing the child nodes.
 * @return a node list containing the child nodes
 */
@JsxGetter
public XMLDOMNodeList getChildNodes() {
    if (childNodes_ == null) {
        final DomNode domNode = getDomNodeOrDie();
        final boolean isXmlPage = domNode.getOwnerDocument() instanceof XmlPage;
        final Boolean xmlSpaceDefault = isXMLSpaceDefault(domNode);
        final boolean skipEmptyTextNode = isXmlPage && !Boolean.FALSE.equals(xmlSpaceDefault);

        childNodes_ = new XMLDOMNodeList(domNode, false, "XMLDOMNode.childNodes") {
            @Override
            protected List<DomNode> computeElements() {
                final List<DomNode> response = new ArrayList<>();
                for (final DomNode child : domNode.getChildren()) {
                    //IE: XmlPage ignores all empty text nodes
                    if (skipEmptyTextNode && child instanceof DomText && !(child instanceof DomCDataSection)
                        && StringUtils.isBlank(((DomText) child).getNodeValue())) { //and 'xml:space' is 'default'
                        continue;
                    }
                    response.add(child);
                }

                return response;
            }
        };
    }
    return childNodes_;
}
 
Example 2
Source File: XMLDOMNode.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the root of the document that contains the node.
 * @return the root of the document that contains the node
 */
@JsxGetter
public Object getOwnerDocument() {
    final DomNode domNode = getDomNodeOrDie();
    final Object document = domNode.getOwnerDocument();
    if (document == null) {
        return null;
    }
    return ((SgmlPage) document).getScriptableObject();
}
 
Example 3
Source File: XMLDOMNode.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a node list containing the child nodes.
 * @return a node list containing the child nodes
 */
@JsxGetter
public XMLDOMNodeList getChildNodes() {
    if (childNodes_ == null) {
        final DomNode domNode = getDomNodeOrDie();
        final boolean isXmlPage = domNode.getOwnerDocument() instanceof XmlPage;
        final Boolean xmlSpaceDefault = isXMLSpaceDefault(domNode);
        final boolean skipEmptyTextNode = isXmlPage && !Boolean.FALSE.equals(xmlSpaceDefault);

        childNodes_ = new XMLDOMNodeList(domNode, false, "XMLDOMNode.childNodes") {
            @Override
            protected List<DomNode> computeElements() {
                final List<DomNode> response = new ArrayList<>();
                for (final DomNode child : domNode.getChildren()) {
                    //IE: XmlPage ignores all empty text nodes
                    if (skipEmptyTextNode && child instanceof DomText && !(child instanceof DomCDataSection)
                        && StringUtils.isBlank(((DomText) child).getNodeValue())) { //and 'xml:space' is 'default'
                        continue;
                    }
                    response.add(child);
                }

                return response;
            }
        };
    }
    return childNodes_;
}
 
Example 4
Source File: XMLDOMNode.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the root of the document that contains the node.
 * @return the root of the document that contains the node
 */
@JsxGetter
public Object getOwnerDocument() {
    final DomNode domNode = getDomNodeOrDie();
    final Object document = domNode.getOwnerDocument();
    if (document == null) {
        return null;
    }
    return ((SgmlPage) document).getScriptableObject();
}