jdk/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/Transform.java
author mullan
Thu, 02 May 2013 11:42:44 -0400
changeset 18261 3d81094a9d10
parent 18240 cda839ac048f
child 18780 f47b920867e7
permissions -rw-r--r--
8008744: Rework part of fix for JDK-6741606 Reviewed-by: xuelei, ahgross
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.transforms;
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.io.OutputStream;
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    27
import java.util.concurrent.ConcurrentHashMap;
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 8814
diff changeset
    28
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.xml.parsers.ParserConfigurationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    36
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformBase64Decode;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    37
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformC14N;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    38
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformC14N11;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    39
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformC14N11_WithComments;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    40
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformC14NExclusive;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    41
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformC14NExclusiveWithComments;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    42
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformC14NWithComments;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    43
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformEnvelopedSignature;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    44
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformXPath;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    45
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformXPath2Filter;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    46
import com.sun.org.apache.xml.internal.security.transforms.implementations.TransformXSLT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.xml.internal.security.utils.Constants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import com.sun.org.apache.xml.internal.security.utils.HelperNodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    50
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import org.xml.sax.SAXException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * Implements the behaviour of the <code>ds:Transform</code> element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    59
 * This <code>Transform</code>(Factory) class acts as the Factory and Proxy of
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    60
 * the implementing class that supports the functionality of <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * href=http://www.w3.org/TR/xmldsig-core/#sec-TransformAlg>a Transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * algorithm</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Implements the Factory and Proxy pattern for ds:Transform algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @see Transforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see TransformSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
public final class Transform extends SignatureElementProxy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    71
    /** {@link org.apache.commons.logging} logging facility */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    72
    private static java.util.logging.Logger log =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        java.util.logging.Logger.getLogger(Transform.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    75
    /** All available Transform classes are registered here */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    76
    private static Map<String, Class<? extends TransformSpi>> transformSpiHash =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    77
        new ConcurrentHashMap<String, Class<? extends TransformSpi>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    79
    private final TransformSpi transformSpi;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
1337
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
     * Generates a Transform object that implements the specified
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    83
     * <code>Transform algorithm</code> URI.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    84
     *
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    85
     * @param doc the proxy {@link Document}
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    86
     * @param algorithmURI <code>Transform algorithm</code> URI representation,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    87
     * such as specified in
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    88
     * <a href=http://www.w3.org/TR/xmldsig-core/#sec-TransformAlg>Transform algorithm </a>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    89
     * @throws InvalidTransformException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    90
     */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    91
    public Transform(Document doc, String algorithmURI) throws InvalidTransformException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
    92
        this(doc, algorithmURI, (NodeList)null);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    93
    }
