/** * Constructor. * * @param root * the root node of the object model subtree that is being serialized; this * information is used by the serializer in scenarios that require access to the * namespace context of the parent of the root node * @param namespaceRepairing * indicates if the serializer should perform namespace repairing * @param preserveNamespaceContext * indicates if the namespace context determined by the ancestors of the root node * should be strictly preserved in the output */ public Serializer(OMSerializable root, boolean namespaceRepairing, boolean preserveNamespaceContext) { this.root = root; if (root instanceof OMNode) { OMContainer parent = ((OMNode)root).getParent(); if (parent instanceof OMElement) { contextElement = (OMElement)parent; } else { contextElement = null; } } else { contextElement = null; } this.namespaceRepairing = namespaceRepairing; this.preserveNamespaceContext = preserveNamespaceContext; }
public final void endElement(String uri, String localName, String qName) throws SAXException { if (!inEntityReference) { completed((OMElement)target); target = ((OMNode)target).getParent(); } }
public Object next() { if (hasNext()) { currentNode = nextNode; currentParent = currentNode instanceof OMNode ? ((OMNode)currentNode).getParent() : null; nextNode = null; nextCalled = true; return currentNode; } else { throw new NoSuchElementException(); } }
public Object next() { if (hasNext()) { currentNode = nextNode; currentParent = currentNode.getParent(); nextNode = null; nextCalled = true; return currentNode; } else { throw new NoSuchElementException(); } }
public final void endElement(String uri, String localName, String qName) throws SAXException { if (!inEntityReference) { completed((OMElement)target); target = ((OMNode)target).getParent(); } }
public Object next() { if (hasNext()) { currentNode = nextNode; currentParent = currentNode instanceof OMNode ? ((OMNode)currentNode).getParent() : null; nextNode = null; nextCalled = true; return currentNode; } else { throw new NoSuchElementException(); } }
public boolean hasNext() { if (noMoreNodes) { return false; } else if (nextNode != null) { return true; } else { if (currentNode.getParent() != currentParent) { throw new ConcurrentModificationException("The current node has been removed using a method other than Iterator#remove()"); } nextNode = getNextNode(currentNode); noMoreNodes = nextNode == null; return !noMoreNodes; } }
public Node getParentNode() { return fac.getNode(node.getParent()); }
public boolean hasNext() { if (noMoreNodes) { return false; } else if (nextNode != null) { return true; } else { if (currentNode instanceof OMNode && ((OMNode)currentNode).getParent() != currentParent) { throw new ConcurrentModificationException("The current node has been removed using a method other than Iterator#remove()"); } nextNode = getNextNode(currentNode); noMoreNodes = nextNode == null; return !noMoreNodes; } }
public boolean hasNext() { if (noMoreNodes) { return false; } else if (nextNode != null) { return true; } else { if (currentNode instanceof OMNode && ((OMNode)currentNode).getParent() != currentParent) { throw new ConcurrentModificationException("The current node has been removed using a method other than Iterator#remove()"); } nextNode = getNextNode(currentNode); noMoreNodes = nextNode == null; return !noMoreNodes; } }
/** * Returns the document node that contains the given context node. * * @param contextNode the context node * @return Returns the document of the context node. * @see #isDocument(Object) */ public Object getDocumentNode(Object contextNode) { if (contextNode instanceof OMDocument) { return contextNode; } OMContainer parent = ((OMNode) contextNode).getParent(); if (parent == null) { // this node doesn't have a parent Document. So return the document element itself return contextNode; } else { return getDocumentNode(parent); } }
/** * Constructor OMStAXWrapper * * @param builder * @param startNode * @param cache */ public DOMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode, boolean cache) { // create a navigator this.navigator = new DOMNavigator(startNode); this.builder = builder; this.rootNode = startNode; if (rootNode != null && rootNode.getParent() != null && rootNode.getParent() instanceof OMDocument) { needToThrowEndDocument = true; } // initaite the next and current nodes // Note - navigator is written in such a way that it first // returns the starting node at the first call to it currentNode = navigator.next(); updateNextNode(); switchingAllowed = !cache; }
/** * Returns the parent of the given context node. * <p> * The parent of any node must either be a document node or an element node. * * @param contextNode the context node * @return Returns the parent of the context node, or null if this is a document node. * @throws UnsupportedAxisException if the parent axis is not supported by the model * @see #isDocument * @see #isElement */ public Object getParentNode(Object contextNode) throws UnsupportedAxisException { if (contextNode == null || contextNode instanceof OMDocument) { return null; } else if (contextNode instanceof OMAttribute) { return ((OMAttribute) contextNode).getOwner(); } else if (contextNode instanceof OMNamespaceEx) { return ((OMNamespaceEx) contextNode).getParent(); } return ((OMNode) contextNode).getParent(); }
/** Private method to encapsulate the searching logic */ private void updateNextNode() { if ((next instanceof OMElement) && !visited) { ElementImpl e = (ElementImpl) next; if (e.firstChild != null) { next = e.firstChild; } else if (e.isComplete()) { backtracked = true; } else { next = null; } } else { OMNode nextSibling = ((ChildNode) next).nextSibling; OMContainer parent = next.getParent(); if (nextSibling != null) { next = nextSibling; } else if ((parent != null) && parent.isComplete()) { next = (NodeImpl) parent; backtracked = true; } else { next = null; } } }
protected OMSerializable getNextNode(OMSerializable currentNode) { if (currentNode instanceof OMContainer) { OMNode firstChild = ((OMContainer)currentNode).getFirstOMChild(); if (firstChild != null) { level++; return firstChild; } } OMSerializable node = currentNode; while (true) { if (level == 0) { return null; } OMNode nextSibling = ((OMNode)node).getNextOMSibling(); if (nextSibling != null) { return nextSibling; } else { node = ((OMNode)node).getParent(); level--; } } } }
private Map<String,String> getAllNamespaces(OMSerializable contextNode) { if (contextNode == null) { return Collections.emptyMap(); } OMContainer context; if (contextNode instanceof OMContainer) { context = (OMContainer)contextNode; } else { context = ((OMNode)contextNode).getParent(); } Map<String,String> nsMap = new LinkedHashMap<String,String>(); while (context != null && !(context instanceof OMDocument)) { OMElement element = (OMElement) context; for (Iterator it = element.getAllDeclaredNamespaces(); it.hasNext(); ) { addNamespaceToMap((OMNamespace) it.next(), nsMap); } if (element.getNamespace() != null) { addNamespaceToMap(element.getNamespace(), nsMap); } for (Iterator it = element.getAllAttributes(); it.hasNext(); ) { OMAttribute attr = (OMAttribute) it.next(); if (attr.getNamespace() != null) { addNamespaceToMap(attr.getNamespace(), nsMap); } } context = element.getParent(); } return nsMap; }
public Node getPreviousSibling() { if (prev == null) { if (node.getParent() instanceof OMDocument) { OMNode n = node.getPreviousOMSibling(); do { if (!(n instanceof OMText)) { prev = fac.getNode(n); break; } n = n.getPreviousOMSibling(); } while (true); } else { prev = fac.getNode(node.getPreviousOMSibling()); } } return prev; }
/** * Retrieves an <code>Iterator</code> matching the <code>parent</code> XPath axis. * * @param contextNode the original context node * @return Returns an Iterator capable of traversing the axis, not null. * @throws UnsupportedAxisException if the semantics of the parent axis are not supported by * this object model */ public Iterator getParentAxisIterator(Object contextNode) throws UnsupportedAxisException { if (contextNode instanceof OMNode) { return new SingleObjectIterator(((OMNode) contextNode).getParent()); } else if (contextNode instanceof OMNamespaceEx) { return new SingleObjectIterator( ((OMNamespaceEx) contextNode).getParent()); } else if (contextNode instanceof OMAttribute) { return new SingleObjectIterator( ((OMAttribute) contextNode).getOwner()); } return JaxenConstants.EMPTY_ITERATOR; }
public Node getNextSibling() { if (next == null) { if (node.getParent() instanceof OMDocument) { OMNode n = node.getNextOMSibling(); do { if (!(n instanceof OMText)) { next = fac.getNode(n); break; } n = n.getNextOMSibling(); } while (true); } else { next = fac.getNode(node.getNextOMSibling()); } } return next; }
/** Private method to encapsulate the searching logic. */ private void updateNextNode() { if (!isLeaf(next) && !visited) { OMNode firstChild = _getFirstChild((OMContainer) next); if (firstChild != null) { next = firstChild; } else if (next.isComplete()) { backtracked = true; } else { next = null; } } else { if (next instanceof OMDocument) { next = null; } else { OMNode nextNode = (OMNode)next; OMContainer parent = nextNode.getParent(); OMNode nextSibling = getNextSibling(nextNode); if (nextSibling != null) { next = nextSibling; } else if ((parent != null) && parent.isComplete()) { next = parent; backtracked = true; } else { next = null; } } } }