public Object get(Object o, int i) { return ((ParentNode)o).getChild(i); } };
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; }
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; }
/** * 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 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; }
/** * 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); } }
/** * gets molecule context for spectrum. In simple documents we assume that * molecules will occur as siblings of spectrum elements. There may be * several spectrums but only one molecule is allowed. * * @return the sibling molecule or null. * @throws RuntimeException * if there are duplicate sibling molecules */ public CMLMolecule getSiblingMolecule() { CMLMolecule molecule = null; ParentNode parent = this.getParent(); if (parent != null) { for (int i = 0; i < parent.getChildCount(); i++) { Node node = parent.getChild(i); if (node instanceof CMLMolecule) { if (molecule != null) { throw new RuntimeException("duplicate sibling molecules"); } molecule = (CMLMolecule) node; } } } return molecule; }
public XOMNodeWrapper getPreviousSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } if (index != -1) { if ((index - 1) > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } else { return null; } } index = parenti.indexOf(node); if (index - 1 > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } return null; }
/** * 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; }
/** * 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; }
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; }
public SteppingNode getPreviousSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } if (index != -1) { if ((index - 1) > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } else { return null; } } index = parenti.indexOf(node); if (index - 1 > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } return null; }
public XOMNodeWrapper 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; }
public XOMNodeWrapper getPreviousSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } if (index != -1) { if ((index - 1) > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } else { return null; } } index = parenti.indexOf(node); if (index - 1 > 0) { return makeWrapper(parenti.getChild(index - 1), docWrapper, parent, index - 1); } return null; }
public XOMNodeWrapper 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; }
/** * gets the element that is previous or parent to the join, depending * on moleculeRefs2 * * @return */ public Element getParentOrPrevious() { if (getMoleculeRefs2Attribute().getValue().equals(PARENT_S + " " + CHILD_S)) { return (Element) getParent(); } else if (getMoleculeRefs2Attribute().getValue().equals(PREVIOUS_S + " " + NEXT_S)) { ParentNode parent = getParent(); int position = parent.indexOf(this); if (position == 0) return null; return (Element) parent.getChild(position - 1); } return null; }
private void writeNode(Node node, StringBuilder stringBuilder) { if (node instanceof ParentNode) { ParentNode parentNode = (ParentNode) node; Element mentionElement = new Element((Element)node); if(mentionElement.getLocalName().equals(TrConstants.FormatInfo.MENTION)){ stringBuilder.append('@'); } for (int childIndex = 0; childIndex < parentNode.getChildCount(); childIndex++) { writeNode(parentNode.getChild(childIndex), stringBuilder); } } else if (node instanceof Text) { Text text = (Text) node; stringBuilder.append(text.getValue()); } } }
/** * Get the following node in an iteration of descendants * * @param start the start node * @param anchor the node marking the root of the subtree within which navigation takes place (may be null) * @return the next node in document order after the start node, excluding attributes and namespaces */ private static Node getSuccessorNode(Node start, Node anchor) { if (start.getChildCount() > 0) { return start.getChild(0); } if (start == anchor) { return null; } Node p = start; while (true) { ParentNode q = p.getParent(); if (q == null) { return null; } int i = q.indexOf(p) + 1; if (i < q.getChildCount()) { return q.getChild(i); } if (q == anchor) { return null; } p = q; } }
/** * Get the following node in an iteration of descendants * * @param start the start node * @param anchor the node marking the root of the subtree within which navigation takes place (may be null) * @return the next node in document order after the start node, excluding attributes and namespaces */ private static Node getSuccessorNode(Node start, Node anchor) { if (start.getChildCount() > 0) { return start.getChild(0); } if (start == anchor) { return null; } Node p = start; while (true) { ParentNode q = p.getParent(); if (q == null) { return null; } int i = q.indexOf(p) + 1; if (i < q.getChildCount()) { return q.getChild(i); } if (q == anchor) { return null; } p = q; } }
/** * gets the element that is next or child to the join, depending * on moleculeRefs2 * * @return */ public CMLElement getChildOrNext() { if (getMoleculeRefs2Attribute().getValue().equals(PARENT_S + " " + CHILD_S)) { if (getChildCount() > 0) return (CMLElement) getChild(0); } else if (getMoleculeRefs2Attribute().getValue().equals(PREVIOUS_S + " " + NEXT_S)) { ParentNode parent = getParent(); int position = getParent().indexOf(this); if (position == parent.getChildCount() - 1) return null; return (CMLElement) parent.getChild(position + 1); } return null; }