Search in sources :

Example 21 with DomText

use of com.gargoylesoftware.htmlunit.html.DomText 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);
    }
}
Also used : DomText(com.gargoylesoftware.htmlunit.html.DomText) Node(com.gargoylesoftware.htmlunit.javascript.host.dom.Node) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) NodeList(org.w3c.dom.NodeList) SgmlPage(com.gargoylesoftware.htmlunit.SgmlPage)

Example 22 with DomText

use of com.gargoylesoftware.htmlunit.html.DomText in project htmlunit by HtmlUnit.

the class HtmlSerializerNormalizedText method appendTitle.

/**
 * Process {@link HtmlTitle}.
 * @param builder the StringBuilder to add to
 * @param htmlTitle the target to process
 */
protected void appendTitle(final HtmlSerializerTextBuilder builder, final HtmlTitle htmlTitle) {
    // optimized version
    // for the title there is no need to check the visibility
    // of the containing dom text;
    // this optimization defers the load of the style sheets
    final DomNode child = htmlTitle.getFirstChild();
    if (child instanceof DomText) {
        builder.append(((DomText) child).getData(), Mode.NORMALIZE);
        builder.appendBlockSeparator();
    }
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomText(com.gargoylesoftware.htmlunit.html.DomText)

Example 23 with DomText

use of com.gargoylesoftware.htmlunit.html.DomText in project htmlunit by HtmlUnit.

the class Document method createTextNode.

/**
 * Create a new DOM text node with the given data.
 *
 * @param newData the string value for the text node
 * @return the new text node or NOT_FOUND if there is an error
 */
@JsxFunction
public Object createTextNode(final String newData) {
    Object result = NOT_FOUND;
    try {
        final DomNode domNode = new DomText(getDomNodeOrDie().getPage(), newData);
        final Object jsElement = getScriptableFor(domNode);
        if (jsElement == NOT_FOUND) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("createTextNode(" + newData + ") cannot return a result as there isn't a JavaScript object for the DOM node " + domNode.getClass().getName());
            }
        } else {
            result = jsElement;
        }
    } catch (final ElementNotFoundException e) {
    // Just fall through - result is already set to NOT_FOUND
    }
    return result;
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomText(com.gargoylesoftware.htmlunit.html.DomText) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) FunctionObject(net.sourceforge.htmlunit.corejs.javascript.FunctionObject) ElementNotFoundException(com.gargoylesoftware.htmlunit.ElementNotFoundException) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

DomText (com.gargoylesoftware.htmlunit.html.DomText)23 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)15 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)5 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)5 JsxSetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter)3 ArrayList (java.util.ArrayList)3 NodeList (org.w3c.dom.NodeList)3 ElementNotFoundException (com.gargoylesoftware.htmlunit.ElementNotFoundException)2 DomAttr (com.gargoylesoftware.htmlunit.html.DomAttr)2 DomCDataSection (com.gargoylesoftware.htmlunit.html.DomCDataSection)2 DomComment (com.gargoylesoftware.htmlunit.html.DomComment)2 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)2 DomProcessingInstruction (com.gargoylesoftware.htmlunit.html.DomProcessingInstruction)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)2 Node (com.gargoylesoftware.htmlunit.javascript.host.dom.Node)2 FunctionObject (net.sourceforge.htmlunit.corejs.javascript.FunctionObject)2 Test (org.junit.Test)2 DomDocumentFragment (com.gargoylesoftware.htmlunit.html.DomDocumentFragment)1 DomDocumentType (com.gargoylesoftware.htmlunit.html.DomDocumentType)1