use of com.gargoylesoftware.htmlunit.javascript.host.html.HTMLScriptElement in project htmlunit by HtmlUnit.
the class Element method printNode.
protected void printNode(final StringBuilder builder, final DomNode node, final boolean html) {
if (node instanceof DomComment) {
if (html) {
// Remove whitespace sequences.
final String s = PRINT_NODE_PATTERN.matcher(node.getNodeValue()).replaceAll(" ");
builder.append("<!--").append(s).append("-->");
}
} else if (node instanceof DomCharacterData) {
// Remove whitespace sequences, possibly escape XML characters.
String s = node.getNodeValue();
if (html) {
s = com.gargoylesoftware.htmlunit.util.StringUtils.escapeXmlChars(s);
}
builder.append(s);
} else if (html) {
final DomElement element = (DomElement) node;
final Element scriptObject = node.getScriptableObject();
final String tag = element.getTagName();
Element htmlElement = null;
if (scriptObject instanceof HTMLElement) {
htmlElement = scriptObject;
}
builder.append('<').append(tag);
// Add the attributes. IE does not use quotes, FF does.
for (final DomAttr attr : element.getAttributesMap().values()) {
if (!attr.getSpecified()) {
continue;
}
final String name = attr.getName();
final String value = PRINT_NODE_QUOTE_PATTERN.matcher(attr.getValue()).replaceAll(""");
builder.append(' ').append(name).append('=');
builder.append('\"');
builder.append(value);
builder.append('\"');
}
builder.append('>');
// Add the children.
final boolean isHtml = html && !(scriptObject instanceof HTMLScriptElement) && !(scriptObject instanceof HTMLStyleElement);
printChildren(builder, node, isHtml);
if (null == htmlElement || !htmlElement.isEndTagForbidden()) {
builder.append("</").append(tag).append('>');
}
} else {
if (node instanceof HtmlElement) {
final HtmlElement element = (HtmlElement) node;
if ("p".equals(element.getTagName())) {
if (getBrowserVersion().hasFeature(JS_INNER_HTML_LF)) {
// \r\n because it's to implement something IE specific
builder.append('\n');
} else {
int i = builder.length() - 1;
while (i >= 0 && Character.isWhitespace(builder.charAt(i))) {
i--;
}
builder.setLength(i + 1);
builder.append('\n');
}
}
if (!"script".equals(element.getTagName())) {
printChildren(builder, node, html);
}
}
}
}
Aggregations