org.jcp.xml.dsig.internal.dom.DOMSubTreeData Maven / Gradle / Ivy
The newest version!
/* */ package org.jcp.xml.dsig.internal.dom;
/* */
/* */ import java.util.ArrayList;
/* */ import java.util.Iterator;
/* */ import java.util.List;
/* */ import java.util.ListIterator;
/* */ import java.util.NoSuchElementException;
/* */ import javax.xml.crypto.NodeSetData;
/* */ import org.w3c.dom.NamedNodeMap;
/* */ import org.w3c.dom.Node;
/* */
/* */ public class DOMSubTreeData
/* */ implements NodeSetData
/* */ {
/* */ private boolean excludeComments;
/* */ private Iterator ni;
/* */ private Node root;
/* */
/* */ public DOMSubTreeData(Node root, boolean excludeComments)
/* */ {
/* 32 */ this.root = root;
/* 33 */ this.ni = new DelayedNodeIterator(root, excludeComments);
/* 34 */ this.excludeComments = excludeComments;
/* */ }
/* */
/* */ public Iterator iterator() {
/* 38 */ return this.ni;
/* */ }
/* */
/* */ public Node getRoot() {
/* 42 */ return this.root;
/* */ }
/* */
/* */ public boolean excludeComments() {
/* 46 */ return this.excludeComments;
/* */ }
/* */
/* */ static class DelayedNodeIterator implements Iterator
/* */ {
/* */ private Node root;
/* */ private List nodeSet;
/* */ private ListIterator li;
/* */ private boolean withComments;
/* */
/* */ DelayedNodeIterator(Node root, boolean excludeComments) {
/* 60 */ this.root = root;
/* 61 */ this.withComments = (!excludeComments);
/* */ }
/* */
/* */ public boolean hasNext() {
/* 65 */ if (this.nodeSet == null) {
/* 66 */ this.nodeSet = dereferenceSameDocumentURI(this.root);
/* 67 */ this.li = this.nodeSet.listIterator();
/* */ }
/* 69 */ return this.li.hasNext();
/* */ }
/* */
/* */ public Object next() {
/* 73 */ if (this.nodeSet == null) {
/* 74 */ this.nodeSet = dereferenceSameDocumentURI(this.root);
/* 75 */ this.li = this.nodeSet.listIterator();
/* */ }
/* 77 */ if (this.li.hasNext()) {
/* 78 */ return (Node)this.li.next();
/* */ }
/* 80 */ throw new NoSuchElementException();
/* */ }
/* */
/* */ public void remove()
/* */ {
/* 85 */ throw new UnsupportedOperationException();
/* */ }
/* */
/* */ private List dereferenceSameDocumentURI(Node node)
/* */ {
/* 96 */ List nodeSet = new ArrayList();
/* 97 */ if (node != null) {
/* 98 */ nodeSetMinusCommentNodes(node, nodeSet, null);
/* */ }
/* 100 */ return nodeSet;
/* */ }
/* */
/* */ private void nodeSetMinusCommentNodes(Node node, List nodeSet, Node prevSibling)
/* */ {
/* 114 */ switch (node.getNodeType()) {
/* */ case 1:
/* 116 */ NamedNodeMap attrs = node.getAttributes();
/* 117 */ if (attrs != null) {
/* 118 */ int i = 0; for (int len = attrs.getLength(); i < len; i++) {
/* 119 */ nodeSet.add(attrs.item(i));
/* */ }
/* */ }
/* 122 */ nodeSet.add(node);
/* 123 */ Node pSibling = null;
/* 124 */ for (Node child = node.getFirstChild(); child != null;
/* 125 */ child = child.getNextSibling()) {
/* 126 */ nodeSetMinusCommentNodes(child, nodeSet, pSibling);
/* 127 */ pSibling = child;
/* */ }
/* 129 */ break;
/* */ case 3:
/* */ case 4:
/* 134 */ if ((prevSibling != null) && ((prevSibling.getNodeType() == 3) || (prevSibling.getNodeType() == 4)))
/* */ {
/* 136 */ return;
/* */ }
/* */ case 7:
/* 139 */ nodeSet.add(node);
/* 140 */ break;
/* */ case 8:
/* 142 */ if (this.withComments)
/* 143 */ nodeSet.add(node);
/* */ break;
/* */ case 2:
/* */ case 5:
/* */ case 6:
/* */ }
/* */ }
/* */ }
/* */ }
/* Location: E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
* Qualified Name: org.jcp.xml.dsig.internal.dom.DOMSubTreeData
* JD-Core Version: 0.6.2
*/