Package com.gargoylesoftware.htmlunit.html

Examples of com.gargoylesoftware.htmlunit.html.DomNode


                case Node.TEXT_NODE:
                    String value = child.getNodeValue();
                    value = StringUtils.escapeXmlChars(value);
                    if (isIE && value.trim().length() == 0) {
                        buffer.append('\r').append('\n');
                        final DomNode sibling = child.getNextSibling();
                        if (sibling != null && sibling.getNodeType() == Node.ELEMENT_NODE) {
                            for (int i = 0; i < indent; i++) {
                                buffer.append('\t');
                            }
                        }
                    }
View Full Code Here


                return selects(cs.getSimpleSelector(), element) && parent != null
                    && selects(cs.getAncestorSelector(), parent);
            case Selector.SAC_DESCENDANT_SELECTOR:
                final DescendantSelector ds = (DescendantSelector) selector;
                if (selects(ds.getSimpleSelector(), element)) {
                    DomNode ancestor = element.getParentNode();
                    while (ancestor instanceof HtmlElement) {
                        if (selects(ds.getAncestorSelector(), (HtmlElement) ancestor)) {
                            return true;
                        }
                        ancestor = ancestor.getParentNode();
                    }
                }
                return false;
            case Selector.SAC_CONDITIONAL_SELECTOR:
                final ConditionalSelector conditional = (ConditionalSelector) selector;
                final Condition condition = conditional.getCondition();
                return selects(conditional.getSimpleSelector(), element) && selects(condition, element);
            case Selector.SAC_ELEMENT_NODE_SELECTOR:
                final ElementSelector es = (ElementSelector) selector;
                final String name = es.getLocalName();
                return name == null || tagName.equalsIgnoreCase(name);
            case Selector.SAC_ROOT_NODE_SELECTOR:
                return HtmlHtml.TAG_NAME.equalsIgnoreCase(tagName);
            case Selector.SAC_DIRECT_ADJACENT_SELECTOR:
                final SiblingSelector ss = (SiblingSelector) selector;
                final DomNode prev = element.getPreviousSibling();
                return prev instanceof HtmlElement
                    && selects(ss.getSelector(), (HtmlElement) prev)
                    && selects(ss.getSiblingSelector(), element);
            case Selector.SAC_NEGATIVE_SELECTOR:
                final NegativeSelector ns = (NegativeSelector) selector;
View Full Code Here

     */
    public String jsxGet_href() {
        final BrowserVersion version = getBrowserVersion();

        if (ownerNode_ != null) {
            final DomNode node = ownerNode_.getDomNodeOrDie();
            if (node instanceof HtmlLink) {
                // <link rel="stylesheet" type="text/css" href="..." />
                final HtmlLink link = (HtmlLink) node;
                final HtmlPage page = (HtmlPage) link.getPage();
                final String href = link.getHrefAttribute();
                if (!version.hasFeature(BrowserVersionFeatures.STYLESHEET_HREF_EXPANDURL)) {
                    // Don't expand relative URLs.
                    return href;
                }
                // Expand relative URLs.
                try {
                    final URL url = page.getFullyQualifiedUrl(href);
                    return url.toExternalForm();
                }
                catch (final MalformedURLException e) {
                    // Log the error and fall through to the return values below.
                    LOG.warn(e.getMessage(), e);
                }
            }
        }

        // <style type="text/css"> ... </style>
        if (version.hasFeature(BrowserVersionFeatures.STYLESHEET_HREF_STYLE_EMPTY)) {
            return "";
        }
        else if (version.hasFeature(BrowserVersionFeatures.STYLESHEET_HREF_STYLE_NULL)) {
            return null;
        }
        else {
            final DomNode node = ownerNode_.getDomNodeOrDie();
            final HtmlPage page = (HtmlPage) node.getPage();
            final URL url = page.getWebResponse().getRequestSettings().getUrl();
            return url.toExternalForm();
        }
    }
