Java Code Examples for com.gargoylesoftware.htmlunit.html.DomNode#getLocalName()

The following examples show how to use com.gargoylesoftware.htmlunit.html.DomNode#getLocalName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLDocument.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@JsxFunction
public HTMLCollection getElementsByTagName(final String tagName) {
    final DomNode firstChild = getDomNodeOrDie().getFirstChild();
    if (firstChild == null) {
        return HTMLCollection.emptyCollection(getWindow().getDomNodeOrDie());
    }

    final HTMLCollection collection = new HTMLCollection(getDomNodeOrDie(), false) {
        @Override
        protected boolean isMatching(final DomNode node) {
            final String nodeName;
            if (getBrowserVersion().hasFeature(JS_XML_GET_ELEMENTS_BY_TAG_NAME_LOCAL)) {
                nodeName = node.getLocalName();
            }
            else {
                nodeName = node.getNodeName();
            }

            return nodeName.equals(tagName);
        }
    };

    return collection;
}
 
Example 2
Source File: HTMLElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the DOM node that corresponds to this JavaScript object.
 * @param domNode the DOM node
 */
@Override
public void setDomNode(final DomNode domNode) {
    super.setDomNode(domNode);

    final String name = domNode.getLocalName();
    if ("wbr".equalsIgnoreCase(name)
            || "basefont".equalsIgnoreCase(name)
            || "keygen".equalsIgnoreCase(name)
            || "track".equalsIgnoreCase(name)) {
        endTagForbidden_ = true;
    }

    if ("input".equalsIgnoreCase(name)
            || "button".equalsIgnoreCase(name)
            || "textarea".equalsIgnoreCase(name)
            || "select".equalsIgnoreCase(name)) {
        final HtmlForm form = ((HtmlElement) domNode).getEnclosingForm();
        if (form != null) {
            setParentScope(getScriptableFor(form));
        }
    }
}
 
Example 3
Source File: HTMLElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String getLocalName() {
    final DomNode domNode = getDomNodeOrDie();
    if (domNode.getHtmlPageOrNull() != null) {
        final String prefix = domNode.getPrefix();
        if (prefix != null) {
            // create string builder only if needed (performance)
            final StringBuilder localName = new StringBuilder(prefix.toLowerCase(Locale.ROOT))
                .append(':')
                .append(domNode.getLocalName().toLowerCase(Locale.ROOT));
            return localName.toString();
        }
        return domNode.getLocalName().toLowerCase(Locale.ROOT);
    }
    return domNode.getLocalName();
}
 
Example 4
Source File: XMLDocument.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@JsxFunction
public HTMLCollection getElementsByTagName(final String tagName) {
    final DomNode firstChild = getDomNodeOrDie().getFirstChild();
    if (firstChild == null) {
        return HTMLCollection.emptyCollection(getWindow().getDomNodeOrDie());
    }

    final HTMLCollection collection = new HTMLCollection(getDomNodeOrDie(), false) {
        @Override
        protected boolean isMatching(final DomNode node) {
            final String nodeName;
            if (getBrowserVersion().hasFeature(JS_XML_GET_ELEMENTS_BY_TAG_NAME_LOCAL)) {
                nodeName = node.getLocalName();
            }
            else {
                nodeName = node.getNodeName();
            }

            return nodeName.equals(tagName);
        }
    };

    return collection;
}
 
Example 5
Source File: HTMLElement.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String getLocalName() {
    final DomNode domNode = getDomNodeOrDie();
    if (domNode.getHtmlPageOrNull() != null) {
        final String prefix = domNode.getPrefix();
        if (prefix != null) {
            // create string builder only if needed (performance)
            final StringBuilder localName = new StringBuilder(prefix.toLowerCase(Locale.ROOT));
            localName.append(':');
            localName.append(domNode.getLocalName().toLowerCase(Locale.ROOT));
            return localName.toString();
        }
        return domNode.getLocalName().toLowerCase(Locale.ROOT);
    }
    return domNode.getLocalName();
}
 
Example 6
Source File: XMLDOMNode.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the base name for the name qualified with the namespace.
 * @return the base name for the name qualified with the namespace
 */
@JsxGetter
public String getBaseName() {
    final DomNode domNode = getDomNodeOrDie();
    final String baseName = domNode.getLocalName();
    if (baseName == null) {
        return "";
    }
    return baseName;
}
 
Example 7
Source File: HTMLElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the DOM node that corresponds to this JavaScript object.
 * @param domNode the DOM node
 */
@Override
public void setDomNode(final DomNode domNode) {
    super.setDomNode(domNode);

    final String name = domNode.getLocalName();
    if ("wbr".equalsIgnoreCase(name)
            || "basefont".equalsIgnoreCase(name)
            || "keygen".equalsIgnoreCase(name)
            || "track".equalsIgnoreCase(name)) {
        endTagForbidden_ = true;
    }
}
 
Example 8
Source File: XMLDOMNode.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the base name for the name qualified with the namespace.
 * @return the base name for the name qualified with the namespace
 */
@JsxGetter
public String getBaseName() {
    final DomNode domNode = getDomNodeOrDie();
    final String baseName = domNode.getLocalName();
    if (baseName == null) {
        return "";
    }
    return baseName;
}