author | chegar |
Sun, 17 Aug 2014 15:54:13 +0100 | |
changeset 25859 | 3317bb8137f4 |
parent 24970 | jdk/src/share/classes/org/jcp/xml/dsig/internal/dom/ApacheNodeSetData.java@094bfaa699c3 |
child 27747 | 3a271dc8b758 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1337 | 2 |
* reserved comment block |
3 |
* DO NOT REMOVE OR ALTER! |
|
2 | 4 |
*/ |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
5 |
/** |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
7 |
* or more contributor license agreements. See the NOTICE file |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
8 |
* distributed with this work for additional information |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
9 |
* regarding copyright ownership. The ASF licenses this file |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
10 |
* to you under the Apache License, Version 2.0 (the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
11 |
* "License"); you may not use this file except in compliance |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
12 |
* with the License. You may obtain a copy of the License at |
1337 | 13 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
1337 | 15 |
* |
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
16 |
* Unless required by applicable law or agreed to in writing, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
17 |
* software distributed under the License is distributed on an |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
19 |
* KIND, either express or implied. See the License for the |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
20 |
* specific language governing permissions and limitations |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
21 |
* under the License. |
1337 | 22 |
*/ |
23 |
/* |
|
24970
094bfaa699c3
8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents:
23010
diff
changeset
|
24 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
1337 | 25 |
*/ |
26 |
/* |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
27 |
* $Id: ApacheNodeSetData.java 1203890 2011-11-18 22:47:56Z mullan $ |
2 | 28 |
*/ |
29 |
package org.jcp.xml.dsig.internal.dom; |
|
30 |
||
31 |
import java.util.Collections; |
|
32 |
import java.util.Iterator; |
|
33 |
import java.util.LinkedHashSet; |
|
34 |
import java.util.List; |
|
35 |
import java.util.Set; |
|
36 |
import javax.xml.crypto.NodeSetData; |
|
37 |
import org.w3c.dom.Node; |
|
38 |
import com.sun.org.apache.xml.internal.security.signature.NodeFilter; |
|
39 |
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; |
|
40 |
import com.sun.org.apache.xml.internal.security.utils.XMLUtils; |
|
41 |
||
42 |
public class ApacheNodeSetData implements ApacheData, NodeSetData { |
|
43 |
||
44 |
private XMLSignatureInput xi; |
|
45 |
||
46 |
public ApacheNodeSetData(XMLSignatureInput xi) { |
|
47 |
this.xi = xi; |
|
48 |
} |
|
49 |
||
24970
094bfaa699c3
8046044: Fix raw and unchecked lint warnings in XML Signature Impl
mullan
parents:
23010
diff
changeset
|
50 |
public Iterator<Node> iterator() { |
2 | 51 |
// If nodefilters are set, must execute them first to create node-set |
18266
26e69da689b9
8010714: XML DSig API allows a RetrievalMethod to reference another RetrievalMethod
mullan
parents:
5506
diff
changeset
|
52 |
if (xi.getNodeFilters() != null && !xi.getNodeFilters().isEmpty()) { |
2 | 53 |
return Collections.unmodifiableSet |
54 |
(getNodeSet(xi.getNodeFilters())).iterator(); |
|
55 |
} |
|
56 |
try { |
|
57 |
return Collections.unmodifiableSet(xi.getNodeSet()).iterator(); |
|
58 |
} catch (Exception e) { |
|
59 |
// should not occur |
|
60 |
throw new RuntimeException |
|
61 |
("unrecoverable error retrieving nodeset", e); |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
public XMLSignatureInput getXMLSignatureInput() { |
|
66 |
return xi; |
|
67 |
} |
|
68 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
69 |
private Set<Node> getNodeSet(List<NodeFilter> nodeFilters) { |
2 | 70 |
if (xi.isNeedsToBeExpanded()) { |
71 |
XMLUtils.circumventBug2650 |
|
72 |
(XMLUtils.getOwnerDocument(xi.getSubNode())); |
|
73 |
} |
|
74 |
||
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
75 |
Set<Node> inputSet = new LinkedHashSet<Node>(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
76 |
XMLUtils.getSet(xi.getSubNode(), inputSet, |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
77 |
null, !xi.isExcludeComments()); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
78 |
Set<Node> nodeSet = new LinkedHashSet<Node>(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
79 |
for (Node currentNode : inputSet) { |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
80 |
Iterator<NodeFilter> it = nodeFilters.iterator(); |
2 | 81 |
boolean skipNode = false; |
82 |
while (it.hasNext() && !skipNode) { |
|
18780
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
83 |
NodeFilter nf = it.next(); |
f47b920867e7
8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents:
18266
diff
changeset
|
84 |
if (nf.isNodeInclude(currentNode) != 1) { |
2 | 85 |
skipNode = true; |
86 |
} |
|
87 |
} |
|
88 |
if (!skipNode) { |
|
89 |
nodeSet.add(currentNode); |
|
90 |
} |
|
91 |
} |
|
92 |
return nodeSet; |
|
93 |
} |
|
94 |
} |