0N/A/*
661N/A * reserved comment block
661N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
661N/A * Copyright 2005 The Apache Software Foundation.
661N/A *
661N/A * Licensed under the Apache License, Version 2.0 (the "License");
661N/A * you may not use this file except in compliance with the License.
661N/A * You may obtain a copy of the License at
661N/A *
661N/A * http://www.apache.org/licenses/LICENSE-2.0
661N/A *
661N/A * Unless required by applicable law or agreed to in writing, software
661N/A * distributed under the License is distributed on an "AS IS" BASIS,
661N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
661N/A * See the License for the specific language governing permissions and
661N/A * limitations under the License.
661N/A *
661N/A */
661N/A/*
2362N/A * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
661N/A */
661N/A/*
661N/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
0N/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;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.XMLUtils;
0N/A
0N/Apublic class ApacheNodeSetData implements ApacheData, NodeSetData {
0N/A
0N/A private XMLSignatureInput xi;
0N/A
0N/A public ApacheNodeSetData(XMLSignatureInput xi) {
0N/A this.xi = xi;
0N/A }
0N/A
0N/A public Iterator iterator() {
0N/A // If nodefilters are set, must execute them first to create node-set
6385N/A if (xi.getNodeFilters() != null && !xi.getNodeFilters().isEmpty()) {
0N/A return Collections.unmodifiableSet
0N/A (getNodeSet(xi.getNodeFilters())).iterator();
0N/A }
0N/A try {
0N/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) {
0N/A NodeFilter nf = (NodeFilter) it.next();
661N/A if (nf.isNodeInclude(currentNode)!=1) {
0N/A skipNode = true;
0N/A }
0N/A }
0N/A if (!skipNode) {
0N/A nodeSet.add(currentNode);
0N/A }
0N/A }
0N/A return nodeSet;
0N/A }
0N/A}