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());
}
}
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);
}
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_;
}
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);
}
}
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();
}
Aggregations