public Object get(Object o, int i) { return ((ParentNode)o).getChild(i); } };
public Iterator getChildAxisIterator(Object o) { if (isElement(o) || (o instanceof Document)) { return new IndexIterator(o, 0, ((ParentNode)o).getChildCount()) { public Object get(Object o, int i) { return ((ParentNode)o).getChild(i); } }; } return JaxenConstants.EMPTY_ITERATOR; }
/** * get next sibling. * * @author Eliotte Rusty Harold * @param current * may be null * @return following sibling or null */ public static Node getFollowingSibling(Node current) { Node node = null; if (current != null) { ParentNode parent = current.getParent(); if (parent != null) { int index = parent.indexOf(current); if (index + 1 < parent.getChildCount()) { node = parent.getChild(index + 1); } } } return node; }
private NodeInfo advance() { Node nextChild; do { if (forwards) { if (cursor == par.getChildCount()) return null; nextChild = par.getChild(cursor++); } else { // backwards if (cursor == 0) return null; nextChild = par.getChild(--cursor); } } while (nextChild instanceof DocType); // DocType is not an XPath node; can occur for /child::node() NodeInfo curr = makeWrapper(nextChild, docWrapper, commonParent, ix); ix += (forwards ? 1 : -1); return curr; }
/** * get previous sibling. * * @param current * @return previous sibling */ public static Node getPrecedingSibling(Node current) { Node node = null; if (current != null) { ParentNode parent = current.getParent(); if (parent != null) { int index = parent.indexOf(current); if (index > 0) { node = parent.getChild(index - 1); } } } return node; }
for (int i=node.getChildCount(); --i >= 0; ) { Node child = node.getChild(i); if (child instanceof Element) { // recursively walk the tree normalize((Element)child); while (--i >= 0 && node.getChild(i) instanceof Text) ; String norm = normalizeWhitespace(value); if (norm.length() == 0) { node.removeChild(i); } else if (!norm.equals(value)) { ((Text) child).setValue(norm);
parent.appendChild(element); case XMLStreamConstants.END_ELEMENT: nodeFactory.finishMakingElement(element); parent = parent.getParent(); break; case XMLStreamConstants.ATTRIBUTE:
/** * Found more than one adjacent Text node; merge them. Appends forwards * and removes backwards to minimize memory copies of list elems. */ private void merge(ParentNode node, int i, int j) { int k = i; StringBuffer buf = new StringBuffer(node.getChild(k++).getValue()); while (k <= j) buf.append(node.getChild(k++).getValue()); k = j; while (k >= i) node.removeChild(k--); // replace run with compact merged Text node unless empty String norm = normalizeWhitespace(buf.toString()); if (norm.length() > 0) { node.insertChild(new Text(norm), i); } }
private ChildAxisIterator(XOMNodeWrapper start, boolean downwards, boolean forwards, NodeTest test) { this.forwards = forwards; if (test == AnyNodeTest.getInstance()) { test = null; } nodeTest = test; commonParent = downwards ? start : start.getParent(); par = (ParentNode) commonParent.node; if (downwards) { ix = (forwards ? 0 : par.getChildCount()); } else { // find the start node among the list of siblings ix = par.indexOf(start.node); if (forwards) ix++; } cursor = ix; if (!downwards && !forwards) ix--; }
/** * Get the index position of this node among its siblings (starting from 0) */ public int getSiblingPosition() { // This method is used only to support generate-id() if (index != -1) return index; switch (nodeKind) { case Type.ATTRIBUTE: { Attribute att = (Attribute) node; Element p = (Element) att.getParent(); if (p == null) return 0; for (int i = p.getAttributeCount(); --i >= 0; ) { if (p.getAttribute(i) == att) { index = i; return i; } } throw new IllegalStateException("XOM node not linked to parent node"); } default: { ParentNode p = node.getParent(); int i = (p == null ? 0 : p.indexOf(node)); if (i == -1) throw new IllegalStateException("XOM node not linked to parent node"); index = i; return index; } } }
@Override protected void insertFosterParentedChild(Element child, Element table, Element stackParent) throws SAXException { try { Node parent = table.getParent(); if (parent != null) { // always an element if not null ((ParentNode)parent).insertChild(child, indexOfTable(table, stackParent)); cachedTableIndex++; } else { stackParent.appendChild(child); } } catch (XMLException e) { fatal(e); } }
Node node = context.getNode(); ParentNode parent = node.getParent(); int index = parent.indexOf(node); TableAdapter table = UtilTable.newTable(node); int colIndex = 0; columnIndex += span; parent.insertChild(quote, index + 1); UtilNode.setIgnore(node); return ENext.SKIP;
/** re-route detach(). * to parent.removeChild(this); */ public void detach() { ParentNode parent = this.getParent(); if (parent != null) { if (parent instanceof Document) { parent.replaceChild(this, new Element("dummy")); } else { parent.removeChild(this); } } }
/** * Get full class name (package + class) for "class" XML element. * * @param elem The element. * @return the full class name (package + class) for "class" XML element. */ private String fullClassName( Element elem ) { final Element packageElem = (Element) elem.getParent().getParent(); final String packageName = packageElem.getAttributeValue( "name" ); final String className = elem.getAttributeValue( "name" ); return packageName.length() != 0 ? packageName + "." + className : className; }
Node node = nodes.get(i); ParentNode dependency = node.getParent(); Nodes classifier = dependency.query("mvn:classifier", context); if (classifier.size() != 0) if (!classifier.get(0).getValue().equals(artifact.getClassifier())) return; final Nodes versionNodes = dependency.query("mvn:version", context); if (versionNodes.size() > 0) { getLog().info("Upgrading dependency to " + artifact.toString() + " from " + oldVersion); Element newRange = new Element("version", "http://maven.apache.org/POM/4.0.0"); newRange.appendChild(artifact.getVersion()); dependency.replaceChild(version, newRange);
static void reparentBodyNode( final Element current_body, final @Nullable Element target_body) { if (target_body != null) { final Node rbody_root = SXHTMLReparent.getAbsoluteAncestor(target_body); assert rbody_root != null; final ParentNode current_body_parent = current_body.getParent(); assert current_body_parent != null; current_body.detach(); current_body_parent.appendChild(rbody_root); target_body.appendChild(current_body); } } }
/** * Delete this node (that is, detach it from its parent) */ public void delete() throws XPathException { if (parent != null) { if (nodeKind == Type.ATTRIBUTE) { ((Element) parent.node).removeAttribute((Attribute) node); } else { ((ParentNode) parent.node).removeChild(node); } } }
public static void detach(nu.xom.Element element) { ParentNode parent = (element == null) ? null : element.getParent(); if (parent != null) { if (parent instanceof Document) { parent.replaceChild(element, new Element(DUMMY)); } else { element.detach(); } } }
public SteppingNode getNextSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } int count = parenti.getChildCount(); if (index != -1) { if ((index + 1) < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } else { return null; } } index = parenti.indexOf(node); if (index + 1 < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } return null; }