/** * Returns an <code>Iterator</code> of the children of the node. * * @return the iterator of the nodes children */ public Iterator iterator() { return children().iterator(); }
protected void addTextToNode() { if (parent == null) { // TODO store this on root node? reset bodyText? return; } String text = bodyText.toString(); if (!trimWhitespace && keepIgnorableWhitespace) { parent.children().add(text); } else if (!trimWhitespace && text.trim().length() > 0) { parent.children().add(text); } else if (text.trim().length() > 0) { parent.children().add(text.trim()); } bodyText = new StringBuilder(); }
private boolean isEmptyElement(Node node) { if (node == null) { throw new IllegalArgumentException("Node must not be null!"); } if (!node.children().isEmpty()) { return false; } return node.text().length() == 0; }
private List getTail() { List list = parent().children(); int afterIndex = list.indexOf(this); List tail = new ArrayList(list.subList(afterIndex + 1, list.size())); list.subList(afterIndex + 1, list.size()).clear(); return tail; }
private static List<Node> buildChildrenFromClosure(Closure c) { NodeBuilder b = new NodeBuilder(); Node newNode = (Node) b.invokeMethod("dummyNode", c); return newNode.children(); }
/** * Provides lookup of elements by non-namespaced name * * @param key the name (or shortcut key) of the node(s) of interest * @return the nodes which match key */ public Object get(String key) { if (key != null && key.charAt(0) == '@') { String attributeName = key.substring(1); return attributes().get(attributeName); } if ("..".equals(key)) { return parent(); } if ("*".equals(key)) { return children(); } if ("**".equals(key)) { return depthFirst(); } return getByName(key); }
/** * Provides lookup of elements by QName. * * @param name the QName of interest * @return the nodes matching name */ public NodeList getAt(QName name) { NodeList answer = new NodeList(); for (Object child : children()) { if (child instanceof Node) { Node childNode = (Node) child; Object childNodeName = childNode.name(); if (name.matches(childNodeName)) { answer.add(childNode); } } } return answer; }
/** * Provides lookup of elements by name. * * @param name the name of interest * @return the nodes matching name */ private NodeList getByName(String name) { NodeList answer = new NodeList(); for (Object child : children()) { if (child instanceof Node) { Node childNode = (Node) child; Object childNodeName = childNode.name(); if (childNodeName instanceof QName) { QName qn = (QName) childNodeName; if (qn.matches(name)) { answer.add(childNode); } } else if (name.equals(childNodeName)) { answer.add(childNode); } } } return answer; }
private void appendNodes(Closure c) { List tail = getTail(); for (Node child : buildChildrenFromClosure(c)) { parent().appendNode(child.name(), child.attributes(), child.value()); } parent().children().addAll(tail); }
/** * Replaces the current node with the supplied node. * * @param n the new Node * @return the original now replaced node */ public Node replaceNode(Node n) { if (parent() == null) { throw new UnsupportedOperationException("Replacing the root node is not supported"); } List tail = getTail(); parent().appendNode(n.name(), n.attributes(), n.value()); parent().children().addAll(tail); getParentList(parent()).remove(this); this.setParent(null); return this; }
private void merge(Properties props, Node node, String prefix) { assert props != null; assert node != null; assert prefix != null; String name = prefix + node.name(); Object value = node.value(); if (value instanceof String) { props.setProperty(name, String.valueOf(value)); } Map attrs = node.attributes(); for (Object key : attrs.keySet()) { props.setProperty(name + "." + key, String.valueOf(attrs.get(key))); } for (Object child : node.children()) { if (child instanceof Node) { merge(props, (Node) child, name + "."); } } } }
nextElementsToDepthIncrease = 0; for (Node child : current.children()) { nodeQueue.add(child);
private Xpp3Dom nodeToXpp3(final Node node) { Xpp3Dom dom = new Xpp3Dom((String) node.name()); Object value = node.value(); if (value instanceof String) { dom.setValue(String.valueOf(value)); } Map attrs = node.attributes(); for (Object key : attrs.keySet()) { dom.setAttribute(String.valueOf(key), String.valueOf(attrs.get(key))); } for (Object child : node.children()) { if (child instanceof Node) { dom.addChild(nodeToXpp3((Node) child)); } } return dom; } }
@Override public boolean onNodeChildren(FactoryBuilderSupport builder, Object node, Closure content) { Xpp3Dom dom = (Xpp3Dom) node; NodeBuilder nodes = new NodeBuilder() { @Override protected void setClosureDelegate(final Closure c, final Object o) { c.setDelegate(this); c.setResolveStrategy(Closure.DELEGATE_FIRST); } @Override public void setProperty(final String name, final Object value) { this.invokeMethod(name, value); } }; content.setDelegate(nodes); content.setResolveStrategy(Closure.DELEGATE_FIRST); Node root = (Node) nodes.invokeMethod(getName(), content); for (Node child : (List<Node>) root.children()) { dom.addChild(nodeToXpp3(child)); } return false; }
protected void addTextToNode() { String text = bodyText.toString(); if (trimWhitespace) { text = text.trim(); } if (text.length() > 0) { parent.children().add(text); } bodyText = new StringBuffer(); }
private static boolean isEmptyElement(Node node) { if (node == null) { throw new IllegalArgumentException("Node must not be null!"); } if (!node.children().isEmpty()) { return false; } return node.text().length() == 0; }
private Node findChild(Node node, String name) { for (Object childObject : node.children()) { if ((childObject instanceof Node) && ((Node) childObject).name().equals(name)) { return (Node) childObject; } } return null; }
private boolean isEmptyElement(Node node) { if (node == null) { throw new IllegalArgumentException("Node must not be null!"); } if (!node.children().isEmpty()) { return false; } return node.text().length() == 0; }
private boolean isEmptyElement(Node node) { if (node == null) { throw new IllegalArgumentException("Node must not be null!"); } if (!node.children().isEmpty()) { return false; } return node.text().length() == 0; }
private List<Node> buildChildrenFromClosure(Closure c) { NodeBuilder b = new NodeBuilder(); Node newNode = (Node) b.invokeMethod("dummyNode", c); return newNode.children(); }