use of com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentFragment in project htmlunit by HtmlUnit.
the class XSLTProcessor method transformToFragment.
/**
* Transforms the node source applying the stylesheet given by the importStylesheet() function.
* The owner document of the output node owns the returned document fragment.
* @param source the node to be transformed
* @param output This document is used to generate the output
* @return the result of the transformation
*/
@JsxFunction
public DocumentFragment transformToFragment(final Node source, final Object output) {
final SgmlPage page = (SgmlPage) ((Document) output).getDomNodeOrDie();
final DomDocumentFragment fragment = page.createDocumentFragment();
final DocumentFragment rv = new DocumentFragment();
rv.setPrototype(getPrototype(rv.getClass()));
rv.setParentScope(getParentScope());
rv.setDomNode(fragment);
transform(source, fragment);
return rv;
}
use of com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentFragment in project htmlunit by HtmlUnit.
the class HTMLTemplateElement method getContent.
/**
* @return the value of the {@code content} property
*/
@JsxGetter
public DocumentFragment getContent() {
final DocumentFragment result = new DocumentFragment();
result.setPrototype(getPrototype(result.getClass()));
result.setParentScope(getParentScope());
result.setDomNode(((HtmlTemplate) getDomNodeOrDie()).getContent());
return result;
}
use of com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentFragment in project htmlunit by HtmlUnit.
the class XMLSerializer method serializeToString.
/**
* The subtree rooted by the specified element is serialized to a string.
* @param root the root of the subtree to be serialized (this may be any node, even a document)
* @return the serialized string
*/
@JsxFunction
public String serializeToString(Node root) {
if (root == null) {
return "";
}
if (root instanceof DocumentFragment) {
if (root.getOwnerDocument() instanceof HTMLDocument && getBrowserVersion().hasFeature(JS_XML_SERIALIZER_HTML_DOCUMENT_FRAGMENT_ALWAYS_EMPTY)) {
return "";
}
Node node = root.getFirstChild();
if (node == null) {
return "";
}
final StringBuilder builder = new StringBuilder();
while (node != null) {
builder.append(serializeToString(node));
node = node.getNextSibling();
}
return builder.toString();
}
if (root instanceof Document) {
root = ((Document) root).getDocumentElement();
}
if (root instanceof Element) {
final StringBuilder builder = new StringBuilder();
final DomNode node = root.getDomNodeOrDie();
final SgmlPage page = node.getPage();
final boolean isHtmlPage = page != null && page.isHtmlPage();
String forcedNamespace = null;
if (isHtmlPage) {
forcedNamespace = "http://www.w3.org/1999/xhtml";
}
toXml(1, node, builder, forcedNamespace);
return builder.toString();
}
if (root instanceof CDATASection && getBrowserVersion().hasFeature(JS_XML_SERIALIZER_ROOT_CDATA_AS_ESCAPED_TEXT)) {
final DomCDataSection domCData = (DomCDataSection) root.getDomNodeOrDie();
final String data = domCData.getData();
if (org.apache.commons.lang3.StringUtils.isNotBlank(data)) {
return StringUtils.escapeXmlChars(data);
}
}
return root.getDomNodeOrDie().asXml();
}
Aggregations