protected Object createNode(final String name) { final Element element = documentFactory.createElement(encodeNode(name)); final Branch top = top(); if (top != null) { top().add(element); } return element; }
@Override public void startTag(String tagName) { Branch top = stack.getLast(); Element element = top.addElement(tagName); stack.addLast(element); }
@Override void getContent(Object node, List result) { if (node instanceof Branch) { result.addAll(((Branch) node).content()); } }
public static org.w3c.dom.Node insertBefore(Node node, org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws DOMException { if (node instanceof Branch) { assert newChild instanceof Node; Branch branch = (Branch) node; List<Node> list = branch.content(); int index = list.indexOf(refChild); if (index < 0) { branch.add((Node) newChild); } else { list.add(index, (Node) newChild); } return newChild; } else { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Children not allowed for this node: " + node); } }
public Iterator getChildAxisIterator(Object contextNode) { Iterator result = null; if ( contextNode instanceof Branch ) { Branch node = (Branch) contextNode; result = node.nodeIterator(); } if (result != null) { return result; } return JaxenConstants.EMPTY_ITERATOR; }
if ( modules == null ) modules = project.addText( " " ).addElement( "modules" ); modules.setText( "\n " ); project.addText( "\n" ); for ( Iterator i = modules.nodeIterator(); i.hasNext(); ) modules.remove( lastTextNode ); modules.addElement( "module" ).setText( artifactId ); modules.addText( "\n " );
protected void assertNodesEqualContent(Branch b1, Branch b2) { int c1 = b1.nodeCount(); int c2 = b2.nodeCount(); if (c1 != c2) { log("Content of: " + b1); log("is: " + b1.content()); log("Content of: " + b2); log("is: " + b2.content()); } Assert.assertEquals(c1, c2, String.format("Branches have same number of children (%d, %d for: %s and %s", c1, c2, b1, b2)); for (int i = 0; i < c1; i++) { Node n1 = b1.node(i); Node n2 = b2.node(i); assertNodesEqual(n1, n2); } }
public static org.w3c.dom.Node removeChild(Node node, org.w3c.dom.Node oldChild) throws DOMException { if (node instanceof Branch) { Branch branch = (Branch) node; branch.remove((Node) oldChild); return oldChild; } throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Children not allowed for this node: " + node); }
public void setValue(final String text) { top().setText(text); }
public IllegalAddException(Branch parent, Node node, String reason) { super("The node \"" + node.toString() + "\" could not be added to the branch \"" + parent.getName() + "\" because: " + reason); } }
/** * <p>Removes whitespace-only {@link Text} nodes without siblings from a given {@link Node} and its descendants.</p> * * @param node The node from which to remove whitespace-only {@link Text} nodes without siblings. */ public static void removeWhitespaceWithoutSiblings(final Node node) { if (node instanceof Branch) { final Branch branch = (Branch) node; if (branch.nodeCount() > 1) { final Iterator<Node> childIterator = branch.nodeIterator(); while (childIterator.hasNext()) { final Node child = childIterator.next(); if (child instanceof Text) { final Text text = (Text) child; if (text.getText().trim().length() == 0) { childIterator.remove(); continue; } } removeWhitespaceWithoutSiblings(child); } } } }
public boolean isLeaf() { return getXmlBranch().nodeCount() <= 0; }
private Node getNodeForPath(Document doc, SimplePath path) { Node node = doc; for (SimplePath p = path; p != null; p = p.next) { if (!(node instanceof Branch)) throw new IllegalStateException("Node with children not a Branch"); Branch parent = (Branch) node; node = parent.node(p.childNum); } return node; }
/** * Writes each child node within the provided {@link Branch}instance. This * method simply iterates through the {@link Branch}'s nodes and calls * {@link #writeNode(Node)}. * * @param branch * The node whose children will be written to the stream. * * @throws XMLStreamException * If an error occurs writing to the stream. */ public void writeChildNodes(Branch branch) throws XMLStreamException { for (int i = 0, s = branch.nodeCount(); i < s; i++) { Node n = branch.node(i); writeNode(n); } }
public static org.w3c.dom.Node insertBefore(Node node, org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws DOMException { if (node instanceof Branch) { Branch branch = (Branch) node; List list = branch.content(); int index = list.indexOf(refChild); if (index < 0) { branch.add((Node) newChild); } else { list.add(index, newChild); } return newChild; } else { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Children not allowed for this node: " + node); } }
protected void writeContent(Branch branch, NamespaceStack namespaceStack) throws SAXException { for (Iterator<Node> iter = branch.nodeIterator(); iter.hasNext();) { Node node = iter.next(); if (node instanceof Element) { write((Element) node, namespaceStack); } else if (node instanceof CharacterData) { if (node instanceof Text) { Text text = (Text) node; write(text.getText()); } else if (node instanceof CDATA) { write((CDATA) node); } else if (node instanceof Comment) { write((Comment) node); } else { throw new SAXException("Invalid Node in DOM4J content: " + node + " of type: " + node.getClass()); } } else if (node instanceof Entity) { write((Entity) node); } else if (node instanceof ProcessingInstruction) { write((ProcessingInstruction) node); } else if (node instanceof Namespace) { write((Namespace) node); } else { throw new SAXException("Invalid Node in DOM4J content: " + node); } } }
Branch b = findWhichBranch(player); Team t = findWhichTeam(player); b.remove(player); t.remove(player); players[index] = null;
@Override public void setValue(final String text) { top().setText(text); }
public IllegalAddException(Branch parent, Node node, String reason) { super("The node \"" + node.toString() + "\" could not be added to the branch \"" + parent.getName() + "\" because: " + reason); } }