use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class XSLTProcessor method transform.
private void transform(final Node 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), true);
}
} else {
final DomText text = new DomText(parent.getPage(), (String) result);
parent.appendChild(text);
}
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class HtmlSerializerNormalizedText method appendDomNode.
/**
* Process {@link HtmlHiddenInput}.
*
* @param builder the StringBuilder to add to
* @param domNode the target to process
*/
protected void appendDomNode(final HtmlSerializerTextBuilder builder, final DomNode domNode) {
boolean block = false;
if (!(domNode instanceof HtmlBody)) {
final SgmlPage page = domNode.getPage();
final WebWindow window = page.getEnclosingWindow();
if (page != null && // TODO
page.getWebClient().isJavaScriptEngineEnabled() && window.getWebClient().getOptions().isCssEnabled()) {
if (domNode instanceof DomElement) {
final String display = window.getComputedStyle((DomElement) domNode, null).getDisplay();
block = "block".equals(display);
}
} else if (domNode instanceof HtmlElement) {
block = DisplayStyle.BLOCK == ((HtmlElement) domNode).getDefaultStyleDisplay();
}
}
if (block) {
builder.appendBlockSeparator();
}
appendChildren(builder, domNode);
if (block) {
builder.appendBlockSeparator();
}
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class HtmlSerializerVisibleText method appendInlineFrame.
/**
* Process {@link HtmlInlineFrame}.
*
* @param builder the StringBuilder to add to
* @param htmlInlineFrame the target to process
* @param mode the {@link Mode} to use for processing
*/
protected void appendInlineFrame(final HtmlSerializerTextBuilder builder, final HtmlInlineFrame htmlInlineFrame, final Mode mode) {
if (isDisplayed(htmlInlineFrame)) {
builder.appendBlockSeparator();
final Page page = htmlInlineFrame.getEnclosedPage();
if (page instanceof SgmlPage) {
builder.append(((SgmlPage) page).asNormalizedText(), mode);
}
builder.appendBlockSeparator();
}
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class XmlSerializer method asXml.
/**
* @param node a node
* @return the xml representation according to the setting of this serializer
* @throws IOException in case of problem saving resources
*/
public String asXml(final DomElement node) throws IOException {
builder_.setLength(0);
indent_.setLength(0);
final SgmlPage page = node.getPage();
if (null != page && page.isHtmlPage()) {
final Charset charsetName = page.getCharset();
if (charsetName != null && node instanceof HtmlHtml) {
builder_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>\n");
}
}
printXml(node);
final String response = builder_.toString();
builder_.setLength(0);
return response;
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class ScriptElementSupport method isExecutionNeeded.
/**
* Indicates if script execution is necessary and/or possible.
*
* @param element the element
* @param ignoreAttachedToPage don't do the isAttachedToPage check
* @param ignorePageIsAncestor don't do the element.getPage().isAncestorOf(element) check
* @return {@code true} if the script should be executed
*/
private static boolean isExecutionNeeded(final DomElement element, final boolean ignoreAttachedToPage, final boolean ignorePageIsAncestor) {
final ScriptElement script = (ScriptElement) element;
if (script.isExecuted() || script.wasCreatedByDomParser()) {
return false;
}
if (!ignoreAttachedToPage && !element.isAttachedToPage()) {
return false;
}
// If JavaScript is disabled, we don't need to execute.
final SgmlPage page = element.getPage();
if (!page.getWebClient().isJavaScriptEnabled()) {
return false;
}
// If innerHTML or outerHTML is being parsed
final HtmlPage htmlPage = element.getHtmlPageOrNull();
if (htmlPage != null && htmlPage.isParsingHtmlSnippet()) {
return false;
}
// If the script node is nested in an iframe, a noframes, or a noscript node, we don't need to execute.
for (DomNode o = element; o != null; o = o.getParentNode()) {
if (o instanceof HtmlInlineFrame || o instanceof HtmlNoFrames) {
return false;
}
}
// because another script set window.location.href), and we don't need to execute.
if (page.getEnclosingWindow() != null && page.getEnclosingWindow().getEnclosedPage() != page) {
return false;
}
// If the script language is not JavaScript, we can't execute.
final String t = element.getAttributeDirect("type");
final String l = element.getAttributeDirect("language");
if (!isJavaScript(element, t, l)) {
// Browsers are also not warning about this.
if (LOG.isDebugEnabled()) {
LOG.debug("Script is not JavaScript (type: '" + t + "', language: '" + l + "'). Skipping execution.");
}
return false;
}
// If it isn't yet part of the page, don't execute the script; it's probably just being cloned.
return ignorePageIsAncestor || element.getPage().isAncestorOf(element);
}
Aggregations