List of usage examples for com.google.gwt.xml.client Node hasChildNodes
boolean hasChildNodes();
Node has any child nodes. From source file:client.net.sf.saxon.ce.xmldom.XMLParser.java
License:Mozilla Public License
private static void removeWhitespaceInner(Node n, Node parent) { // This n is removed from the parent if n is a whitespace node if (parent != null && n instanceof Text && (!(n instanceof CDATASection))) { Text t = (Text) n; if (t.getData().matches("[ \t\n]*")) { parent.removeChild(t);//from ww w. jav a 2 s. c o m } } if (n.hasChildNodes()) { int length = n.getChildNodes().getLength(); List<Node> toBeProcessed = new ArrayList<Node>(); // We collect all the nodes to iterate as the child nodes will change // upon removal for (int i = 0; i < length; i++) { toBeProcessed.add(n.getChildNodes().item(i)); } // This changes the child nodes, but the iterator of nodes never changes // meaning that this is safe for (Node childNode : toBeProcessed) { removeWhitespaceInner(childNode, n); } } }
From source file:com.codenvy.editor.api.editor.common.ContentFormatter.java
License:Apache License
/** * Transform children nodes of xml node to text format. * * @param node/*w w w. j a v a 2 s .c o m*/ * node that contains children which need to be formatted * @param depth * depth of parent node in xml * @return children nodes in text format */ @NotNull private static String transformChildrenNodes(@NotNull Node node, int depth) { StringBuilder text = new StringBuilder(); NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node currentNode = nodeList.item(i); if (isTextNode(currentNode)) { text.append(currentNode.toString()); } else if (currentNode.hasChildNodes()) { text.append(parseXMLNode(currentNode, depth + 1)); } else { text.append('\n').append(createTab(depth + 1)).append(currentNode); } } return text.toString(); }
From source file:com.codenvy.editor.api.editor.common.ContentFormatter.java
License:Apache License
/** * Returns whether a node has a text child node. * * @param node/*from ww w . j av a 2 s .c om*/ * node that need to be checked * @return <code>true</code> if a node has a text child node, and <code>false</code> otherwise */ private static boolean hasTextChildNode(@NotNull Node node) { if (node.hasChildNodes()) { Node child = node.getChildNodes().item(0); return isTextNode(child); } return false; }
From source file:com.codenvy.ide.client.common.ContentFormatter.java
License:Open Source License
/** * Transform children nodes of xml node to text format. * * @param node/*from w ww .j a v a 2 s. c o m*/ * node that contains children which need to be formatted * @param depth * depth of parent node in xml * @return children nodes in text format */ @Nonnull private static String transformChildrenNodes(@Nonnull Node node, @Nonnegative int depth) { StringBuilder text = new StringBuilder(); NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node currentNode = nodeList.item(i); if (isTextNode(currentNode)) { text.append(currentNode.toString()); } else if (currentNode.hasChildNodes()) { text.append(parseXMLNode(currentNode, depth + 1)); } else { text.append('\n').append(createTab(depth + 1)).append(currentNode); } } return text.toString(); }
From source file:com.codenvy.ide.client.common.ContentFormatter.java
License:Open Source License
/** * Returns whether a node has a text child node. * * @param node//from w w w. j a va2 s.co m * node that need to be checked * @return <code>true</code> if a node has a text child node, and <code>false</code> otherwise */ private static boolean hasTextChildNode(@Nonnull Node node) { if (node.hasChildNodes()) { Node child = node.getChildNodes().item(0); return isTextNode(child); } return false; }
From source file:com.codenvy.ide.client.elements.mediators.Call.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w . j a v a 2s.com public void deserialize(@Nonnull Node node) { super.deserialize(node); if (!node.hasChildNodes()) { putProperty(ENDPOINT_TYPE, NONE); } if (branches.isEmpty()) { Branch branch = branchProvider.get(); branch.setParent(this); branches.add(branch); } }
From source file:com.codenvy.ide.client.elements.mediators.Call.java
License:Open Source License
/** {@inheritDoc} */ @Override// w w w .j a v a 2 s .c om protected void applyProperty(@Nonnull Node node) { isKeyAttributeFound = false; isKeyExpressionAttributeFound = false; readXMLAttributes(node); if (isKeyAttributeFound) { putProperty(ENDPOINT_TYPE, REGISTRYKEY); } else if (isKeyExpressionAttributeFound) { putProperty(ENDPOINT_TYPE, XPATH); } else { putProperty(ENDPOINT_TYPE, INLINE); } Branch branch = branchProvider.get(); branch.setParent(this); if (node.hasChildNodes()) { Node item = node.getChildNodes().item(0); Element element = createElement(item.getNodeName()); if (element != null) { element.deserialize(node); branch.addElement(element); } } branches.add(branch); }
From source file:com.codenvy.ide.client.elements.mediators.enrich.Source.java
License:Open Source License
/** * Apply properties from XML node to the diagram element * * @param node/*from w w w. j a va 2 s . co m*/ * XML node that need to be analyzed */ public void applyProperty(@Nonnull Node node) { readXMLAttributes(node); String sourceXML = getProperty(SOURCE_XML); if (sourceXML == null || !node.hasChildNodes()) { return; } String item = node.getChildNodes().item(0).toString(); int indexFirst = item.indexOf(" "); int indexLast = item.indexOf(">"); String tagName = item.substring(0, indexLast); String xmlns = tagName.substring(indexFirst, tagName.contains("/") ? indexLast - 1 : indexLast); sourceXML = item.replace(xmlns, ""); putProperty(SOURCE_XML, sourceXML); }
From source file:com.codenvy.ide.client.elements.mediators.Header.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from www. ja v a 2s.c o m*/ public void deserialize(@Nonnull Node node) { isFirstNamespace = true; readXMLAttributes(node); if (node.hasChildNodes()) { String item = node.getChildNodes().item(0).toString(); int indexFirst = item.indexOf(" "); int indexLast = item.indexOf(">"); String tagName = item.substring(0, indexLast); String xmlns = tagName.substring(indexFirst, tagName.contains("/") ? indexLast - 1 : indexLast); String inlineXml = item.replace(xmlns, ""); putProperty(INLINE_XML, inlineXml); putProperty(VALUE_TYPE, INLINE); } }
From source file:com.codenvy.ide.client.elements.mediators.payload.Format.java
License:Open Source License
/** * Apply properties from XML node to the diagram element * * @param node//from ww w . j ava2s . c o m * XML node that need to be analyzed */ public void applyProperty(@Nonnull Node node) { if (!node.hasChildNodes()) { return; } putProperty(FORMAT_INLINE, convertNodeToString(node)); }