jdk/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/Canonicalizer.java
author mullan
Mon, 22 Apr 2013 11:23:33 +0100
changeset 18240 cda839ac048f
parent 10694 cf59e2badd14
child 18780 f47b920867e7
permissions -rw-r--r--
6741606: Integrate Apache Santuario Reviewed-by: vinnie, hawtin
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
 */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
     5
/**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
     7
 * or more contributor license agreements. See the NOTICE file
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
     8
 * distributed with this work for additional information
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
     9
 * regarding copyright ownership. The ASF licenses this file
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    10
 * to you under the Apache License, Version 2.0 (the
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    11
 * "License"); you may not use this file except in compliance
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    12
 * with the License. You may obtain a copy of the License at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    16
 * Unless required by applicable law or agreed to in writing,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    17
 * software distributed under the License is distributed on an
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    18
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    19
 * KIND, either express or implied. See the License for the
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    20
 * specific language governing permissions and limitations
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    21
 * under the License.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xml.internal.security.c14n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.io.ByteArrayInputStream;
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    26
import java.io.InputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Set;
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    30
import java.util.concurrent.ConcurrentHashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    32
import javax.xml.XMLConstants;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.xml.parsers.DocumentBuilder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.xml.parsers.DocumentBuilderFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    36
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer11_OmitComments;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    37
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer11_WithComments;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    38
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    39
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    40
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315OmitComments;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    41
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315WithComments;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import org.xml.sax.InputSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class Canonicalizer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    54
    /** The output encoding of canonicalized data */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    55
    public static final String ENCODING = "UTF8";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    57
    /**
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    58
     * XPath Expression for selecting every node and continuous comments joined
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    59
     * in only one node
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    61
    public static final String XPATH_C14N_WITH_COMMENTS_SINGLE_NODE =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    62
        "(.//. | .//@* | .//namespace::*)";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    64
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * The URL defined in XML-SEC Rec for inclusive c14n <b>without</b> comments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    67
    public static final String ALGO_ID_C14N_OMIT_COMMENTS =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    68
        "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    69
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    70
     * The URL defined in XML-SEC Rec for inclusive c14n <b>with</b> comments.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    71
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    72
    public static final String ALGO_ID_C14N_WITH_COMMENTS =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    73
        ALGO_ID_C14N_OMIT_COMMENTS + "#WithComments";
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    74
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    75
     * The URL defined in XML-SEC Rec for exclusive c14n <b>without</b> comments.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    76
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    77
    public static final String ALGO_ID_C14N_EXCL_OMIT_COMMENTS =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    78
        "http://www.w3.org/2001/10/xml-exc-c14n#";
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    79
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    80
     * The URL defined in XML-SEC Rec for exclusive c14n <b>with</b> comments.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    81
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    82
    public static final String ALGO_ID_C14N_EXCL_WITH_COMMENTS =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    83
        ALGO_ID_C14N_EXCL_OMIT_COMMENTS + "WithComments";
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    84
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    85
     * The URI for inclusive c14n 1.1 <b>without</b> comments.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    86
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    87
    public static final String ALGO_ID_C14N11_OMIT_COMMENTS =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    88
        "http://www.w3.org/2006/12/xml-c14n11";
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    89
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    90
     * The URI for inclusive c14n 1.1 <b>with</b> comments.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    91
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    92
    public static final String ALGO_ID_C14N11_WITH_COMMENTS =
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    93
        ALGO_ID_C14N11_OMIT_COMMENTS + "#WithComments";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    95
    private static Map<String, Class<? extends CanonicalizerSpi>> canonicalizerHash =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    96
        new ConcurrentHashMap<String, Class<? extends CanonicalizerSpi>>();
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    97
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    98
    private final CanonicalizerSpi canonicalizerSpi;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   100
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   101
     * Constructor Canonicalizer
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   102
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   103
     * @param algorithmURI
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   104
     * @throws InvalidCanonicalizerException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   105
     */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   106
    private Canonicalizer(String algorithmURI) throws InvalidCanonicalizerException {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   107
        try {
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   108
            Class<? extends CanonicalizerSpi> implementingClass =
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   109
                canonicalizerHash.get(algorithmURI);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   111
            canonicalizerSpi = implementingClass.newInstance();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   112
            canonicalizerSpi.reset = true;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   113
        } catch (Exception e) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   114
            Object exArgs[] = { algorithmURI };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   115
            throw new InvalidCanonicalizerException(
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   116
                "signature.Canonicalizer.UnknownCanonicalizer", exArgs, e
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   117
            );
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   118
        }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   119
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   121
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   122
     * Method getInstance
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   123
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   124
     * @param algorithmURI
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   125
     * @return a Canonicalizer instance ready for the job
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   126
     * @throws InvalidCanonicalizerException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   127
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   128
    public static final Canonicalizer getInstance(String algorithmURI)
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   129
        throws InvalidCanonicalizerException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   130
        return new Canonicalizer(algorithmURI);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   131
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   133
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   134
     * Method register
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   135
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   136
     * @param algorithmURI
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   137
     * @param implementingClass
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   138
     * @throws AlgorithmAlreadyRegisteredException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   139
     */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   140
    @SuppressWarnings("unchecked")
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   141
    public static void register(String algorithmURI, String implementingClass)
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   142
        throws AlgorithmAlreadyRegisteredException, ClassNotFoundException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   143
        // check whether URI is already registered
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   144
        Class<? extends CanonicalizerSpi> registeredClass =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   145
            canonicalizerHash.get(algorithmURI);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   146
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   147
        if (registeredClass != null)  {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   148
            Object exArgs[] = { algorithmURI, registeredClass };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   149
            throw new AlgorithmAlreadyRegisteredException("algorithm.alreadyRegistered", exArgs);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   150
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   152
        canonicalizerHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   153
            algorithmURI, (Class<? extends CanonicalizerSpi>)Class.forName(implementingClass)
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   154
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   155
    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   156
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   157
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   158
     * Method register
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   159
     *
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   160
     * @param algorithmURI
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   161
     * @param implementingClass
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   162
     * @throws AlgorithmAlreadyRegisteredException
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   163
     */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   164
    public static void register(String algorithmURI, Class<CanonicalizerSpi> implementingClass)
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   165
        throws AlgorithmAlreadyRegisteredException, ClassNotFoundException {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   166
        // check whether URI is already registered
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   167
        Class<? extends CanonicalizerSpi> registeredClass = canonicalizerHash.get(algorithmURI);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   169
        if (registeredClass != null)  {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   170
            Object exArgs[] = { algorithmURI, registeredClass };
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   171
            throw new AlgorithmAlreadyRegisteredException("algorithm.alreadyRegistered", exArgs);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   172
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   174
        canonicalizerHash.put(algorithmURI, implementingClass);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   175
    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   176
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   177
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   178
     * This method registers the default algorithms.
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   179
     */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   180
    public static void registerDefaultAlgorithms() {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   181
        canonicalizerHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   182
            Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   183
            Canonicalizer20010315OmitComments.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   184
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   185
        canonicalizerHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   186
            Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   187
            Canonicalizer20010315WithComments.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   188
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   189
        canonicalizerHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   190
            Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   191
            Canonicalizer20010315ExclOmitComments.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   192
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   193
        canonicalizerHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   194
            Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   195
            Canonicalizer20010315ExclWithComments.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   196
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   197
        canonicalizerHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   198
            Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   199
            Canonicalizer11_OmitComments.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   200
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   201
        canonicalizerHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   202
            Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   203
            Canonicalizer11_WithComments.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   204
        );
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   205
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   207
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   208
     * Method getURI
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   209
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   210
     * @return the URI defined for this c14n instance.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   211
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   212
    public final String getURI() {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   213
        return canonicalizerSpi.engineGetURI();
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   214
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   216
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   217
     * Method getIncludeComments
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   218
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   219
     * @return true if the c14n respect the comments.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   220
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   221
    public boolean getIncludeComments() {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   222
        return canonicalizerSpi.engineGetIncludeComments();
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   223
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
1337
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
     * This method tries to canonicalize the given bytes. It's possible to even
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   227
     * canonicalize non-wellformed sequences if they are well-formed after being
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   228
     * wrapped with a <CODE>&gt;a&lt;...&gt;/a&lt;</CODE>.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   229
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   230
     * @param inputBytes
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   231
     * @return the result of the canonicalization.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   232
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   233
     * @throws java.io.IOException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   234
     * @throws javax.xml.parsers.ParserConfigurationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   235
     * @throws org.xml.sax.SAXException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   236
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   237
    public byte[] canonicalize(byte[] inputBytes)
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   238
        throws javax.xml.parsers.ParserConfigurationException,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   239
        java.io.IOException, org.xml.sax.SAXException, CanonicalizationException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   240
        InputStream bais = new ByteArrayInputStream(inputBytes);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   241
        InputSource in = new InputSource(bais);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   242
        DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   243
        dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   245
        dfactory.setNamespaceAware(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   247
        // needs to validate for ID attribute normalization
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   248
        dfactory.setValidating(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   250
        DocumentBuilder db = dfactory.newDocumentBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   252
        /*
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   253
         * for some of the test vectors from the specification,
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   254
         * there has to be a validating parser for ID attributes, default
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   255
         * attribute values, NMTOKENS, etc.
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   256
         * Unfortunately, the test vectors do use different DTDs or
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   257
         * even no DTD. So Xerces 1.3.1 fires many warnings about using
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   258
         * ErrorHandlers.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   259
         *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   260
         * Text from the spec:
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   261
         *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   262
         * The input octet stream MUST contain a well-formed XML document,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   263
         * but the input need not be validated. However, the attribute
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   264
         * value normalization and entity reference resolution MUST be
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   265
         * performed in accordance with the behaviors of a validating
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   266
         * XML processor. As well, nodes for default attributes (declared
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   267
         * in the ATTLIST with an AttValue but not specified) are created
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   268
         * in each element. Thus, the declarations in the document type
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   269
         * declaration are used to help create the canonical form, even
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   270
         * though the document type declaration is not retained in the
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   271
         * canonical form.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   272
         */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   273
        db.setErrorHandler(new com.sun.org.apache.xml.internal.security.utils.IgnoreAllErrorHandler());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   275
        Document document = db.parse(in);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   276
        return this.canonicalizeSubtree(document);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   277
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   279
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   280
     * Canonicalizes the subtree rooted by <CODE>node</CODE>.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   281
     *
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   282
     * @param node The node to canonicalize
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   283
     * @return the result of the c14n.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   284
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   285
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   286
     */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   287
    public byte[] canonicalizeSubtree(Node node) throws CanonicalizationException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   288
        return canonicalizerSpi.engineCanonicalizeSubTree(node);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   289
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   291
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   292
     * Canonicalizes the subtree rooted by <CODE>node</CODE>.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   293
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   294
     * @param node
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   295
     * @param inclusiveNamespaces
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   296
     * @return the result of the c14n.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   297
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   298
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   299
    public byte[] canonicalizeSubtree(Node node, String inclusiveNamespaces)
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   300
        throws CanonicalizationException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   301
        return canonicalizerSpi.engineCanonicalizeSubTree(node, inclusiveNamespaces);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   302
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   304
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   305
     * Canonicalizes an XPath node set. The <CODE>xpathNodeSet</CODE> is treated
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   306
     * as a list of XPath nodes, not as a list of subtrees.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   307
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   308
     * @param xpathNodeSet
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   309
     * @return the result of the c14n.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   310
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   311
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   312
    public byte[] canonicalizeXPathNodeSet(NodeList xpathNodeSet)
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   313
        throws CanonicalizationException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   314
        return canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   315
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   317
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   318
     * Canonicalizes an XPath node set. The <CODE>xpathNodeSet</CODE> is treated
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   319
     * as a list of XPath nodes, not as a list of subtrees.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   320
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   321
     * @param xpathNodeSet
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   322
     * @param inclusiveNamespaces
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   323
     * @return the result of the c14n.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   324
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   325
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   326
    public byte[] canonicalizeXPathNodeSet(
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   327
        NodeList xpathNodeSet, String inclusiveNamespaces
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   328
    ) throws CanonicalizationException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   329
        return
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   330
            canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet, inclusiveNamespaces);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   331
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   333
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   334
     * Canonicalizes an XPath node set.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   335
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   336
     * @param xpathNodeSet
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   337
     * @return the result of the c14n.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   338
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   339
     */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
   340
    public byte[] canonicalizeXPathNodeSet(Set<Node> xpathNodeSet)
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   341
        throws CanonicalizationException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   342
        return canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   343
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   345
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   346
     * Canonicalizes an XPath node set.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   347
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   348
     * @param xpathNodeSet
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   349
     * @param inclusiveNamespaces
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   350
     * @return the result of the c14n.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   351
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   352
     */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   353
    public byte[] canonicalizeXPathNodeSet(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   354
        Set<Node> xpathNodeSet, String inclusiveNamespaces
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   355
    ) throws CanonicalizationException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   356
        return
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   357
            canonicalizerSpi.engineCanonicalizeXPathNodeSet(xpathNodeSet, inclusiveNamespaces);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   358
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   360
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   361
     * Sets the writer where the canonicalization ends.  ByteArrayOutputStream
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   362
     * if none is set.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   363
     * @param os
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   364
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   365
    public void setWriter(OutputStream os) {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   366
        canonicalizerSpi.setWriter(os);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   367
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   369
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   370
     * Returns the name of the implementing {@link CanonicalizerSpi} class
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   371
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   372
     * @return the name of the implementing {@link CanonicalizerSpi} class
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   373
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   374
    public String getImplementingCanonicalizerClass() {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   375
        return canonicalizerSpi.getClass().getName();
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   376
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   378
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   379
     * Set the canonicalizer behaviour to not reset.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   380
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   381
    public void notReset() {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   382
        canonicalizerSpi.reset = false;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   383
    }
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   384
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
}