List of usage examples for com.google.gwt.dom.client Node hasChildNodes
@Override
public boolean hasChildNodes()
From source file:com.cgxlib.xq.client.impl.research.SelectorEngineJS.java
License:Apache License
private void getEmptyPseudo(JsNodeArray previousMatch, JsNodeArray matchingElms) { Node previous; for (int q = 0, qlen = previousMatch.size(); q < qlen; q++) { previous = previousMatch.getNode(q); if (!previous.hasChildNodes()) { matchingElms.addNode(previous); }/* w w w. jav a 2 s . co m*/ } }
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 }// w w w . j a v a 2 s.c o 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:de.catma.ui.client.ui.tagger.AffectedNodesFinder.java
License:Open Source License
/** * Recursively walks the tree depth first and creates a list of affected nodes. * @param curNode the (relative) root node to start with *///from w ww.j a v a2s.co m private void walk(Node curNode) { // check if we're still within the affected subtree // and the current node has any taggable content if (!this.outOfAffectedSubtree && ((curNode.getNodeValue() == null) || !curNode.getNodeValue().trim().isEmpty())) { // all text nodes gets added, in case we get into the affected subtree with this // node or one of its children if (curNode.getNodeType() == Node.TEXT_NODE) { affectedNodes.push(curNode); } // we check for children and go down the subtrees if (curNode.hasChildNodes()) { for (int i = 0; i < curNode.getChildCount(); i++) { walk(curNode.getChild(i)); } } // if we reach the outer left node // we're in the affacted subtree -> all parent nodes can stay on the stack else if (curNode.equals(outerLeftNode)) { this.inAffectedSubtree = true; } // if we reach the outer right node // we reject all the rest of the upcoming nodes else if (curNode.equals(outerRightNode)) { this.outOfAffectedSubtree = true; } // if the current node is a text node it has already been pushed onto the stack // and if we're not within the affected subtree, we're removing the current node from the stack // (not being in the affected subtree means neither the current node nor one of its // children is the outer left node) if (!inAffectedSubtree && (curNode.getNodeType() == Node.TEXT_NODE)) { affectedNodes.pop(); } } }
From source file:de.catma.ui.client.ui.tagger.editor.AffectedNodesFinder.java
License:Open Source License
/** * Recursively walks the tree depth first and creates a list of affected nodes. * @param curNode the (relative) root node to start with *///from w ww .j av a2 s .com private void walk(Node curNode) { VConsole.log("AffectedNodesFinder walking node: " + DebugUtil.getNodeInfo(curNode)); // check if we're still within the affected subtree // and the current node has any taggable content if (!this.outOfAffectedSubtree && ((curNode.getNodeValue() == null) || !curNode.getNodeValue().trim().isEmpty())) { // all text nodes gets added, in case we get into the affected subtree with this // node or one of its children if (curNode.getNodeType() == Node.TEXT_NODE) { VConsole.log("AffectedNodesFinder pushing text node: " + DebugUtil.getNodeInfo(curNode)); affectedNodes.push(curNode); } else { VConsole.log("no text node " + DebugUtil.getNodeInfo(curNode)); } // we check for children and go down the subtrees if (curNode.hasChildNodes()) { VConsole.log("AffectedNodesFinder walking down: " + DebugUtil.getNodeInfo(curNode)); for (int i = 0; i < curNode.getChildCount(); i++) { walk(curNode.getChild(i)); } } // if we reach the outer left node // we're in the affacted subtree -> all parent nodes can stay on the stack else if (curNode.equals(outerLeftNode)) { VConsole.log("AffectedNodesFinder outer left node reached: " + DebugUtil.getNodeInfo(curNode)); this.inAffectedSubtree = true; } // if we reach the outer right node // we reject all the rest of the upcoming nodes else if (curNode.equals(outerRightNode)) { VConsole.log("AffectedNodesFinder outer right node reached: " + DebugUtil.getNodeInfo(curNode)); this.outOfAffectedSubtree = true; } // if the current node is a text node it has already been pushed onto the stack // and if we're not within the affected subtree, we're removing the current node from the stack // (not being in the affected subtree means neither the current node nor one of its // children is the outer left node) if (!inAffectedSubtree && (curNode.getNodeType() == Node.TEXT_NODE)) { Node poppedNode = affectedNodes.pop(); VConsole.log("not in affected subtree, popped node " + DebugUtil.getNodeInfo(poppedNode)); } } }
From source file:de.catma.ui.client.ui.tagger.editor.LeafFinder.java
License:Open Source License
private Node descentLeft(Node node) { if (node.hasChildNodes()) { return descentLeft(node.getChild(node.getChildCount() - 1)); }/* ww w. j a va 2s.c o m*/ return node; }
From source file:de.catma.ui.client.ui.tagger.editor.LeafFinder.java
License:Open Source License
private Node descentRight(Node node) { if (node.hasChildNodes()) { return descentRight(node.getChild(0)); }/* w w w.j av a 2 s. c o m*/ return node; }
From source file:de.catma.ui.client.ui.tagger.editor.LeafFinder.java
License:Open Source License
public static Node getFirstTextLeaf(Node root) { VConsole.log("looking for first text leaf for root: " + DebugUtil.getNodeInfo(root)); if (root.hasChildNodes()) { Node candidate = root.getFirstChild(); while (candidate.hasChildNodes()) { candidate = candidate.getFirstChild(); }/*from www . j a va 2 s . c o m*/ VConsole.log("outer left child node: " + DebugUtil.getNodeInfo(candidate)); if (Element.is(candidate) || (candidate.getNodeValue().isEmpty())) { VConsole.log("outer left node is not a text leaf, we start searching to the right now"); LeafFinder leafFinder = new LeafFinder(candidate); // return leafFinder.getNextRightTextLeaf(); return leafFinder.getNextNonEmptyRightTextLeaf(); } else { return candidate; } } return null; }
From source file:de.catma.ui.client.ui.tagger.LeafFinder.java
License:Open Source License
public static Node getFirstTextLeaf(Node root) { if (root.hasChildNodes()) { Node candidate = root.getFirstChild(); while (candidate.hasChildNodes()) { candidate = candidate.getFirstChild(); }//from w ww .java 2s .com if (Element.is(candidate)) { LeafFinder leafFinder = new LeafFinder(candidate); return leafFinder.getNextRightTextLeaf(); } else { return candidate; } } return null; }
From source file:org.chromium.distiller.PageParameterParser.java
License:Open Source License
/** * Finds and adds the leaf node(s) closest to the given start node. * This recurses and keeps finding and, if necessary, adding the numeric text of valid nodes, * collecting the PageParamInfo.PageInfo's for the current adjacency group. * For backward search, i.e. nodes before start node, search terminates (i.e. recursion stops) * once a text node or anchor is encountered. If the text node contains numeric text, it's * added to the current adjacency group. Otherwise, a new group is created to break the * adjacency./*w ww. ja v a 2s . c om*/ * For forward search, i.e. nodes after start node, search continues (i.e. recursion continues) * until a text node or anchor with non-numeric text is encountered. In the process, text nodes * and anchors with numeric text are added to the current adjacency group. When a non-numeric * text node or anchor is encountered, a new group is started to break the adjacency, and search * ends. * * @return true to continue search, false to stop. * * @param start node to work on. * @param checkStart true to check start node. Otherwise, the previous or next sibling of the * start node is checked. * @param backward true to search backward (i.e. nodes before start node), false to search * forward (i.e. nodes after start node). * @param baseAnchor created for the current document, only needed for forward search. */ private boolean findAndAddClosestValidLeafNodes(Node start, boolean checkStart, boolean backward, AnchorElement baseAnchor) { Node node = checkStart ? start : (backward ? start.getPreviousSibling() : start.getNextSibling()); if (node == null) { // No sibling, try parent. node = start.getParentNode(); if (sInvalidParentWrapper == null) { sInvalidParentWrapper = RegExp.compile("(BODY)|(HTML)"); } if (sInvalidParentWrapper.test(node.getNodeName())) return false; return findAndAddClosestValidLeafNodes(node, false, backward, baseAnchor); } checkStart = false; switch (node.getNodeType()) { case Node.TEXT_NODE: String text = node.getNodeValue(); // Text must contain words. if (text.isEmpty() || StringUtil.countWords(text) == 0) break; boolean added = addNonLinkTextIfValid(node.getNodeValue()); // For backward search, we're done regardless if text was added. // For forward search, we're done only if text was invalid, otherwise continue. if (backward || !added) return false; break; case Node.ELEMENT_NODE: Element e = Element.as(node); if (e.hasTagName("A")) { // For backward search, we're done because we've already processed the anchor. if (backward) return false; // For forward search, we're done only if link was invalid, otherwise continue. mNumForwardLinksProcessed++; if (!addLinkIfValid(AnchorElement.as(e), baseAnchor)) return false; break; } // Intentionally fall through. default: // Check children nodes. if (!node.hasChildNodes()) break; checkStart = true; // We want to check the child node. if (backward) { // Start the backward search with the rightmost child i.e. last and closest to // given node. node = node.getLastChild(); } else { // Start the forward search with the leftmost child i.e. first and closest to // given node. node = node.getFirstChild(); } break; } return findAndAddClosestValidLeafNodes(node, checkStart, backward, baseAnchor); }
From source file:org.eclipse.che.ide.extension.machine.client.processes.ConsolesPanelViewImpl.java
License:Open Source License
/** * Improves splitter visibility./*from www . jav a 2s .co m*/ */ private void tuneSplitter() { NodeList<Node> nodes = splitLayoutPanel.getElement().getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.getItem(i); if (node.hasChildNodes()) { com.google.gwt.dom.client.Element el = node.getFirstChild().cast(); if ("gwt-SplitLayoutPanel-HDragger".equals(el.getClassName())) { tuneSplitter(el); return; } } } }