ApacheNodeSetData.java revision 6385
0N/A/*
0N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
2362N/A * Copyright 2005 The Apache Software Foundation.
0N/A *
2362N/A * Licensed under the Apache License, Version 2.0 (the "License");
0N/A * you may not use this file except in compliance with the License.
0N/A * You may obtain a copy of the License at
0N/A *
0N/A * http://www.apache.org/licenses/LICENSE-2.0
0N/A *
0N/A * Unless required by applicable law or agreed to in writing, software
0N/A * distributed under the License is distributed on an "AS IS" BASIS,
0N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A * See the License for the specific language governing permissions and
0N/A * limitations under the License.
0N/A *
2362N/A */
2362N/A/*
2362N/A * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A */
0N/A/*
0N/A * $Id: ApacheNodeSetData.java,v 1.2 2008/07/24 15:20:32 mullan Exp $
0N/A */
0N/Apackage org.jcp.xml.dsig.internal.dom;
0N/A
3171N/Aimport java.util.Collections;
0N/Aimport java.util.HashSet;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.LinkedHashSet;
0N/Aimport java.util.List;
0N/Aimport java.util.Set;
0N/Aimport javax.xml.crypto.NodeSetData;
0N/Aimport org.w3c.dom.Node;
0N/Aimport com.sun.org.apache.xml.internal.security.signature.NodeFilter;
0N/Aimport com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
3171N/Aimport com.sun.org.apache.xml.internal.security.utils.XMLUtils;
3171N/A
0N/Apublic class ApacheNodeSetData implements ApacheData, NodeSetData {
0N/A
1693N/A private XMLSignatureInput xi;
1693N/A
1693N/A public ApacheNodeSetData(XMLSignatureInput xi) {
1693N/A this.xi = xi;
3171N/A }
3171N/A
0N/A public Iterator iterator() {
0N/A // If nodefilters are set, must execute them first to create node-set
0N/A if (xi.getNodeFilters() != null && !xi.getNodeFilters().isEmpty()) {
0N/A return Collections.unmodifiableSet
3171N/A (getNodeSet(xi.getNodeFilters())).iterator();
3171N/A }
3171N/A try {
3171N/A return Collections.unmodifiableSet(xi.getNodeSet()).iterator();
0N/A } catch (Exception e) {
0N/A // should not occur
0N/A throw new RuntimeException
0N/A ("unrecoverable error retrieving nodeset", e);
0N/A }
0N/A }
0N/A
0N/A public XMLSignatureInput getXMLSignatureInput() {
0N/A return xi;
0N/A }
0N/A
0N/A private Set getNodeSet(List nodeFilters) {
0N/A if (xi.isNeedsToBeExpanded()) {
0N/A XMLUtils.circumventBug2650
0N/A (XMLUtils.getOwnerDocument(xi.getSubNode()));
0N/A }
0N/A
0N/A Set inputSet = new LinkedHashSet();
0N/A XMLUtils.getSet
0N/A (xi.getSubNode(), inputSet, null, !xi.isExcludeComments());
0N/A Set nodeSet = new LinkedHashSet();
0N/A Iterator i = inputSet.iterator();
0N/A while (i.hasNext()) {
0N/A Node currentNode = (Node) i.next();
0N/A Iterator it = nodeFilters.iterator();
0N/A boolean skipNode = false;
0N/A while (it.hasNext() && !skipNode) {
1693N/A NodeFilter nf = (NodeFilter) it.next();
0N/A if (nf.isNodeInclude(currentNode)!=1) {
0N/A skipNode = true;
0N/A }
0N/A }
0N/A if (!skipNode) {
1693N/A nodeSet.add(currentNode);
0N/A }
0N/A }
0N/A return nodeSet;
0N/A }
0N/A}
0N/A