jdk/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMRetrievalMethod.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1337 e8d6cef36199
child 18240 cda839ac048f
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     2
 * reserved comment block
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     4
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     5
/*
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     6
 * Copyright 2005 The Apache Software Foundation.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     9
 *  you may not use this file except in compliance with the License.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    10
 *  You may obtain a copy of the License at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    17
 *  See the License for the specific language governing permissions and
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    18
 *  limitations under the License.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    21
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1337
diff changeset
    22
 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    23
 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * ===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright IBM Corp. 2003 All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * ===========================================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/*
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    32
 * $Id: DOMRetrievalMethod.java,v 1.2 2008/07/24 15:20:32 mullan Exp $
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
package org.jcp.xml.dsig.internal.dom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.net.URISyntaxException;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    39
import java.security.Provider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.xml.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.xml.crypto.dsig.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.xml.crypto.dom.DOMCryptoContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.xml.crypto.dom.DOMURIReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.xml.crypto.dsig.keyinfo.RetrievalMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.xml.parsers.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import org.w3c.dom.Attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * DOM-based implementation of RetrievalMethod.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Joyce Leung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public final class DOMRetrievalMethod extends DOMStructure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    implements RetrievalMethod, DOMURIReference {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private final List transforms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private String uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private Attr here;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Creates a <code>DOMRetrievalMethod</code> containing the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * URIReference and List of Transforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @param uri the URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param type the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @param transforms a list of {@link Transform}s. The list is defensively
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *    copied to prevent subsequent modification. May be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *    or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @throws IllegalArgumentException if the format of <code>uri</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *    invalid, as specified by Reference's URI attribute in the W3C
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *    specification for XML-Signature Syntax and Processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @throws NullPointerException if <code>uriReference</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *    is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @throws ClassCastException if <code>transforms</code> contains any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *    entries that are not of type {@link Transform}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public DOMRetrievalMethod(String uri, String type, List transforms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (uri == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            throw new NullPointerException("uri cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (transforms == null || transforms.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            this.transforms = Collections.EMPTY_LIST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            List transformsCopy = new ArrayList(transforms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            for (int i = 0, size = transformsCopy.size(); i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                if (!(transformsCopy.get(i) instanceof Transform)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    throw new ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                        ("transforms["+i+"] is not a valid type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            this.transforms = Collections.unmodifiableList(transformsCopy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.uri = uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if ((uri != null) && (!uri.equals(""))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                new URI(uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                throw new IllegalArgumentException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Creates a <code>DOMRetrievalMethod</code> from an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param rmElem a RetrievalMethod element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   118
    public DOMRetrievalMethod(Element rmElem, XMLCryptoContext context,
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   119
        Provider provider) throws MarshalException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // get URI and Type attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        uri = DOMUtils.getAttributeValue(rmElem, "URI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        type = DOMUtils.getAttributeValue(rmElem, "Type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // get here node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        here = rmElem.getAttributeNodeNS(null, "URI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // get Transforms, if specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        List transforms = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Element transformsElem = DOMUtils.getFirstChildElement(rmElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (transformsElem != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            Element transformElem =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                DOMUtils.getFirstChildElement(transformsElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            while (transformElem != null) {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   134
                transforms.add
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   135
                    (new DOMTransform(transformElem, context, provider));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                transformElem = DOMUtils.getNextSiblingElement(transformElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (transforms.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            this.transforms = Collections.EMPTY_LIST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            this.transforms = Collections.unmodifiableList(transforms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public String getURI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public List getTransforms() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return transforms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        throws MarshalException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        Document ownerDoc = DOMUtils.getOwnerDocument(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        Element rmElem = DOMUtils.createElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            (ownerDoc, "RetrievalMethod", XMLSignature.XMLNS, dsPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        // add URI and Type attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        DOMUtils.setAttribute(rmElem, "URI", uri);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        DOMUtils.setAttribute(rmElem, "Type", type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        // add Transforms elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (!transforms.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            Element transformsElem = DOMUtils.createElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                (ownerDoc, "Transforms", XMLSignature.XMLNS, dsPrefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            rmElem.appendChild(transformsElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            for (int i = 0, size = transforms.size(); i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                ((DOMTransform) transforms.get(i)).marshal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    (transformsElem, dsPrefix, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        parent.appendChild(rmElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // save here node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        here = rmElem.getAttributeNodeNS(null, "URI");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public Node getHere() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return here;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public Data dereference(XMLCryptoContext context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        throws URIReferenceException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (context == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new NullPointerException("context cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * If URIDereferencer is specified in context; use it, otherwise use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * built-in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        URIDereferencer deref = context.getURIDereferencer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (deref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            deref = DOMURIDereferencer.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        Data data = deref.dereference(this, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // pass dereferenced data through Transforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            for (int i = 0, size = transforms.size(); i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                Transform transform = (Transform) transforms.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                data = ((DOMTransform) transform).transform(data, context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new URIReferenceException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public XMLStructure dereferenceAsXMLStructure(XMLCryptoContext context)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        throws URIReferenceException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            ApacheData data = (ApacheData) dereference(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            dbf.setNamespaceAware(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            DocumentBuilder db = dbf.newDocumentBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            Document doc = db.parse(new ByteArrayInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                (data.getXMLSignatureInput().getBytes()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Element kiElem = doc.getDocumentElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (kiElem.getLocalName().equals("X509Data")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                return new DOMX509Data(kiElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                return null; // unsupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            throw new URIReferenceException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (!(obj instanceof RetrievalMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        RetrievalMethod orm = (RetrievalMethod) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        boolean typesEqual = (type == null ? orm.getType() == null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            type.equals(orm.getType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return (uri.equals(orm.getURI()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            transforms.equals(orm.getTransforms()) && typesEqual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}