Example usage for com.google.gwt.dom.client Node getChildNodes

List of usage examples for com.google.gwt.dom.client Node getChildNodes

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Node getChildNodes.

Prototype

@Override
    public NodeList<Node> getChildNodes() 

Source Link

Usage

From source file:bz.davide.dmxmljson.unmarshalling.dom.gwt.GWTDOMValue.java

License:Open Source License

void recursiveText(Node node, StringBuffer sb) {
    if (node.getNodeType() == Node.TEXT_NODE) {
        sb.append(node.getNodeValue());/*from  ww  w.ja  va  2 s.  c o  m*/
    }
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        NodeList<Node> nl = node.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            this.recursiveText(nl.getItem(i), sb);
        }
    }
}

From source file:client.net.sf.saxon.ce.dom.HTMLNodeWrapper.java

License:Mozilla Public License

private static void expandStringValue(NodeList list, StringBuffer sb) {
    final int len = list.getLength();
    for (int i = 0; i < len; i++) {
        Node child = list.getItem(i);
        switch (child.getNodeType()) {
        case Node.ELEMENT_NODE:
            expandStringValue(child.getChildNodes(), sb);
            break;
        case Type.COMMENT:
        case Type.PROCESSING_INSTRUCTION:
            break;
        default:/*w  w w  .j a  va2 s .  c o  m*/
            sb.append(getValue(child));
        }
    }
}

From source file:com.ephesoft.gxt.core.client.ui.widget.util.HTMLDomUtil.java

License:Open Source License

/**
 * Gets the <code> grandChildren </code> of a parent which is the nth child of a grandParent, where 'n' is the childNumber. If
 * child number is less than 1 it returns the grand children of the last child of grandparent.
 * //  w  ww  .  j  a  v  a2s .c  o  m
 * @param grandParent {@link Node} Element whose grandChildren needs to be returned. When NULL , null is returned.
 * @param childNumber int childNumber of the child whose children neeeds to be returned.
 * @return {@link NodeList} < @Node > which are all the grandChildren. NULL if child doesnot exist or has no children.
 */
public static NodeList<Node> getGrandChildren(Node grandParent, int childNumber) {
    NodeList<Node> grandChildren = null;
    if (grandParent != null) {
        Node childNode = null;
        if (childNumber > 0) {
            childNode = grandParent.getChild(childNumber - 1);
        } else {
            int totalChildren = grandParent.getChildCount();
            childNode = totalChildren > 0 ? grandParent.getChild(totalChildren - 1) : null;
        }
        grandChildren = childNode == null ? null : childNode.getChildNodes();
    }
    return grandChildren;
}

From source file:com.vaadin.client.ui.window.WindowConnector.java

License:Apache License

private Node cloneNodeFilteringMedia(Node node) {
    if (node instanceof Element) {
        Element old = (Element) node;
        if ("audio".equalsIgnoreCase(old.getTagName()) || "video".equalsIgnoreCase(old.getTagName())) {
            if (!old.hasAttribute("controls") && "audio".equalsIgnoreCase(old.getTagName())) {
                return null; // nothing to animate, so we won't add this to
                             // the clone
            }/*from www. java2  s.  co  m*/
            Element newEl = DOM.createElement(old.getTagName());
            if (old.hasAttribute("controls")) {
                newEl.setAttribute("controls", old.getAttribute("controls"));
            }
            if (old.hasAttribute("style")) {
                newEl.setAttribute("style", old.getAttribute("style"));
            }
            if (old.hasAttribute("class")) {
                newEl.setAttribute("class", old.getAttribute("class"));
            }
            return newEl;
        }
    }
    Node res = node.cloneNode(false);
    if (node.hasChildNodes()) {
        NodeList<Node> nl = node.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node clone = cloneNodeFilteringMedia(nl.getItem(i));
            if (clone != null) {
                res.appendChild(clone);
            }
        }
    }
    return res;
}

From source file:org.broadleafcommerce.openadmin.client.view.dynamic.form.RichTextHTMLPane.java

License:Apache License