View Full Code Here

            // Apparently it wasn't a stylesheet that changed; be semi-smart about what we evict and when.
            synchronized (computedStyles_) {
                final Iterator<Map.Entry<Node, ComputedCSSStyleDeclaration>> i = computedStyles_.entrySet().iterator();
                while (i.hasNext()) {
                    final Map.Entry<Node, ComputedCSSStyleDeclaration> entry = i.next();
                    final DomNode node = entry.getKey().getDomNodeOrDie();
                    if (changed == node
                        || changed.getParentNode() == node.getParentNode()
                        || changed.isAncestorOf(node)) {
                        i.remove();
                    }
                }
            }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public DomDocumentFragment extractContents() throws DOMException {
        // Clone the common ancestor.
        final DomNode ancestor = (DomNode) getCommonAncestorContainer();
        final DomNode ancestorClone = ancestor.cloneNode(true);

        // Find the start container and end container clones.
        DomNode startClone = null;
        DomNode endClone = null;
        final DomNode start = (DomNode) startContainer_;
        final DomNode end = (DomNode) endContainer_;
        if (start == ancestor) {
            startClone = ancestorClone;
        }
        if (end == ancestor) {
            endClone = ancestorClone;
        }
        final Iterable< DomNode > descendants = ancestor.getDescendants();
        if (startClone == null || endClone == null) {
            final Iterator<DomNode> i = descendants.iterator();
            final Iterator<DomNode> ci = ancestorClone.getDescendants().iterator();
            while (i.hasNext()) {
                final DomNode e = i.next();
                final DomNode ce = ci.next();
                if (start == e) {
                    startClone = ce;
                }
                else if (end == e) {
                    endClone = ce;
                    break;
                }
            }
        }

        // Remove everything prior to the selection start from the clones.
        if (startClone == null) {
            throw Context.reportRuntimeError("Unable to find start node clone.");
        }
        deleteBefore(startClone, startOffset_);
        for (DomNode n = startClone; n != null; n = n.getParentNode()) {
            for (DomNode prev = n.getPreviousSibling(); prev != null; prev = prev.getPreviousSibling()) {
                prev.remove();
            }
        }

        // Remove everything following the selection end from the clones.
        if (endClone == null) {
            throw Context.reportRuntimeError("Unable to find end node clone.");
        }
        deleteAfter(endClone, endOffset_);
        for (DomNode n = endClone; n != null; n = n.getParentNode()) {
            for (DomNode next = n.getNextSibling(); next != null; next = next.getNextSibling()) {
                next.remove();
            }
        }

        // Remove everything inside the range from the original nodes.
        boolean foundStartNode = (ancestor == start); // whether or not we have found the start node yet
        boolean started = false; // whether or not we have found the start node *and* start offset yet
        boolean foundEndNode = false; // whether or not we have found the end node yet
        final Iterator<DomNode> i = ancestor.getDescendants().iterator();
        while (i.hasNext()) {
            final DomNode n = i.next();
            if (!foundStartNode) {
                foundStartNode = (n == start);
                if (foundStartNode && isOffsetChars(n)) {
                    started = true;
                    String text = getText(n);
                    text = text.substring(0, startOffset_);
                    setText(n, text);
                }
            }
            else if (!started) {
                final boolean atStart = (n.getParentNode() == start && n.getIndex() == startOffset_);
                final boolean beyondStart = !start.isAncestorOf(n);
                started = (atStart || beyondStart);
            }
            if (started) {
                if (!foundEndNode) {
                    foundEndNode = (n == end);
                }
                if (!foundEndNode) {
                    // We're inside the range.
                    if (!n.isAncestorOfAny(start, end)) {
                        i.remove();
                    }
                }
                else {
                    // We've reached the end of the range.
                    if (isOffsetChars(n)) {
                        String text = getText(n);
                        text = text.substring(endOffset_);
                        setText(n, text);
                    }
                    else {
                        final DomNodeList< DomNode > children = n.getChildNodes();
                        for (int j = endOffset_ - 1; j >= 0; j--) {
                            children.get(j).remove();
                        }
                    }
                    break;
View Full Code Here

                sb.append(getText(startContainer_).substring(startOffset_, endOffset_));
                return;
            }
        }

        final DomNode ancestor = (DomNode) getCommonAncestorContainer();
        final DomNode start = (DomNode) startContainer_;
        final DomNode end = (DomNode) endContainer_;
        boolean foundStartNode = (ancestor == start); // whether or not we have found the start node yet
        boolean started = false; // whether or not we have found the start node *and* start offset yet
        boolean foundEndNode = false; // whether or not we have found the end node yet
        final Iterator<DomNode> i = ancestor.getDescendants().iterator();
        while (i.hasNext()) {
            final DomNode n = i.next();
            if (!foundStartNode) {
                foundStartNode = (n == start);
                if (foundStartNode && isOffsetChars(n)) {
                    started = true;
                    String text = getText(n);
                    text = text.substring(startOffset_);
                    sb.append(text);
                }
            }
            else if (!started) {
                final boolean atStart = (n.getParentNode() == start && n.getIndex() == startOffset_);
                final boolean beyondStart = !start.isAncestorOf(n);
                started = (atStart || beyondStart);
            }
            if (started) {
                if (!foundEndNode) {
                    foundEndNode = (n == end);
                }
                if (!foundEndNode) {
                    // We're inside the range.
                    if (!n.isAncestorOfAny(start, end) && isOffsetChars(n)) {
                        sb.append(getText(n));
                    }
                }
                else {
                    // We've reached the end of the range.
                    if (isOffsetChars(n)) {
                        String text = getText(n);
                        text = text.substring(0, endOffset_);
                        sb.append(text);
                    }
                    else {
                        final DomNodeList<DomNode> children = n.getChildNodes();
                        for (int j = 0; j < endOffset_; j++) {
                            sb.append(getText(children.get(j)));
                        }
                    }
                    break;
View Full Code Here

            setText(node, text);
        }
        else {
            final DomNodeList<DomNode> children = node.getChildNodes();
            for (int i = 0; i < offset && i < children.getLength(); i++) {
                final DomNode child = children.get(i);
                child.remove();
                i--;
                offset--;
            }
        }
    }
View Full Code Here

            setText(node, text);
        }
        else {
            final DomNodeList<DomNode> children = node.getChildNodes();
            for (int i = offset; i < children.getLength(); i++) {
                final DomNode child = children.get(i);
                child.remove();
                i--;
            }
        }
    }
View Full Code Here

     * Returns all the descendant elements with the specified tag name.
     * @param tagName the name to search for
     * @return all the descendant elements with the specified tag name
     */
    public Object jsxFunction_getElementsByTagName(final String tagName) {
        final DomNode domNode = getDomNodeOrDie();
        final HTMLCollection collection = new HTMLCollection(this);
        collection.init(domNode, ".//*[local-name()='" + tagName + "']");
        return collection;
    }
View Full Code Here

     * @param localName is either the local name of elements to look for or the special value "*",
     *                  which matches all elements.
     * @return a live NodeList of found elements in the order they appear in the tree
     */
    public Object jsxFunction_getElementsByTagNameNS(final Object namespaceURI, final String localName) {
        final DomNode domNode = getDomNodeOrDie();
        final HTMLCollection collection = new HTMLCollection(this);
        final String xpath;
        if (namespaceURI == null || namespaceURI.equals("*")) {
            xpath = ".//" + localName;
        }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.html.DomNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.