Search in sources :

Example 1 with DomCDataSection

use of com.gargoylesoftware.htmlunit.html.DomCDataSection in project htmlunit by HtmlUnit.

the class XMLDOMNode method getChildNodes.

/**
 * 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(child.getNodeValue())) {
                        // and 'xml:space' is 'default'
                        continue;
                    }
                    response.add(child);
                }
                return response;
            }
        };
    }
    return childNodes_;
}
Also used : DomCDataSection(com.gargoylesoftware.htmlunit.html.DomCDataSection) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomText(com.gargoylesoftware.htmlunit.html.DomText) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) ArrayList(java.util.ArrayList) List(java.util.List) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 2 with DomCDataSection

use of com.gargoylesoftware.htmlunit.html.DomCDataSection in project htmlunit by HtmlUnit.

the class XmlUtils method copy.

/**
 * Copy all children from 'source' to 'dest', within the context of the specified page.
 * @param page the page which the nodes belong to
 * @param source the node to copy from
 * @param dest the node to copy to
 * @param handleXHTMLAsHTML if true elements from the XHTML namespace are handled as HTML elements instead of
 *     DOM elements
 */
private static void copy(final SgmlPage page, final Node source, final DomNode dest, final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) {
    final NodeList nodeChildren = source.getChildNodes();
    for (int i = 0; i < nodeChildren.getLength(); i++) {
        final Node child = nodeChildren.item(i);
        switch(child.getNodeType()) {
            case Node.ELEMENT_NODE:
                final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML, attributesOrderMap);
                dest.appendChild(childXml);
                copy(page, child, childXml, handleXHTMLAsHTML, attributesOrderMap);
                break;
            case Node.TEXT_NODE:
                dest.appendChild(new DomText(page, child.getNodeValue()));
                break;
            case Node.CDATA_SECTION_NODE:
                dest.appendChild(new DomCDataSection(page, child.getNodeValue()));
                break;
            case Node.COMMENT_NODE:
                dest.appendChild(new DomComment(page, child.getNodeValue()));
                break;
            case Node.PROCESSING_INSTRUCTION_NODE:
                dest.appendChild(new DomProcessingInstruction(page, child.getNodeName(), child.getNodeValue()));
                break;
            default:
                if (LOG.isWarnEnabled()) {
                    LOG.warn("NodeType " + child.getNodeType() + " (" + child.getNodeName() + ") is not yet supported.");
                }
        }
    }
}
Also used : DomCDataSection(com.gargoylesoftware.htmlunit.html.DomCDataSection) DomComment(com.gargoylesoftware.htmlunit.html.DomComment) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomText(com.gargoylesoftware.htmlunit.html.DomText) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DeferredNode(org.apache.xerces.dom.DeferredNode) DomProcessingInstruction(com.gargoylesoftware.htmlunit.html.DomProcessingInstruction)

Aggregations

DomCDataSection (com.gargoylesoftware.htmlunit.html.DomCDataSection)2 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)2 DomText (com.gargoylesoftware.htmlunit.html.DomText)2 DomComment (com.gargoylesoftware.htmlunit.html.DomComment)1 DomProcessingInstruction (com.gargoylesoftware.htmlunit.html.DomProcessingInstruction)1 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)1 XmlPage (com.gargoylesoftware.htmlunit.xml.XmlPage)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DeferredNode (org.apache.xerces.dom.DeferredNode)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1