2
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
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    96
     * Generates a Transform object that implements the specified
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    97
     * <code>Transform algorithm</code> URI.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    98
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    99
     * @param algorithmURI <code>Transform algorithm</code> URI representation,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   100
     * such as specified in
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   101
     * <a href=http://www.w3.org/TR/xmldsig-core/#sec-TransformAlg>Transform algorithm </a>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   102
     * @param contextChild the child element of <code>Transform</code> element
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   103
     * @param doc the proxy {@link Document}
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   104
     * @throws InvalidTransformException
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
    public Transform(Document doc, String algorithmURI, Element contextChild)
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   107
        throws InvalidTransformException {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   108
        super(doc);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   109
        HelperNodeList contextNodes = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   111
        if (contextChild != null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   112
            contextNodes = new HelperNodeList();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   113
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   114
            XMLUtils.addReturnToElement(doc, contextNodes);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   115
            contextNodes.appendChild(contextChild);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   116
            XMLUtils.addReturnToElement(doc, contextNodes);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   117
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   119
        transformSpi = initializeTransform(algorithmURI, contextNodes);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   120
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   122
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   123
     * Constructs {@link Transform}
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   124
     *
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   125
     * @param doc the {@link Document} in which <code>Transform</code> will be
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   126
     * placed
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   127
     * @param algorithmURI URI representation of <code>Transform algorithm</code>
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   128
     * @param contextNodes the child node list of <code>Transform</code> element
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   129
     * @throws InvalidTransformException
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   130
     */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   131
    public Transform(Document doc, String algorithmURI, NodeList contextNodes)
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   132
        throws InvalidTransformException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   133
        super(doc);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   134
        transformSpi = initializeTransform(algorithmURI, contextNodes);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   135
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   137
    /**
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   138
     * @param element <code>ds:Transform</code> element
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   139
     * @param BaseURI the URI of the resource where the XML instance was stored
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   140
     * @throws InvalidTransformException
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   141
     * @throws TransformationException
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   142
     * @throws XMLSecurityException
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   143
     */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   144
    public Transform(Element element, String BaseURI)
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   145
        throws InvalidTransformException, TransformationException, XMLSecurityException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   146
        super(element, BaseURI);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   147
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   148
        // retrieve Algorithm Attribute from ds:Transform
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   149
        String algorithmURI = element.getAttributeNS(null, Constants._ATT_ALGORITHM);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   150
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   151
        if (algorithmURI == null || algorithmURI.length() == 0) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   152
            Object exArgs[] = { Constants._ATT_ALGORITHM, Constants._TAG_TRANSFORM };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   153
            throw new TransformationException("xml.WrongContent", exArgs);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   154
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   156
        Class<? extends TransformSpi> transformSpiClass = transformSpiHash.get(algorithmURI);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   157
        if (transformSpiClass == null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   158
            Object exArgs[] = { algorithmURI };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   159
            throw new InvalidTransformException("signature.Transform.UnknownTransform", exArgs);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   160
        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   161
        try {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   162
            transformSpi = transformSpiClass.newInstance();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   163
        } catch (InstantiationException ex) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   164
            Object exArgs[] = { algorithmURI };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   165
            throw new InvalidTransformException(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   166
                "signature.Transform.UnknownTransform", exArgs, ex
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   167
            );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   168
        } catch (IllegalAccessException ex) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   169
            Object exArgs[] = { algorithmURI };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   170
            throw new InvalidTransformException(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   171
                "signature.Transform.UnknownTransform", exArgs, ex
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   172
            );
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   173
        }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   174
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   176
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   177
     * Registers implementing class of the Transform algorithm with algorithmURI
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   178
     *
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   179
     * @param algorithmURI algorithmURI URI representation of <code>Transform algorithm</code>
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   180
     * @param implementingClass <code>implementingClass</code> the implementing
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   181
     * class of {@link TransformSpi}
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   182
     * @throws AlgorithmAlreadyRegisteredException if specified algorithmURI
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   183
     * is already registered
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   184
     */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   185
    @SuppressWarnings("unchecked")
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   186
    public static void register(String algorithmURI, String implementingClass)
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   187
        throws AlgorithmAlreadyRegisteredException, ClassNotFoundException,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   188
            InvalidTransformException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   189
        // are we already registered?
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   190
        Class<? extends TransformSpi> transformSpi = transformSpiHash.get(algorithmURI);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   191
        if (transformSpi != null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   192
            Object exArgs[] = { algorithmURI, transformSpi };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   193
            throw new AlgorithmAlreadyRegisteredException("algorithm.alreadyRegistered", exArgs);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   194
        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   195
        Class<? extends TransformSpi> transformSpiClass =
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   196
            (Class<? extends TransformSpi>)
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   197
                ClassLoaderUtils.loadClass(implementingClass, Transform.class);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   198
        transformSpiHash.put(algorithmURI, transformSpiClass);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   199
    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   200
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   201
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   202
     * Registers implementing class of the Transform algorithm with algorithmURI
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   203
     *
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   204
     * @param algorithmURI algorithmURI URI representation of <code>Transform algorithm</code>
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   205
     * @param implementingClass <code>implementingClass</code> the implementing
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   206
     * class of {@link TransformSpi}
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   207
     * @throws AlgorithmAlreadyRegisteredException if specified algorithmURI
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   208
     * is already registered
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   209
     */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   210
    public static void register(String algorithmURI, Class<? extends TransformSpi> implementingClass)
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   211
        throws AlgorithmAlreadyRegisteredException {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   212
        // are we already registered?
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   213
        Class<? extends TransformSpi> transformSpi = transformSpiHash.get(algorithmURI);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   214
        if (transformSpi != null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   215
            Object exArgs[] = { algorithmURI, transformSpi };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   216
            throw new AlgorithmAlreadyRegisteredException("algorithm.alreadyRegistered", exArgs);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   217
        }
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   218
        transformSpiHash.put(algorithmURI, implementingClass);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   219
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   221
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   222
     * This method registers the default algorithms.
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   223
     */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   224
    public static void registerDefaultAlgorithms() {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   225
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   226
            Transforms.TRANSFORM_BASE64_DECODE, TransformBase64Decode.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   227
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   228
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   229
            Transforms.TRANSFORM_C14N_OMIT_COMMENTS, TransformC14N.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   230
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   231
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   232
            Transforms.TRANSFORM_C14N_WITH_COMMENTS, TransformC14NWithComments.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   233
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   234
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   235
            Transforms.TRANSFORM_C14N11_OMIT_COMMENTS, TransformC14N11.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   236
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   237
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   238
            Transforms.TRANSFORM_C14N11_WITH_COMMENTS, TransformC14N11_WithComments.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   239
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   240
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   241
            Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS, TransformC14NExclusive.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   242
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   243
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   244
            Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS, TransformC14NExclusiveWithComments.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   245
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   246
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   247
            Transforms.TRANSFORM_XPATH, TransformXPath.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   248
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   249
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   250
            Transforms.TRANSFORM_ENVELOPED_SIGNATURE, TransformEnvelopedSignature.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   251
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   252
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   253
            Transforms.TRANSFORM_XSLT, TransformXSLT.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   254
        );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   255
        transformSpiHash.put(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   256
            Transforms.TRANSFORM_XPATH2FILTER, TransformXPath2Filter.class
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   257
        );
1337
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
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   260
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   261
     * Returns the URI representation of Transformation algorithm
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   262
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   263
     * @return the URI representation of Transformation algorithm
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   264
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   265
    public String getURI() {
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   266
        return this._constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   267
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   269
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   270
     * Transforms the input, and generates {@link XMLSignatureInput} as output.
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
     * @param input input {@link XMLSignatureInput} which can supplied Octet
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   273
     * Stream and NodeSet as Input of Transformation
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   274
     * @return the {@link XMLSignatureInput} class as the result of
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   275
     * transformation
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   276
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   277
     * @throws IOException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   278
     * @throws InvalidCanonicalizerException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   279
     * @throws TransformationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   280
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   281
    public XMLSignatureInput performTransform(XMLSignatureInput input)
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   282
        throws IOException, CanonicalizationException,
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   283
               InvalidCanonicalizerException, TransformationException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   284
        return performTransform(input, null);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   285
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   287
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   288
     * Transforms the input, and generates {@link XMLSignatureInput} as output.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   289
     *
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   290
     * @param input input {@link XMLSignatureInput} which can supplied Octect
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   291
     * Stream and NodeSet as Input of Transformation
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   292
     * @param os where to output the result of the last transformation
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   293
     * @return the {@link XMLSignatureInput} class as the result of
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   294
     * transformation
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   295
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   296
     * @throws IOException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   297
     * @throws InvalidCanonicalizerException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   298
     * @throws TransformationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   299
     */
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   300
    public XMLSignatureInput performTransform(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   301
        XMLSignatureInput input, OutputStream os
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   302
    ) throws IOException, CanonicalizationException,
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   303
        InvalidCanonicalizerException, TransformationException {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   304
        XMLSignatureInput result = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   306
        try {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   307
            result = transformSpi.enginePerformTransform(input, os, this);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   308
        } catch (ParserConfigurationException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   309
            Object exArgs[] = { this.getURI(), "ParserConfigurationException" };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   310
            throw new CanonicalizationException(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   311
                "signature.Transform.ErrorDuringTransform", exArgs, ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   312
        } catch (SAXException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   313
            Object exArgs[] = { this.getURI(), "SAXException" };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   314
            throw new CanonicalizationException(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   315
                "signature.Transform.ErrorDuringTransform", exArgs, ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   316
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   318
        return result;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   319
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   321
    /** @inheritDoc */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   322
    public String getBaseLocalName() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   323
        return Constants._TAG_TRANSFORM;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   324
    }
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   325
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   326
    /**
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   327
     * Initialize the transform object.
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   328
     */
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   329
    private TransformSpi initializeTransform(String algorithmURI, NodeList contextNodes)
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   330
        throws InvalidTransformException {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   331
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   332
        this._constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM, algorithmURI);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   333
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   334
        Class<? extends TransformSpi> transformSpiClass = transformSpiHash.get(algorithmURI);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   335
        if (transformSpiClass == null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   336
            Object exArgs[] = { algorithmURI };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   337
            throw new InvalidTransformException("signature.Transform.UnknownTransform", exArgs);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   338
        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   339
        TransformSpi newTransformSpi = null;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   340
        try {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   341
            newTransformSpi = transformSpiClass.newInstance();
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   342
        } catch (InstantiationException ex) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   343
            Object exArgs[] = { algorithmURI };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   344
            throw new InvalidTransformException(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   345
                "signature.Transform.UnknownTransform", exArgs, ex
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   346
            );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   347
        } catch (IllegalAccessException ex) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   348
            Object exArgs[] = { algorithmURI };
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   349
            throw new InvalidTransformException(
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   350
                "signature.Transform.UnknownTransform", exArgs, ex
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   351
            );
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   352
        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   353
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   354
        if (log.isLoggable(java.util.logging.Level.FINE)) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   355
            log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   356
                      + newTransformSpi.getClass() + "\"");
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   357
            log.log(java.util.logging.Level.FINE, "The NodeList is " + contextNodes);
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   358
        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   359
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   360
        // give it to the current document
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   361
        if (contextNodes != null) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   362
            for (int i = 0; i < contextNodes.getLength(); i++) {
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   363
                this._constructionElement.appendChild(contextNodes.item(i).cloneNode(true));
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   364
            }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   365
        }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   366
        return newTransformSpi;
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   367
    }
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 10694
diff changeset
   368
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
}