jdk/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformXPath2Filter.java
author mullan
Mon, 26 Sep 2011 17:20:45 -0700
changeset 10694 cf59e2badd14
parent 1337 e8d6cef36199
child 11674 a657f8ba55fc
permissions -rw-r--r--
7088502: Security libraries don't build with javac -Werror Summary: Changes to files in src/share/classes/com/sun/org/apache/xml/internal/security and its subpackages to remove warnings Reviewed-by: mullan Contributed-by: kurchi.subhra.hazra@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.security.transforms.implementations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.util.ArrayList;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    27
import java.util.HashSet;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    28
import java.util.Iterator;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.List;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    30
import java.util.Set;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.xml.parsers.ParserConfigurationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.xml.transform.TransformerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.security.signature.NodeFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    40
import com.sun.org.apache.xml.internal.security.transforms.Transform;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.xml.internal.security.transforms.TransformSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xml.internal.security.transforms.TransformationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xml.internal.security.transforms.Transforms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xml.internal.security.transforms.params.XPath2FilterContainer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xml.internal.security.utils.CachedXPathAPIHolder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.xml.internal.security.utils.CachedXPathFuncHereAPI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import org.w3c.dom.DOMException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import org.xml.sax.SAXException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Implements the <I>XML Signature XPath Filter v2.0</I>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author $Author: mullan $
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see <A HREF="http://www.w3.org/TR/xmldsig-filter2/">XPath Filter v2.0 (TR)</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see <a HREF="http://www.w3.org/Signature/Drafts/xmldsig-xfilter2/">XPath Filter v2.0 (editors copy)</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class TransformXPath2Filter extends TransformSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
   /** {@link java.util.logging} logging facility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
//    static java.util.logging.Logger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
//        java.util.logging.Logger.getLogger(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
//                            TransformXPath2Filter.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
   /** Field implementedTransformURI */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
   public static final String implementedTransformURI =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
      Transforms.TRANSFORM_XPATH2FILTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
   //J-
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
   // contains the type of the filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
   // contains the node set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    * Method engineGetURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    * @inheritDoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
   protected String engineGetURI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      return implementedTransformURI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    * Method enginePerformTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    * @inheritDoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    * @param input
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    * @throws TransformationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    95
   protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, Transform _transformObject)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
           throws TransformationException {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    97
          CachedXPathAPIHolder.setDoc(_transformObject.getElement().getOwnerDocument());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
      try {
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    99
          List<NodeList> unionNodes=new ArrayList<NodeList>();
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   100
          List<NodeList> substractNodes=new ArrayList<NodeList>();
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   101
          List<NodeList> intersectNodes=new ArrayList<NodeList>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         CachedXPathFuncHereAPI xPathFuncHereAPI =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            new CachedXPathFuncHereAPI(CachedXPathAPIHolder.getCachedXPathAPI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         Element []xpathElements =XMLUtils.selectNodes(
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   108
                _transformObject.getElement().getFirstChild(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                   XPath2FilterContainer.XPathFilter2NS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                   XPath2FilterContainer._TAG_XPATH2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         int noOfSteps = xpathElements.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         if (noOfSteps == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            Object exArgs[] = { Transforms.TRANSFORM_XPATH2FILTER, "XPath" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            throw new TransformationException("xml.WrongContent", exArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         Document inputDoc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         if (input.getSubNode() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            inputDoc = XMLUtils.getOwnerDocument(input.getSubNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            inputDoc = XMLUtils.getOwnerDocument(input.getNodeSet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         for (int i = 0; i < noOfSteps; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            Element xpathElement =XMLUtils.selectNode(
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   129
               _transformObject.getElement().getFirstChild(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                  XPath2FilterContainer.XPathFilter2NS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                  XPath2FilterContainer._TAG_XPATH2,i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            XPath2FilterContainer xpathContainer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
               XPath2FilterContainer.newInstance(xpathElement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                                   input.getSourceURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            NodeList subtreeRoots = xPathFuncHereAPI.selectNodeList(inputDoc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                       xpathContainer.getXPathFilterTextNode(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                       CachedXPathFuncHereAPI.getStrFromNode(xpathContainer.getXPathFilterTextNode()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                       xpathContainer.getElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            if (xpathContainer.isIntersect()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                intersectNodes.add(subtreeRoots);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
             } else if (xpathContainer.isSubtract()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                 substractNodes.add(subtreeRoots);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
             } else if (xpathContainer.isUnion()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                unionNodes.add(subtreeRoots);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   151
         input.addNodeFilter(new XPath2NodeFilter(convertNodeListToSet(unionNodes),
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   152
                         convertNodeListToSet(substractNodes),convertNodeListToSet(intersectNodes)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         input.setNodeSet(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         return input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
      } catch (TransformerException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
      } catch (DOMException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      } catch (CanonicalizationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
      } catch (InvalidCanonicalizerException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
      } catch (XMLSecurityException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
      } catch (SAXException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      } catch (ParserConfigurationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
   }
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   173
   static Set<Node> convertNodeListToSet(List<NodeList> l){
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   174
           Set<Node> result=new HashSet<Node>();
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   175
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   176
           for (NodeList rootNodes : l) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   177
               int length = rootNodes.getLength();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   178
               for (int i = 0; i < length; i++) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   179
                    Node rootNode = rootNodes.item(i);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   180
                    result.add(rootNode);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   181
                 }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   182
           }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   183
           return result;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   184
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
class XPath2NodeFilter implements NodeFilter {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   188
        boolean hasUnionNodes;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   189
        boolean hasSubstractNodes;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   190
        boolean hasIntersectNodes;
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   191
        XPath2NodeFilter(Set<Node> unionNodes, Set<Node> substractNodes,
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   192
                        Set<Node> intersectNodes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                this.unionNodes=unionNodes;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   194
                hasUnionNodes=!unionNodes.isEmpty();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                this.substractNodes=substractNodes;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   196
                hasSubstractNodes=!substractNodes.isEmpty();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                this.intersectNodes=intersectNodes;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   198
                hasIntersectNodes=!intersectNodes.isEmpty();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   200
        Set<Node> unionNodes;
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   201
        Set<Node> substractNodes;
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   202
        Set<Node> intersectNodes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    * @see com.sun.org.apache.xml.internal.security.signature.NodeFilter#isNodeInclude(org.w3c.dom.Node)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   208
   public int isNodeInclude(Node currentNode) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   209
           int result=1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   210
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   211
           if (hasSubstractNodes && rooted(currentNode, substractNodes)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   212
                      result = -1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   213
           } else if (hasIntersectNodes && !rooted(currentNode, intersectNodes)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   214
                   result = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   217
          //TODO OPTIMIZE
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   218
      if (result==1)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   219
          return 1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   220
      if (hasUnionNodes) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   221
          if (rooted(currentNode, unionNodes)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   222
                   return 1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   223
          }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   224
          result=0;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   225
      }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   226
      return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
   }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   229
   int inSubstract=-1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   230
   int inIntersect=-1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   231
   int inUnion=-1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   232
   public int isNodeIncludeDO(Node n, int level) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   233
           int result=1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   234
           if (hasSubstractNodes) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   235
                   if ((inSubstract==-1) || (level<=inSubstract)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   236
                           if (inList(n,  substractNodes)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   237
                                   inSubstract=level;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   238
                           } else {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   239
                                   inSubstract=-1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   240
                           }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   241
                   }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   242
                   if (inSubstract!=-1){
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   243
                           result=-1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   244
                   }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   245
           }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   246
           if (result!=-1){
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   247
                   if (hasIntersectNodes) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   248
                   if ((inIntersect==-1) || (level<=inIntersect)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   249
                           if (!inList(n,  intersectNodes)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   250
                                   inIntersect=-1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   251
                                   result=0;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   252
                           } else {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   253
                                   inIntersect=level;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   254
                           }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   255
                   }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   256
                   }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   257
           }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   258
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   259
          if (level<=inUnion)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   260
                   inUnion=-1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   261
      if (result==1)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   262
          return 1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   263
      if (hasUnionNodes) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   264
          if ((inUnion==-1) && inList(n,  unionNodes)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   265
                  inUnion=level;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   266
          }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   267
          if (inUnion!=-1)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   268
                  return 1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   269
          result=0;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   270
      }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   271
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   272
      return result;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   273
   }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    * Method rooted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    * @param currentNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    * @param nodeList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    * @return if rooted bye the rootnodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   282
   static boolean  rooted(Node currentNode, Set<Node> nodeList ) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   283
           if (nodeList.contains(currentNode)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   284
                   return true;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   285
           }
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   286
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   287
           for(Node rootNode : nodeList) {
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   288
               if (XMLUtils.isDescendantOrSelf(rootNode,currentNode)) {
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   289
                   return true;
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   290
               }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
           return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
   }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   294
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   295
      /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   296
       * Method rooted
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   297
       * @param currentNode
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   298
       * @param nodeList
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   299
       *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   300
       * @return if rooted bye the rootnodes
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   301
       */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   302
      static boolean  inList(Node currentNode, Set<Node> nodeList ) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   303
              return nodeList.contains(currentNode);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   304
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
}