jdk/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/Transform.java
author mullan
Mon, 22 Sep 2008 10:43:17 -0400
changeset 1337 e8d6cef36199
parent 2 90ce3da70b43
child 8814 f899ad8ada82
permissions -rw-r--r--
6469266: Integrate Apache XMLSec 1.4.2 into JDK 7 Reviewed-by: valeriep
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.security.transforms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.security.PrivilegedAction;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    27
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.xml.parsers.ParserConfigurationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.security.utils.Constants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.security.utils.HelperNodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
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
    38
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import org.xml.sax.SAXException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Implements the behaviour of the <code>ds:Transform</code> element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    47
 * 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
    48
 * the implementing class that supports the functionality of <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * href=http://www.w3.org/TR/xmldsig-core/#sec-TransformAlg>a Transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * algorithm</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Implements the Factory and Proxy pattern for ds:Transform algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see Transforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see TransformSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public final class Transform extends SignatureElementProxy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    60
    /** {@link java.util.logging} logging facility */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static java.util.logging.Logger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        java.util.logging.Logger.getLogger(Transform.class.getName());
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
    /** Field _alreadyInitialized */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    65
    private static boolean alreadyInitialized = false;
2
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
    /** All available Transform classes are registered here */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    68
    private static HashMap transformClassHash = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    70
    private static HashMap transformSpiHash = new HashMap();
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
    private TransformSpi transformSpi = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
