Search in sources :

Example 6 with DomText

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

the class GWT250Test method verifyStartMailBody.

private static void verifyStartMailBody(final HtmlPage page, final String... details) {
    final List<?> detailsCells = page.getByXPath("//div[@class='MGI']/text()");
    for (int i = 0; i < details.length; i++) {
        final DomText text = (DomText) detailsCells.get(i);
        assertEquals(details[i], text.asNormalizedText());
    }
}
Also used : DomText(com.gargoylesoftware.htmlunit.html.DomText)

Example 7 with DomText

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

the class GWT250Test method hello.

/**
 * @throws Exception if an error occurs
 */
@Test
public void hello() throws Exception {
    final List<String> collectedAlerts = new ArrayList<>();
    final HtmlPage page = loadGWTPage("Hello", collectedAlerts, "//button");
    final HtmlButton button = page.getFirstByXPath("//button");
    final DomText buttonLabel = (DomText) button.getChildren().iterator().next();
    assertEquals("Click me", buttonLabel.getData());
    button.click();
    final String[] expectedAlerts = { "Hello, AJAX" };
    assertEquals(expectedAlerts, collectedAlerts);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) DomText(com.gargoylesoftware.htmlunit.html.DomText) ArrayList(java.util.ArrayList) HtmlButton(com.gargoylesoftware.htmlunit.html.HtmlButton) Test(org.junit.Test)

Example 8 with DomText

use of com.gargoylesoftware.htmlunit.html.DomText 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 9 with DomText

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

the class XSLProcessor method transform.

private void transform(final XMLDOMNode source, final DomNode parent) {
    final Object result = transform(source);
    if (result instanceof org.w3c.dom.Node) {
        final SgmlPage parentPage = parent.getPage();
        final NodeList children = ((org.w3c.dom.Node) result).getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            XmlUtils.appendChild(parentPage, parent, children.item(i), false);
        }
    } else {
        final DomText text = new DomText(parent.getPage(), (String) result);
        parent.appendChild(text);
    }
}
Also used : DomText(com.gargoylesoftware.htmlunit.html.DomText) Node(com.gargoylesoftware.htmlunit.javascript.host.dom.Node) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) NodeList(org.w3c.dom.NodeList) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage)

Example 10 with DomText

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

the class XSLProcessor method transform.

/**
 * Starts the transformation process or resumes a previously failed transformation.
 */
@JsxFunction
public void transform() {
    final XMLDOMNode input = input_;
    final SgmlPage page = input.getDomNodeOrDie().getPage();
    if (output_ == null || !(output_ instanceof XMLDOMNode)) {
        final DomDocumentFragment fragment = page.createDocumentFragment();
        final XMLDOMDocumentFragment node = new XMLDOMDocumentFragment();
        node.setParentScope(getParentScope());
        node.setPrototype(getPrototype(node.getClass()));
        node.setDomNode(fragment);
        output_ = fragment.getScriptableObject();
    }
    transform(input_, ((XMLDOMNode) output_).getDomNodeOrDie());
    final XMLSerializer serializer = new XMLSerializer(false);
    final StringBuilder output = new StringBuilder();
    for (final DomNode child : ((XMLDOMNode) output_).getDomNodeOrDie().getChildren()) {
        if (child instanceof DomText) {
            // See XMLDocumentTest.testLoadXML_XMLSpaceAttribute()
            if (StringUtils.isNotBlank(((DomText) child).getData())) {
                output.append(((DomText) child).getData());
            }
        } else {
            // remove trailing "\r\n"
            final String serializedString = serializer.serializeToString(child.getScriptableObject());
            output.append(serializedString, 0, serializedString.length() - 2);
        }
    }
    output_ = output.toString();
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomDocumentFragment(com.gargoylesoftware.htmlunit.html.DomDocumentFragment) DomText(com.gargoylesoftware.htmlunit.html.DomText) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

DomText (com.gargoylesoftware.htmlunit.html.DomText)23 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)15 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)5 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)5 JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)3 ArrayList (java.util.ArrayList)3 NodeList (org.w3c.dom.NodeList)3 ElementNotFoundException (com.gargoylesoftware.htmlunit.ElementNotFoundException)2 DomAttr (com.gargoylesoftware.htmlunit.html.DomAttr)2 DomCDataSection (com.gargoylesoftware.htmlunit.html.DomCDataSection)2 DomComment (com.gargoylesoftware.htmlunit.html.DomComment)2 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)2 DomProcessingInstruction (com.gargoylesoftware.htmlunit.html.DomProcessingInstruction)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)2 Node (com.gargoylesoftware.htmlunit.javascript.host.dom.Node)2 FunctionObject (net.sourceforge.htmlunit.corejs.javascript.FunctionObject)2 Test (org.junit.Test)2 DomDocumentFragment (com.gargoylesoftware.htmlunit.html.DomDocumentFragment)1 DomDocumentType (com.gargoylesoftware.htmlunit.html.DomDocumentType)1