use of com.gargoylesoftware.htmlunit.SgmlPage 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.SgmlPage 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();
}
use of com.gargoylesoftware.htmlunit.SgmlPage in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method initialize.
/**
* Initializes this window.
* @param webWindow the web window corresponding to this window
* @param pageToEnclose the page that will become the enclosing page
*/
public void initialize(final WebWindow webWindow, final Page pageToEnclose) {
webWindow_ = webWindow;
webWindow_.setScriptableObject(this);
windowProxy_ = new WindowProxy(webWindow_);
if (pageToEnclose instanceof XmlPage) {
document_ = new XMLDocument();
} else {
document_ = new HTMLDocument();
}
document_.setParentScope(this);
document_.setPrototype(getPrototype(document_.getClass()));
document_.setWindow(this);
if (pageToEnclose instanceof SgmlPage) {
final SgmlPage page = (SgmlPage) pageToEnclose;
document_.setDomNode(page);
if (page.isHtmlPage()) {
final HtmlPage htmlPage = (HtmlPage) page;
htmlPage.addAutoCloseable(this);
}
}
documentProxy_ = new DocumentProxy(webWindow_);
navigator_ = new Navigator();
navigator_.setParentScope(this);
navigator_.setPrototype(getPrototype(navigator_.getClass()));
screen_ = new Screen(getWebWindow().getScreen());
screen_.setParentScope(this);
screen_.setPrototype(getPrototype(screen_.getClass()));
history_ = new History();
history_.setParentScope(this);
history_.setPrototype(getPrototype(history_.getClass()));
location_ = new Location();
location_.setParentScope(this);
location_.setPrototype(getPrototype(location_.getClass()));
location_.initialize(this, pageToEnclose);
final Console console = new Console();
console.setWebWindow(webWindow_);
console.setParentScope(this);
console.setPrototype(getPrototype(console.getClass()));
console_ = console;
applicationCache_ = new ApplicationCache();
applicationCache_.setParentScope(this);
applicationCache_.setPrototype(getPrototype(applicationCache_.getClass()));
// like a JS new Object()
final Context ctx = Context.getCurrentContext();
controllers_ = ctx.newObject(this);
if (webWindow_ instanceof TopLevelWindow) {
final WebWindow opener = ((TopLevelWindow) webWindow_).getOpener();
if (opener != null) {
opener_ = opener.getScriptableObject();
}
}
}
use of com.gargoylesoftware.htmlunit.SgmlPage 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.SgmlPage in project htmlunit by HtmlUnit.
the class HtmlSerializerNormalizedText method appendInlineFrame.
/**
* Process {@link HtmlInlineFrame}.
*
* @param builder the StringBuilder to add to
* @param htmlInlineFrame the target to process
*/
protected void appendInlineFrame(final HtmlSerializerTextBuilder builder, final HtmlInlineFrame htmlInlineFrame) {
if (isVisible(htmlInlineFrame)) {
builder.appendBlockSeparator();
final Page page = htmlInlineFrame.getEnclosedPage();
if (page instanceof SgmlPage) {
builder.append(((SgmlPage) page).asNormalizedText(), Mode.NORMALIZE);
}
builder.appendBlockSeparator();
}
}
Aggregations