public Node findIFrame(NodeList<Node> childNodes) {
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node item = childNodes.getItem(i);
        if (item instanceof Element && "IFRAME".equals(((Element) item).getTagName())) {
            return item;
        } else {//from  w  w w .  j  a  v a 2 s .  c o  m
            Node childIFrame = findIFrame(item.getChildNodes());
            if (childIFrame != null) {
                return childIFrame;
            }
        }
    }
    return null;
}

From source file:org.jboss.errai.common.client.dom.DOMUtil.java

License:Apache License

/**
 * Detaches all element children from a node.
 *
 * @param node//from   www  .  ja v a  2 s.  c  om
 *          Must not be null.
 * @return True iff any element children were detached by this call.
 */
public static boolean removeAllElementChildren(final Node node) {
    boolean elementRemoved = false;
    for (final Element child : elementIterable(node.getChildNodes())) {
        node.removeChild(child);
        elementRemoved = true;
    }

    return elementRemoved;
}

From source file:org.nsesa.editor.gwt.core.client.util.NodeUtil.java

License:EUPL

public static Text getText(final Node node, boolean includeChildren) {
    final NodeList<Node> childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.getItem(i);
        if (child.getNodeType() == Node.TEXT_NODE) {
            return (Text) child;
        } else if (child.getNodeType() == Node.ELEMENT_NODE) {
            return getText(child, includeChildren);

        }//from  www .  j  ava2 s  .co m
    }
    return null;
}

From source file:org.nsesa.editor.gwt.core.client.util.NodeUtil.java

License:EUPL

public static void walk(final Node node, final NodeVisitor visitor) {
    visitor.visit(node);//ww w .  j  a  v  a2  s.  c om
    final NodeList<Node> childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.getItem(i);
        walk(child, visitor);
    }
}

From source file:org.nuxeo.ecm.platform.annotations.gwt.client.util.Visitor.java

License:Apache License

public void visit(Node node) {
    if (startNode == node) {
        processing = true;/*w w  w .  j  a v a 2 s .  c  o m*/
    } else if (endNode == node) {
        processing = false;
    }
    if (processor.doBreak()) {
        return;
    }

    NodeList list = node.getChildNodes();
    if (list == null || list.getLength() == 0) {
        processIf(node);
    } else {
        int length = list.getLength();
        Node[] nodes = new Node[list.getLength()];
        for (int x = 0; x < length; x++) {
            nodes[x] = list.getItem(x);
        }
        processIf(node);
        for (int x = 0; x < length; x++) {
            visit(nodes[x]);
        }
    }

}

From source file:org.nuxeo.ecm.platform.annotations.gwt.client.util.XPathUtil.java

License:Apache License

public List<Node> getNode(String xpath, Document document) {
    List<Node> nodes = new ArrayList<Node>();
    if (xpath.startsWith("//")) {
        xpath = xpath.substring(2);/*from   w  w w .  j  a  va 2  s . c o  m*/
        NodeList<Element> n = document.getElementsByTagName(xpath);
        for (int x = 0; x < n.getLength(); x++) {
            nodes.add(n.getItem(x));
        }
        return nodes;
    }
    Log.debug("XPathUtil#getNode -- xpath: " + xpath);
    String[] paths = xpath.split("/");
    Node result = document;
    for (String path : paths) {
        if ("".equals(path)) {
            continue;
        }
        NodeList<Node> nodeList = result.getChildNodes();
        String name = path.substring(0, path.indexOf("["));
        int index = Integer.parseInt(path.substring(path.indexOf("[") + 1, path.indexOf("]")));
        int counter = 1;
        for (int x = 0; x < nodeList.getLength(); x++) {
            Node node = nodeList.getItem(x);
            if (node.getNodeName().equalsIgnoreCase(name)) {
                if (isIgnored(node)) {// considered as text node
                    continue;
                }
                if (counter == index) {
                    result = node;
                    break;
                }
                counter++;
            }
        }

    }
    nodes.add(result);
    Log.debug("XPathUtil#getNode -- end function: ");
    return nodes;
}