1337
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
     * Constructs {@link Transform}
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
     * @param doc the {@link Document} in which <code>Transform</code> will be
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    78
     * placed
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    79
     * @param algorithmURI URI representation of
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    80
     * <code>Transform algorithm</code> which will be specified as parameter of
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    81
     * {@link #getInstance(Document, String)}, when generated. </br>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    82
     * @param contextNodes the child node list of <code>Transform</code> element
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    83
     * @throws InvalidTransformException
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
    public Transform(Document doc, String algorithmURI, NodeList contextNodes)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    86
        throws InvalidTransformException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    88
        super(doc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    90
        this._constructionElement.setAttributeNS
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    91
            (null, Constants._ATT_ALGORITHM, algorithmURI);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    93
        transformSpi = getTransformSpi(algorithmURI);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    94
        if (transformSpi == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
             Object exArgs[] = { algorithmURI };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
             throw new InvalidTransformException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                "signature.Transform.UnknownTransform", exArgs);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    98
        }
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
        if (log.isLoggable(java.util.logging.Level.FINE)) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   101
            log.log(java.util.logging.Level.FINE, "Create URI \"" + algorithmURI + "\" class \""
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   102
                   + transformSpi.getClass() + "\"");
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   103
            log.log(java.util.logging.Level.FINE, "The NodeList is " + contextNodes);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   104
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   106
        // give it to the current document
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   107
        if (contextNodes != null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   108
            for (int i = 0; i < contextNodes.getLength(); i++) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   109
               this._constructionElement.appendChild
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   110
                   (contextNodes.item(i).cloneNode(true));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   112
        }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   113
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   115
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   116
     * This constructor can only be called from the {@link Transforms} object,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   117
     * so it's protected.
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
     * @param element <code>ds:Transform</code> element
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   120
     * @param BaseURI the URI of the resource where the XML instance was stored
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   121
     * @throws InvalidTransformException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   122
     * @throws TransformationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   123
     * @throws XMLSecurityException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   124
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   125
    public Transform(Element element, String BaseURI)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   126
        throws InvalidTransformException, TransformationException,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   127
               XMLSecurityException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   129
        super(element, BaseURI);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   131
        // retrieve Algorithm Attribute from ds:Transform
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   132
        String algorithmURI = element.getAttributeNS(null, Constants._ATT_ALGORITHM);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   134
        if (algorithmURI == null || algorithmURI.length() == 0) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   135
            Object exArgs[] = { Constants._ATT_ALGORITHM,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   136
                                Constants._TAG_TRANSFORM };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   137
            throw new TransformationException("xml.WrongContent", exArgs);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   138
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   140
        transformSpi = getTransformSpi(algorithmURI);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   141
        if (transformSpi == null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   142
            Object exArgs[] = { algorithmURI };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   143
            throw new InvalidTransformException(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   144
                "signature.Transform.UnknownTransform", exArgs);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   145
        }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   146
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   148
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   149
     * Generates a Transform object that implements the specified
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   150
     * <code>Transform algorithm</code> URI.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   151
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   152
     * @param algorithmURI <code>Transform algorithm</code> URI representation,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   153
     * such as specified in
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   154
     * <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
   155
     * @param doc the proxy {@link Document}
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   156
     * @return <code>{@link Transform}</code> object
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   157
     * @throws InvalidTransformException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   158
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   159
    public static Transform getInstance(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   160
        Document doc, String algorithmURI) throws InvalidTransformException {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   161
        return getInstance(doc, algorithmURI, (NodeList) null);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   162
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   164
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   165
     * Generates a Transform object that implements the specified
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   166
     * <code>Transform algorithm</code> URI.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   167
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   168
     * @param algorithmURI <code>Transform algorithm</code> URI representation,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   169
     * such as specified in
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   170
     * <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
   171
     * @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
   172
     * @param doc the proxy {@link Document}
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   173
     * @return <code>{@link Transform}</code> object
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   174
     * @throws InvalidTransformException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   175
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   176
    public static Transform getInstance(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   177
        Document doc, String algorithmURI, Element contextChild)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   178
        throws InvalidTransformException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   180
        HelperNodeList contextNodes = new HelperNodeList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   182
        XMLUtils.addReturnToElement(doc, contextNodes);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   183
        contextNodes.appendChild(contextChild);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   184
        XMLUtils.addReturnToElement(doc, contextNodes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   186
        return getInstance(doc, algorithmURI, contextNodes);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   187
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   189
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   190
     * Generates a Transform object that implements the specified
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   191
     * <code>Transform algorithm</code> URI.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   192
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   193
     * @param algorithmURI <code>Transform algorithm</code> URI form, such as
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   194
     * specified in <a href=http://www.w3.org/TR/xmldsig-core/#sec-TransformAlg>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   195
     * Transform algorithm </a>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   196
     * @param contextNodes the child node list of <code>Transform</code> element
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   197
     * @param doc the proxy {@link Document}
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   198
     * @return <code>{@link Transform}</code> object
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   199
     * @throws InvalidTransformException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   200
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   201
    public static Transform getInstance(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   202
        Document doc, String algorithmURI, NodeList contextNodes)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   203
        throws InvalidTransformException {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   204
        return new Transform(doc, algorithmURI, contextNodes);
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
     * Initalizes for this {@link Transform}.
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
    public static void init() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   211
        if (!alreadyInitialized) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   212
            transformClassHash = new HashMap(10);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   213
            alreadyInitialized = true;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   214
        }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   215
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   217
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   218
     * 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
   219
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   220
     * @param algorithmURI algorithmURI URI representation of
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   221
     * <code>Transform algorithm</code> will be specified as parameter of
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   222
     * {@link #getInstance(Document, String)}, when generate. </br>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   223
     * @param implementingClass <code>implementingClass</code> the implementing
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   224
     * class of {@link TransformSpi}
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   225
     * @throws AlgorithmAlreadyRegisteredException if specified algorithmURI
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   226
     * is already registered
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   227
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   228
    public static void register(String algorithmURI, String implementingClass)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   229
        throws AlgorithmAlreadyRegisteredException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   231
        // are we already registered?
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   232
        Class registeredClass = getImplementingClass(algorithmURI);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   233
        if ((registeredClass != null) ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            Object exArgs[] = { algorithmURI, registeredClass };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            throw new AlgorithmAlreadyRegisteredException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
               "algorithm.alreadyRegistered", exArgs);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   237
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   239
        ClassLoader cl = (ClassLoader) AccessController.doPrivileged(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   240
            new PrivilegedAction() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   241
                public Object run() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   242
                    return Thread.currentThread().getContextClassLoader();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   243
                }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   244
            });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   246
        try {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   247
            transformClassHash.put
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   248
                (algorithmURI, Class.forName(implementingClass, true, cl));
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   249
        } catch (ClassNotFoundException e) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   250
            throw new RuntimeException(e);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   251
        }
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
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   254
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   255
     * Returns the URI representation of Transformation algorithm
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   256
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   257
     * @return the URI representation of Transformation algorithm
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
    public String getURI() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   260
        return this._constructionElement.getAttributeNS
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   261
            (null, Constants._ATT_ALGORITHM);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   262
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
1337
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
     * 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
   266
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   267
     * @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
   268
     * Stream and NodeSet as Input of Transformation
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   269
     * @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
   270
     * transformation
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   271
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   272
     * @throws IOException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   273
     * @throws InvalidCanonicalizerException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   274
     * @throws TransformationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   275
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   276
    public XMLSignatureInput performTransform(XMLSignatureInput input)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   277
         throws IOException, CanonicalizationException,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   278
                InvalidCanonicalizerException, TransformationException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   280
        XMLSignatureInput result = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   282
        try {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   283
            result = transformSpi.enginePerformTransform(input, this);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   284
        } catch (ParserConfigurationException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   285
            Object exArgs[] = { this.getURI(), "ParserConfigurationException" };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   286
            throw new CanonicalizationException(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   287
                "signature.Transform.ErrorDuringTransform", exArgs, ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   288
        } catch (SAXException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   289
            Object exArgs[] = { this.getURI(), "SAXException" };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   290
            throw new CanonicalizationException(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   291
                "signature.Transform.ErrorDuringTransform", exArgs, ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   292
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   294
        return result;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   295
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   297
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   298
     * 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
   299
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   300
     * @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
   301
     * Stream and NodeSet as Input of Transformation
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   302
     * @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
   303
     * @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
   304
     * transformation
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   305
     * @throws CanonicalizationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   306
     * @throws IOException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   307
     * @throws InvalidCanonicalizerException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   308
     * @throws TransformationException
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   309
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   310
    public XMLSignatureInput performTransform(XMLSignatureInput input,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   311
        OutputStream os) throws IOException, CanonicalizationException,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   312
        InvalidCanonicalizerException, TransformationException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   314
        XMLSignatureInput result = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   316
        try {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   317
            result = transformSpi.enginePerformTransform(input, os, this);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   318
        } catch (ParserConfigurationException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   319
            Object exArgs[] = { this.getURI(), "ParserConfigurationException" };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   320
            throw new CanonicalizationException(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   321
                "signature.Transform.ErrorDuringTransform", exArgs, ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   322
        } catch (SAXException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   323
            Object exArgs[] = { this.getURI(), "SAXException" };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   324
            throw new CanonicalizationException(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   325
                "signature.Transform.ErrorDuringTransform", exArgs, ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   326
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   328
        return result;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   329
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   331
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   332
     * Method getImplementingClass
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
     * @param URI
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   335
     * @return The name of the class implementing the URI.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   336
     */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   337
    private static Class getImplementingClass(String URI) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   338
        return (Class) transformClassHash.get(URI);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   339
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   341
    private static TransformSpi getTransformSpi(String URI)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   342
        throws InvalidTransformException {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   343
        try {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   344
            Object value = transformSpiHash.get(URI);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   345
            if (value != null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   346
                return (TransformSpi) value;
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
            Class cl = (Class) transformClassHash.get(URI);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   349
            if (cl != null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   350
                TransformSpi tr = (TransformSpi) cl.newInstance();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   351
                transformSpiHash.put(URI, tr);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   352
                return tr;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   353
            }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   354
        } catch (InstantiationException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   355
            Object exArgs[] = { URI };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   356
            throw new InvalidTransformException(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   357
                "signature.Transform.UnknownTransform", exArgs, ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   358
        } catch (IllegalAccessException ex) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   359
            Object exArgs[] = { URI };
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   360
            throw new InvalidTransformException(
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   361
                "signature.Transform.UnknownTransform", exArgs, ex);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   362
        }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   363
        return null;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   364
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   366
    /** @inheritDoc */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   367
    public String getBaseLocalName() {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   368
        return Constants._TAG_TRANSFORM;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   369
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
}