Search in sources :

Example 1 with Attr

use of com.gargoylesoftware.htmlunit.javascript.host.dom.Attr in project htmlunit by HtmlUnit.

the class Element method setAttributeNode.

/**
 * Sets the attribute node for the specified attribute.
 * @param newAtt the attribute to set
 * @return the replaced attribute node, if any
 */
@JsxFunction
public Attr setAttributeNode(final Attr newAtt) {
    final String name = newAtt.getName();
    final NamedNodeMap nodes = getAttributes();
    final Attr replacedAtt = (Attr) nodes.getNamedItemWithoutSytheticClassAttr(name);
    if (replacedAtt != null) {
        replacedAtt.detachFromParent();
    }
    final DomAttr newDomAttr = newAtt.getDomNodeOrDie();
    getDomNodeOrDie().setAttributeNode(newDomAttr);
    return replacedAtt;
}
Also used : NamedNodeMap(com.gargoylesoftware.htmlunit.javascript.NamedNodeMap) DomAttr(com.gargoylesoftware.htmlunit.html.DomAttr) DomAttr(com.gargoylesoftware.htmlunit.html.DomAttr) Attr(com.gargoylesoftware.htmlunit.javascript.host.dom.Attr) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 2 with Attr

use of com.gargoylesoftware.htmlunit.javascript.host.dom.Attr in project htmlunit by HtmlUnit.

the class XMLDocument method makeScriptableFor.

/**
 * {@inheritDoc}
 */
@Override
public HtmlUnitScriptable makeScriptableFor(final DomNode domNode) {
    final HtmlUnitScriptable scriptable;
    // TODO: cleanup, getScriptObject() should be used!!!
    if (domNode instanceof DomElement && !(domNode instanceof HtmlElement)) {
        if (domNode instanceof SvgElement) {
            final Class<? extends HtmlUnitScriptable> javaScriptClass = ((JavaScriptEngine) getWindow().getWebWindow().getWebClient().getJavaScriptEngine()).getJavaScriptClass(domNode.getClass());
            try {
                scriptable = javaScriptClass.newInstance();
            } catch (final Exception e) {
                throw Context.throwAsScriptRuntimeEx(e);
            }
        } else {
            scriptable = new Element();
        }
    } else if (domNode instanceof DomAttr) {
        scriptable = new Attr();
    } else {
        return super.makeScriptableFor(domNode);
    }
    scriptable.setPrototype(getPrototype(scriptable.getClass()));
    scriptable.setParentScope(getParentScope());
    scriptable.setDomNode(domNode);
    return scriptable;
}
Also used : HtmlUnitScriptable(com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) DomAttr(com.gargoylesoftware.htmlunit.html.DomAttr) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) SvgElement(com.gargoylesoftware.htmlunit.svg.SvgElement) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) SvgElement(com.gargoylesoftware.htmlunit.svg.SvgElement) Element(com.gargoylesoftware.htmlunit.javascript.host.Element) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) DOMException(com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException) IOException(java.io.IOException) Attr(com.gargoylesoftware.htmlunit.javascript.host.dom.Attr) DomAttr(com.gargoylesoftware.htmlunit.html.DomAttr) JavaScriptEngine(com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine)

Aggregations

DomAttr (com.gargoylesoftware.htmlunit.html.DomAttr)2 Attr (com.gargoylesoftware.htmlunit.javascript.host.dom.Attr)2 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)1 JavaScriptEngine (com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine)1 NamedNodeMap (com.gargoylesoftware.htmlunit.javascript.NamedNodeMap)1 JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)1 Element (com.gargoylesoftware.htmlunit.javascript.host.Element)1 DOMException (com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException)1 SvgElement (com.gargoylesoftware.htmlunit.svg.SvgElement)1 IOException (java.io.IOException)1