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